This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/36959 (unnecessarily emitting inline function with static var)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 03 Nov 2009 18:12:09 -0500
- Subject: C++ PATCH for c++/36959 (unnecessarily emitting inline function with static var)
Removing the code suggested in the PR discussion didn't cause any
testsuite regressions. -frepo doesn't seem to work properly on
i686-pc-linux-gnu, so rather than test the effect on -frepo I just
conditioned the code on -frepo.
Tested x86_64-pc-linux-gnu, applied to trunk. Will also apply to 4.4
after testing.
commit 738bf1d66924ec7fd117518b031a4ce4a9f3ce78
Author: Jason Merrill <jason@redhat.com>
Date: Tue Nov 3 17:39:27 2009 -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.
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index b1fe4b9..dbb9fb4 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -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. */
diff --git a/gcc/testsuite/g++.dg/opt/inline16.C b/gcc/testsuite/g++.dg/opt/inline16.C
new file mode 100644
index 0000000..6ee6d76
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/inline16.C
@@ -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);
+}
+