C++ PATCH: Fix linkage of statics in inlines
Jason Merrill
jason@redhat.com
Sat Nov 11 15:48:00 GMT 2000
We suppress inlining of functions with static locals in order to avoid
having multiple copies of the locals. This was broken by the move to
tree-based inlining, since it does not respect
current_function_cannot_inline.
Fixes g++.other/comdat1.C.
2000-11-11 Jason Merrill <jason@redhat.com>
* decl.c (maybe_commonize_var): Set DECL_UNINLINABLE for statics
in inlines.
*** decl.c.~1~ Sat Nov 11 23:30:00 2000
--- decl.c Sat Nov 11 23:38:23 2000
*************** maybe_commonize_var (decl)
*** 7655,7660 ****
--- 7655,7661 ----
inlining of such functions. */
current_function_cannot_inline
= "function with static variable cannot be inline";
+ DECL_UNINLINABLE (current_function_decl) = 1;
/* If flag_weak, we don't need to mess with this, as we can just
make the function weak, and let it refer to its unique local
Index: ../testsuite/g++.old-deja/g++.other/comdat1-aux.cc
===================================================================
RCS file: comdat1-aux.cc
diff -N comdat1-aux.cc
*** /dev/null Tue May 5 13:32:27 1998
--- ../testsuite/g++.old-deja/g++.other/comdat1-aux.cc Sat Nov 11 15:45:02 2000
***************
*** 0 ****
--- 1,10 ----
+ inline int f ()
+ {
+ static int k;
+ return ++k;
+ }
+
+ int g ()
+ {
+ return f();
+ }
Index: ../testsuite/g++.old-deja/g++.other/comdat1.C
===================================================================
RCS file: comdat1.C
diff -N comdat1.C
*** /dev/null Tue May 5 13:32:27 1998
--- ../testsuite/g++.old-deja/g++.other/comdat1.C Sat Nov 11 15:45:02 2000
***************
*** 0 ****
--- 1,24 ----
+ // Test that statics in inline functions are unified between
+ // translation units. Currently we handle this by just suppressing
+ // inling and relying on unification of the function itself.
+
+ // Special g++ Options: -O
+
+ // Additional sources: comdat1-aux.cc
+
+ inline int f ()
+ {
+ static int i;
+ return ++i;
+ }
+
+ int g ();
+
+ int main ()
+ {
+ if (f() != 1
+ || g() != 2
+ || f() != 3)
+ return 1;
+ return 0;
+ }
More information about the Gcc-patches
mailing list