Fix crash accessing builtins in sanitizer.def and after (PR jit/82174)
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 14 Sep 2017 19:30:26 +0000 (19:30 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 14 Sep 2017 19:30:26 +0000 (19:30 +0000)
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.

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.

From-SVN: r252769

gcc/jit/ChangeLog
gcc/jit/jit-builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c [new file with mode: 0644]

index d06722c0edf653ce5e8e753f00f4ae63cd0d105e..63d8b06198fe43f468ea9070e04f688e1a5feffd 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-14  David Malcolm  <dmalcolm@redhat.com>
+
+       PR jit/82174
+       * jit-builtins.c (matches_builtin): Ignore entries with a NULL
+       name.
+
 2017-08-18  David Malcolm  <dmalcolm@redhat.com>
 
        PR tree-optimization/46805
index 7840915a69f24f854d93fd621aa10305c34edbef..35c4db048755c08c1c9ae326515261ddd27632ce 100644 (file)
@@ -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);
index 005c0b9882c4625d5dd736200dc58e9df6a9275c..c03547b73199f9881895e2af225af2a5058ce57e 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-14  David Malcolm  <dmalcolm@redhat.com>
+
+       PR jit/82174
+       * jit.dg/test-error-gcc_jit_context_get_builtin_function-unknown-builtin.c:
+       New test case.
+
 2017-09-14  Pat Haugen  <pthaugen@us.ibm.com>
 
        * gcc.target/powerpc/r2_shrink-wrap.c: New.
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 (file)
index 0000000..b1e389c
--- /dev/null
@@ -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");
+}