[committed] analyzer: fix ICE on function pointer casts [PR 93775]

Message ID 20200218012047.9570-1-dmalcolm@redhat.com
State New
Headers show
Series
  • [committed] analyzer: fix ICE on function pointer casts [PR 93775]
Related show

Commit Message

David Malcolm Feb. 18, 2020, 1:20 a.m.
PR analyzer/93775 reports an ICE in cgraph_node::get when -fanalyzer is
used on code that calls a function pointer that was generated via a cast
from a non-function.

This patch fixes it by bulletproofing region_model::get_fndecl_for_call
for the case where the code_region's get_tree_for_child_region returns
NULL.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to master as r10-6686-gd8cde6f9c223f1b6d4f4e4e07088f08a629b7c2a.

gcc/analyzer/ChangeLog:
	PR analyzer/93775
	* region-model.cc (region_model::get_fndecl_for_call): Handle the
	case where the code_region's get_tree_for_child_region returns
	NULL.

gcc/testsuite/ChangeLog:
	PR analyzer/93775
	* gcc.dg/analyzer/20020129-1.c: New test.
---
 gcc/analyzer/region-model.cc               | 2 ++
 gcc/testsuite/gcc.dg/analyzer/20020129-1.c | 2 ++
 2 files changed, 4 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/20020129-1.c

-- 
2.21.0

Patch

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index b67660cf864..deb201546f3 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -6693,6 +6693,8 @@  region_model::get_fndecl_for_call (const gcall *call,
       if (code)
 	{
 	  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 ();
 	  if (ultimate_node)
diff --git a/gcc/testsuite/gcc.dg/analyzer/20020129-1.c b/gcc/testsuite/gcc.dg/analyzer/20020129-1.c
new file mode 100644
index 00000000000..7d49519bc40
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/20020129-1.c
@@ -0,0 +1,2 @@ 
+/* { dg-require-effective-target indirect_calls } */
+#include "../../gcc.c-torture/compile/20020129-1.c"