analyzer: fix ICE on function pointer casts [PR 93775]
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 17 Feb 2020 08:06:14 +0000 (03:06 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 18 Feb 2020 01:18:03 +0000 (20:18 -0500)
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.

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/ChangeLog
gcc/analyzer/region-model.cc
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/analyzer/20020129-1.c [new file with mode: 0644]

index d669c989ac119f20824a098ea40e249a331ab691..f9fd80c1cf549547cba34f72abd4b2c7a7c108bd 100644 (file)
@@ -1,3 +1,10 @@
+2020-02-17  David Malcolm  <dmalcolm@redhat.com>
+
+       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.
+
 2020-02-17  David Malcolm  <dmalcolm@redhat.com>
 
        PR analyzer/93388
index b67660cf864b776875fbe8666234fe8abb573624..deb201546f307c827156b6994a2c036efaa1f562 100644 (file)
@@ -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)
index 2e8d92221dbf7fed51d4a97b7833eb1bab696ddc..0e7d7bcc4b81f44c8ef80eae7ffd7aa2e3dd70a5 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-17  David Malcolm  <dmalcolm@redhat.com>
+
+       PR analyzer/93775
+       * gcc.dg/analyzer/20020129-1.c: New test.
+
 2020-02-17  Alexandre Oliva <oliva@adacore.com>
 
        * gcc.dg/tls/emutls-3.c: New, combining emutls-2.c and
diff --git a/gcc/testsuite/gcc.dg/analyzer/20020129-1.c b/gcc/testsuite/gcc.dg/analyzer/20020129-1.c
new file mode 100644 (file)
index 0000000..7d49519
--- /dev/null
@@ -0,0 +1,2 @@
+/* { dg-require-effective-target indirect_calls } */
+#include "../../gcc.c-torture/compile/20020129-1.c"