re PR lto/46083 (gcc.dg/initpri1.c FAILs with -flto/-fwhopr (attribute constructor...
authorJan Hubicka <jh@suse.cz>
Mon, 10 Jan 2011 21:54:33 +0000 (22:54 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Mon, 10 Jan 2011 21:54:33 +0000 (21:54 +0000)
PR lto/46083
* lto-streamer-out.c (pack_ts_function_decl_value_fields): Store
DECL_FINI_PRIORITY.
* lto-streamer-in.c (unpack_ts_function_decl_value_fields):
Restore DECL_FINI_PRIORITY.
* gcc.dg/initpri3.c: New testcase.

From-SVN: r168642

gcc/ChangeLog
gcc/lto-streamer-in.c
gcc/lto-streamer-out.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/initpri3.c [new file with mode: 0644]

index d7ffbef94c81779adbe0053ca1824f109e4fe376..14d5066fdf03ccc9c07f16510821cc2d3ca1d1b7 100644 (file)
@@ -1,3 +1,11 @@
+2011-01-10  Jan Hubicka  <jh@suse.cz>
+
+       PR lto/46083
+       * lto-streamer-out.c (pack_ts_function_decl_value_fields): Store
+       DECL_FINI_PRIORITY.
+       * lto-streamer-in.c (unpack_ts_function_decl_value_fields):
+       Restore DECL_FINI_PRIORITY.
+
 2011-01-10  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        * doc/gimple.texi: Fix quoting of multi-word return values in
index 4fe9cdb2c6bc51c84834fae2286eeded2524e73d..ba48cbb3f60ea649b38ab3cf560dbbb467c13086 100644 (file)
@@ -1683,6 +1683,11 @@ unpack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
   DECL_DISREGARD_INLINE_LIMITS (expr) = (unsigned) bp_unpack_value (bp, 1);
   DECL_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
   DECL_LOOPING_CONST_OR_PURE_P (expr) = (unsigned) bp_unpack_value (bp, 1);
+  if (DECL_STATIC_DESTRUCTOR (expr))
+    {
+       priority_type p = (priority_type) bp_unpack_value (bp, HOST_BITS_PER_SHORT);
+       SET_DECL_FINI_PRIORITY (expr, p);
+    }
 }
 
 
index 781b2571c196eb1e0f4eed22b921874b66cdd583..82c2f6feae51704e655ce496c5f6e085a1c5f01b 100644 (file)
@@ -496,6 +496,8 @@ pack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
   bp_pack_value (bp, DECL_DISREGARD_INLINE_LIMITS (expr), 1);
   bp_pack_value (bp, DECL_PURE_P (expr), 1);
   bp_pack_value (bp, DECL_LOOPING_CONST_OR_PURE_P (expr), 1);
+  if (DECL_STATIC_DESTRUCTOR (expr))
+    bp_pack_value (bp, DECL_FINI_PRIORITY (expr), HOST_BITS_PER_SHORT);
 }
 
 
index 08241ca719e8dbfd03f3ce97e6ea5db28e6d903e..6df0d8e0dd9920bd129e5517eeae4db6e6ab0dc0 100644 (file)
@@ -1,3 +1,8 @@
+2011-01-10  Jan Hubicka  <jh@suse.cz>
+
+       PR lto/46083
+       * gcc.dg/initpri3.c: New testcase.
+
 2011-01-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR lto/47222
diff --git a/gcc/testsuite/gcc.dg/initpri3.c b/gcc/testsuite/gcc.dg/initpri3.c
new file mode 100644 (file)
index 0000000..1633da0
--- /dev/null
@@ -0,0 +1,64 @@
+/* { dg-do run { target init_priority } } */
+/* { dg-require-effective-target lto } */
+/* { dg-options "-flto -O3" } */
+
+extern void abort ();
+
+int i;
+int j;
+
+void c1() __attribute__((constructor (500)));
+void c2() __attribute__((constructor (700)));
+void c3() __attribute__((constructor (600)));
+
+void c1() {
+  if (i++ != 0)
+    abort ();
+}
+
+void c2() {
+  if (i++ != 2)
+    abort ();
+}
+
+void c3() {
+  if (i++ != 1)
+    abort ();
+}
+
+void d1() __attribute__((destructor (500)));
+void d2() __attribute__((destructor (700)));
+void d3() __attribute__((destructor (600)));
+
+void d1() {
+  if (--i != 0)
+    abort ();
+}
+
+void d2() {
+  if (--i != 2)
+    abort ();
+}
+
+void d3() {
+  if (j != 2)
+    abort ();
+  if (--i != 1)
+    abort ();
+}
+
+void cd4() __attribute__((constructor (800), destructor (800)));
+
+void cd4() {
+  if (i != 3)
+    abort ();
+  ++j;
+}
+
+int main () {
+  if (i != 3)
+    return 1;
+  if (j != 1)
+    abort ();
+  return 0;
+}