From 23844fd7306763ee07f27acd6883fd47bc858ec3 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 1 Dec 2014 18:16:37 +0000 Subject: [PATCH] jit-builtins.c: Fix segfault on unsupported builtins 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 | 8 ++++++++ gcc/jit/jit-builtins.c | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gcc/jit/ChangeLog b/gcc/jit/ChangeLog index 36fcc7692e2..042a6f0a9fd 100644 --- a/gcc/jit/ChangeLog +++ b/gcc/jit/ChangeLog @@ -1,3 +1,11 @@ +2014-12-01 David Malcolm + + * 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 * jit-playback.c (gcc::jit::playback::context::compile): Move DSO diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c index 49d37d8f73a..9063075c221 100644 --- a/gcc/jit/jit-builtins.c +++ b/gcc/jit/jit-builtins.c @@ -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; -- 2.30.2