analyzer: fix ICE when DECL_INITIAL is error_mark_node [PR98580]
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 7 Jan 2021 20:45:29 +0000 (15:45 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 7 Jan 2021 20:45:29 +0000 (15:45 -0500)
lto-streamer-out.c's get_symbol_initial_value can return error_mark_node
rather than DECL_INITIAL as an optimization to avoid extra sections for
simple scalar values.

Add a check to the analyzer to handle such cases gracefully.

gcc/analyzer/ChangeLog:
PR analyzer/98580
* region.cc (decl_region::get_svalue_for_initializer): Gracefully
handle when LTO writes out DECL_INITIAL as error_mark_node.

gcc/testsuite/ChangeLog:
PR analyzer/98580
* gcc.dg/analyzer/pr98580-a.c: New test.
* gcc.dg/analyzer/pr98580-b.c: New test.

gcc/analyzer/region.cc
gcc/testsuite/gcc.dg/analyzer/pr98580-a.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/analyzer/pr98580-b.c [new file with mode: 0644]

index aefc389edd31d3c72b3276575c166bd31c8bff39..6db1fc91afd96eb9eeb2de4dcc55b4d71aaed309 100644 (file)
@@ -969,6 +969,11 @@ decl_region::get_svalue_for_initializer (region_model_manager *mgr) const
                                                 c.get_map ());
     }
 
+  /* LTO can write out error_mark_node as the DECL_INITIAL for simple scalar
+     values (to avoid writing out an extra section).  */
+  if (init == error_mark_node)
+    return NULL;
+
   if (TREE_CODE (init) == CONSTRUCTOR)
     return get_svalue_for_constructor (init, mgr);
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr98580-a.c b/gcc/testsuite/gcc.dg/analyzer/pr98580-a.c
new file mode 100644 (file)
index 0000000..d2b10d6
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do link } */
+/* { dg-require-effective-target lto } */
+/* { dg-additional-options "-flto" } */
+/* { dg-additional-sources pr98580-b.c } */
+
+int a;
+int *p = &a;
+int foo();
+int main() { return foo(); }
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr98580-b.c b/gcc/testsuite/gcc.dg/analyzer/pr98580-b.c
new file mode 100644 (file)
index 0000000..629ebce
--- /dev/null
@@ -0,0 +1,2 @@
+extern int *p;
+int foo() { return *p; }