re PR c++/36959 (C++ front-end causing a static inline function to be emitted)
authorJason Merrill <jason@redhat.com>
Tue, 3 Nov 2009 23:02:41 +0000 (18:02 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 3 Nov 2009 23:02:41 +0000 (18:02 -0500)
PR c++/36959
* decl2.c (cxx_callgraph_analyze_expr): Don't reference a function
just because a static variable in it is needed unless -frepo.

From-SVN: r153878

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/inline16.C [new file with mode: 0644]

index 21adec9..2ef626d 100644 (file)
@@ -1,5 +1,9 @@
 2009-11-03  Jason Merrill  <jason@redhat.com>
 
+       PR c++/36959
+       * decl2.c (cxx_callgraph_analyze_expr): Don't reference a function
+       just because a static variable in it is needed unless -frepo.
+
        PR c++/41876
        * parser.c (cp_parser_type_specifier_seq): Rename is_condition to
        is_declaration.
index b1fe4b9..dbb9fb4 100644 (file)
@@ -3310,6 +3310,7 @@ cxx_callgraph_analyze_expr (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED)
            mark_decl_referenced (vtbl);
        }
       else if (DECL_CONTEXT (t)
+              && flag_use_repository
               && TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL)
        /* If we need a static variable in a function, then we
           need the containing function.  */
index 4a499e2..f525db0 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-03  Jason Merrill  <jason@redhat.com>
+
+       PR c++/36959
+       * g++.dg/opt/inline16.C: New.
+
 2009-11-03  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/stack_check.adb1: New test.
diff --git a/gcc/testsuite/g++.dg/opt/inline16.C b/gcc/testsuite/g++.dg/opt/inline16.C
new file mode 100644 (file)
index 0000000..6ee6d76
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/36959
+// We shouldn't have to emit fromSlotB just because we need shuf_BZZZ.
+// { dg-options -O }
+// { dg-final { scan-assembler-not "_ZL9fromSlotBv" } }
+
+static inline int *fromSlotB(void)
+{
+  static int shuf_BZZZ = 1;
+  return &shuf_BZZZ;
+}
+
+int *p;
+
+int main(void)
+{
+  p = fromSlotB();
+  return (*p != 1);
+}
+