jit-builtins.c: Fix segfault on unsupported builtins
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 1 Dec 2014 18:16:37 +0000 (18:16 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Mon, 1 Dec 2014 18:16:37 +0000 (18:16 +0000)
gcc/jit/ChangeLog:
* jit-builtins.c
(gcc::jit::recording::builtins_manager::get_builtin_function):
Check for NULL return from make_builtin_function.
(gcc::jit::recording::builtins_manager::make_builtin_function):
Check for NULL return from get_type.

From-SVN: r218239

gcc/jit/ChangeLog
gcc/jit/jit-builtins.c

index 36fcc7692e2fb455fe2ae3b0dfed00d9e58237a0..042a6f0a9fd92900863551c31f958a14b8a6ed29 100644 (file)
@@ -1,3 +1,11 @@
+2014-12-01  David Malcolm  <dmalcolm@redhat.com>
+
+       * jit-builtins.c
+       (gcc::jit::recording::builtins_manager::get_builtin_function):
+       Check for NULL return from make_builtin_function.
+       (gcc::jit::recording::builtins_manager::make_builtin_function):
+       Check for NULL return from get_type.
+
 2014-12-01  David Malcolm  <dmalcolm@redhat.com>
 
        * jit-playback.c (gcc::jit::playback::context::compile): Move DSO
index 49d37d8f73ab7a03d43f94aa8c498efe90c90323..9063075c221bf3f3ee6d43164437e56fe30bb1bf 100644 (file)
@@ -160,8 +160,12 @@ builtins_manager::get_builtin_function (const char *name)
      the same id on a context give back the same object.  */
   if (!m_builtin_functions[builtin_id])
     {
-      m_builtin_functions[builtin_id] = make_builtin_function (builtin_id);
-      m_ctxt->record (m_builtin_functions[builtin_id]);
+      function *fn = make_builtin_function (builtin_id);
+      if (fn)
+       {
+         m_builtin_functions[builtin_id] = fn;
+         m_ctxt->record (fn);
+       }
     }
 
   return m_builtin_functions[builtin_id];
@@ -174,7 +178,10 @@ builtins_manager::make_builtin_function (enum built_in_function builtin_id)
 {
   const struct builtin_data& bd = builtin_data[builtin_id];
   enum jit_builtin_type type_id = bd.type;
-  function_type *func_type = get_type (type_id)->as_a_function_type ();
+  type *t = get_type (type_id);
+  if (!t)
+    return NULL;
+  function_type *func_type = t->as_a_function_type ();
   if (!func_type)
     return NULL;