]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: [multiple changes]
authorDirk Mueller <dmueller@suse.de>
Wed, 20 Jun 2007 16:27:23 +0000 (16:27 +0000)
committerDirk Mueller <mueller@gcc.gnu.org>
Wed, 20 Jun 2007 16:27:23 +0000 (16:27 +0000)
2007-06-20  Dirk Mueller  <dmueller@suse.de>

       PR c++/31809
       PR c++/31806
       Backport from mainline:
       2007-05-31  Jakub Jelinek  <jakub@redhat.com>

       * decl.c (cp_finish_decl): Also clear was_readonly if a static var
       needs runtime initialization.

       2007-05-30  Jakub Jelinek  <jakub@redhat.com>

       * decl.c (cp_finish_decl): Clear TREE_READONLY flag on TREE_STATIC
       variables that need runtime initialization.

       * g++.dg/opt/static5.C: New testcase
       * g++.dg/opt/static6.C: Likewise

From-SVN: r125887

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

index c330b427dec269322a49f8da264f21c81a4f8d03..9cb6d56e270009b8692e33f3cf2fa677a158948c 100644 (file)
@@ -1,3 +1,18 @@
+2007-06-20  Dirk Mueller  <dmueller@suse.de>
+
+       PR c++/31809
+       PR c++/31806
+       Backport from mainline:
+       2007-05-31  Jakub Jelinek  <jakub@redhat.com>
+
+       * decl.c (cp_finish_decl): Also clear was_readonly if a static var
+       needs runtime initialization.
+
+       2007-05-30  Jakub Jelinek  <jakub@redhat.com>
+
+       * decl.c (cp_finish_decl): Clear TREE_READONLY flag on TREE_STATIC
+       variables that need runtime initialization.
+
 2007-04-28  Andrew Pinski  <andrew_pinski@playstation.sony.com>
 
        PR C++/30221
index 3b9c470f6f832492e0fe5b36b5700389b15e34e3..32040abfa4f80cbdd021d0f6e1753e87a9eb23dd 100644 (file)
@@ -5240,7 +5240,15 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
             initializer.  It is not legal to redeclare a static data
             member, so this issue does not arise in that case.  */
          if (var_definition_p && TREE_STATIC (decl))
-           expand_static_init (decl, init);
+            {
+              if (init)
+                {
+                  if (TREE_READONLY (decl))
+                      TREE_READONLY (decl) = 0;
+                  was_readonly = 0;
+                }
+             expand_static_init (decl, init);
+            }
        }
     }
 
index 7cdf183da287eb1977b778b8dd8ab2e5f9da35bb..604970b1432fb1631a2f53df147e6a3d0fb461f0 100644 (file)
@@ -1,3 +1,10 @@
+2007-06-20  Dirk Mueller  <dmueller@suse.de>
+
+       PR c++/31806
+       PR c++/31809
+       * g++.dg/opt/static5.C: New test.
+       * g++.dg/opt/static6.C: New test.
+
 2007-06-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR inline-asm/32109
diff --git a/gcc/testsuite/g++.dg/opt/static5.C b/gcc/testsuite/g++.dg/opt/static5.C
new file mode 100644 (file)
index 0000000..1daca6d
--- /dev/null
@@ -0,0 +1,29 @@
+// PR c++/31809
+// { dg-do run }
+// { dg-options "-O2" }
+
+struct S
+{
+  unsigned v;
+  static inline S f (unsigned a);
+};
+
+inline S
+S::f (unsigned a)
+{
+  static S t = { a };
+  return t;
+}
+
+const static S s = S::f (26);
+
+extern "C" void abort (void);
+
+int
+main ()
+{
+  S t = s;
+  if (t.v != 26)
+    abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/opt/static6.C b/gcc/testsuite/g++.dg/opt/static6.C
new file mode 100644 (file)
index 0000000..00e76fb
--- /dev/null
@@ -0,0 +1,35 @@
+// PR c++/31806
+// { dg-do run }
+// { dg-options "-O2 -fno-inline -fno-threadsafe-statics" }
+
+extern "C" void abort(void);
+
+struct A
+{
+    void *d;
+};
+
+static const A& staticA()
+{
+    static A s_static;
+    return s_static;
+}
+
+void assert_failed()
+{
+    abort();
+}
+
+A testMethod()
+{
+    static const A& s = staticA( );
+    if (&s == 0)
+        assert_failed();
+    return s;
+}
+
+int main()
+{
+    testMethod();
+    return 0;
+}