aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2020-02-26 09:43:57 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2020-02-26 21:02:53 -0500
commit0ba70d1b5ae8df6406a880b2d23e4710b393e8c9 (patch)
tree52b4c8b2498c56cabb21025e9283280cf37870ae /gcc/analyzer
parent89f759ac2ebb9f09ce5655ce5d791793922c612d (diff)
downloadgcc-0ba70d1b5ae8df6406a880b2d23e4710b393e8c9.zip
gcc-0ba70d1b5ae8df6406a880b2d23e4710b393e8c9.tar.gz
gcc-0ba70d1b5ae8df6406a880b2d23e4710b393e8c9.tar.bz2
analyzer: fix ICE on unreachable calls [PR 93947]
PR analyzer/93947 reports an ICE at -O1 when attempting to analyze a call that has been optimized away as unreachable. The root cause is a NULL dereference due to the fndecl having a NULL cgraph_node: the cgraph_node was created by pass_build_cgraph_edges::execute, but was later removed by symbol_table::remove_unreachable_nodes before the analyzer pass. This patch fixes it by checking for NULL before handling the cgraph_node. The reproducer demonstrates a weakness in the analyzer's constraint handling, where region_model::apply_constraints_for_gswitch fails to spot when the cases fully cover the data type, and thus make the default impossible. For now this is xfail-ed in the testcase. gcc/analyzer/ChangeLog: PR analyzer/93947 * region-model.cc (region_model::get_fndecl_for_call): Gracefully fail for fn_decls that don't have a cgraph_node. gcc/testsuite/ChangeLog: PR analyzer/93947 * gcc.dg/analyzer/torture/pr93947.c: New test.
Diffstat (limited to 'gcc/analyzer')
-rw-r--r--gcc/analyzer/ChangeLog6
-rw-r--r--gcc/analyzer/region-model.cc6
2 files changed, 10 insertions, 2 deletions
diff --git a/gcc/analyzer/ChangeLog b/gcc/analyzer/ChangeLog
index 982cc3c..92377be 100644
--- a/gcc/analyzer/ChangeLog
+++ b/gcc/analyzer/ChangeLog
@@ -1,5 +1,11 @@
2020-02-26 David Malcolm <dmalcolm@redhat.com>
+ PR analyzer/93947
+ * region-model.cc (region_model::get_fndecl_for_call): Gracefully
+ fail for fn_decls that don't have a cgraph_node.
+
+2020-02-26 David Malcolm <dmalcolm@redhat.com>
+
* bar-chart.cc: New file.
* bar-chart.h: New file.
* engine.cc: Include "analyzer/bar-chart.h".
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index a71884d..b2179bd 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -6732,8 +6732,10 @@ region_model::get_fndecl_for_call (const gcall *call,
tree fn_decl = code->get_tree_for_child_region (fn_rid);
if (!fn_decl)
return NULL_TREE;
- const cgraph_node *ultimate_node
- = cgraph_node::get (fn_decl)->ultimate_alias_target ();
+ cgraph_node *node = cgraph_node::get (fn_decl);
+ if (!node)
+ return NULL_TREE;
+ const cgraph_node *ultimate_node = node->ultimate_alias_target ();
if (ultimate_node)
return ultimate_node->decl;
}