public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] Fix crash accessing builtins in sanitizer.def and after (PR jit/82174)
@ 2017-01-01  0:00 David Malcolm
  2017-01-01  0:00 ` Michael Cree
  0 siblings, 1 reply; 5+ messages in thread
From: David Malcolm @ 2017-01-01  0:00 UTC (permalink / raw)
  To: gcc-patches, jit; +Cc: David Malcolm

Calls to gcc_jit_context_get_builtin_function that accessed builtins
in sanitizer.def and after (or failed to match any builtin) led to
a crash accessing a NULL builtin name.

The entries with the NULL name came from these lines in sanitizer.def:

  /* This has to come before all the sanitizer builtins.  */
  DEF_BUILTIN_STUB(BEGIN_SANITIZER_BUILTINS, (const char *)0)

  [...snip...]

  /* This has to come after all the sanitizer builtins.  */
  DEF_BUILTIN_STUB(END_SANITIZER_BUILTINS, (const char *)0)

This patch updates jit-builtins.c to cope with such entries, fixing the
crash.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu;
takes jit.sum from 9769 to 9789 PASS results.

Committed to trunk as r252769.

gcc/jit/ChangeLog:
	PR jit/82174
	* jit-builtins.c (matches_builtin): Ignore entries with a NULL
	name.

gcc/testsuite/ChangeLog:
	PR jit/82174
	* jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c:
	New test case.
---
 gcc/jit/jit-builtins.c                             |  5 ++++-
 ..._context_get_builtin_function-unknown-builtin.c | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c

diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c
index 7840915..35c4db0 100644
--- a/gcc/jit/jit-builtins.c
+++ b/gcc/jit/jit-builtins.c
@@ -68,7 +68,10 @@ matches_builtin (const char *in_name,
 		 const struct builtin_data& bd)
 {
   const bool debug = 0;
-  gcc_assert (bd.name);
+
+  /* Ignore entries with a NULL name.  */
+  if (!bd.name)
+    return false;
 
   if (debug)
     fprintf (stderr, "seen builtin: %s\n", bd.name);
diff --git a/gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c b/gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c
new file mode 100644
index 0000000..b1e389c
--- /dev/null
+++ b/gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c
@@ -0,0 +1,22 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+  gcc_jit_context_get_builtin_function (ctxt,
+					"this_is_not_a_builtin");
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+  CHECK_VALUE (result, NULL);
+
+  CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
+		      "builtin \"this_is_not_a_builtin\" not found");
+}
-- 
1.8.5.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-04 19:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-01  0:00 [committed] Fix crash accessing builtins in sanitizer.def and after (PR jit/82174) David Malcolm
2017-01-01  0:00 ` Michael Cree
2017-01-01  0:00   ` [committed] jit: implement gcc_jit_context_new_rvalue_from_vector David Malcolm
2017-01-01  0:00   ` [committed] Fix crash accessing builtins in sanitizer.def and after (PR jit/82174) David Malcolm
2017-01-01  0:00     ` Michael Cree

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).