This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[C++ PATCH] Avoid inlining function if it is having static variables


Hi!

This is just addition to
2000-11-11  Jason Merrill  <jason@redhat.com>
        * decl.c (maybe_commonize_var): Set DECL_UNINLINABLE for statics
        in inlines.
where it would not work first time a function containing static variables is
instantiated.
The right fix is to revert Jason's patch and mangling the local variables
using
Z <function name> E { <num> <name> [ _ <id> ] | s [ _ <id> ] },
putting them into separate unique sections and exporting them, but I guess
this would not be a two-liner like this, so I prefer first having properly
working compiler and then optimize.
Ok to commit?

2001-01-24  Jakub Jelinek  <jakub@redhat.com>

	* optimize.c (inlinable_function_p): Honour if DECL_UNINLINABLE is
	set during instantiate_decl.

	* g++.old-deja/g++.other/comdat2.C: New test.
	* g++.old-deja/g++.other/comdat2-aux.cc: Auxiliary source for it.

--- gcc/cp/optimize.c.jj	Wed Jan 17 13:36:20 2001
+++ gcc/cp/optimize.c	Wed Jan 24 19:02:21 2001
@@ -570,6 +570,9 @@ inlinable_function_p (fn, id)
     {
       fn = instantiate_decl (fn, /*defer_ok=*/0);
       inlinable = !TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn));
+      /* Instantiation could set DECL_UNINLINABLE.  */
+      if (DECL_UNINLINABLE (fn))
+	inlinable = 0;
     }
 
   /* If we don't have the function body available, we can't inline
--- gcc/testsuite/g++.old-deja/g++.other/comdat2.C.jj	Wed Jan 24 19:09:57 2001
+++ gcc/testsuite/g++.old-deja/g++.other/comdat2.C	Wed Jan 24 19:09:53 2001
@@ -0,0 +1,31 @@
+// 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: comdat2-aux.cc
+
+template <class T>
+struct S {
+  static int f ()
+  {
+    static int i;
+    return ++i;
+  }
+  S () {};
+  ~S () {};
+};
+
+typedef S<int> a;
+
+int g ();
+
+int main ()
+{
+  if (a::f() != 1
+      || g() != 2
+      || a::f() != 3)
+    return 1;
+  return 0;
+}
--- gcc/testsuite/g++.old-deja/g++.other/comdat2-aux.cc.jj	Wed Jan 24 19:10:08 2001
+++ gcc/testsuite/g++.old-deja/g++.other/comdat2-aux.cc	Wed Jan 24 19:10:38 2001
@@ -0,0 +1,17 @@
+template <class T>
+struct S {
+  static int f ()
+  {
+    static int i;
+    return ++i;
+  }
+  S () {};
+  ~S () {};
+};
+
+typedef S<int> a;
+
+int g ()
+{
+  return a::f();
+}

	Jakub

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]