re PR middle-end/50199 (wrong code with -flto -fno-merge-constants)
authorJakub Jelinek <jakub@redhat.com>
Wed, 11 Jan 2017 08:40:59 +0000 (09:40 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 11 Jan 2017 08:40:59 +0000 (09:40 +0100)
PR middle-end/50199
* lto-lang.c (lto_post_options): Force flag_merge_constants = 1
if it was 0.

* gcc.dg/lto/pr50199_0.c: New test.

From-SVN: r244304

gcc/lto/ChangeLog
gcc/lto/lto-lang.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/lto/pr50199_0.c [new file with mode: 0644]

index f94add5585224b5e9c6df77f4dbc7c0b2e070f2f..9bf6df015445b018e2b88911b807361704433aee 100644 (file)
@@ -1,3 +1,9 @@
+2017-01-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/50199
+       * lto-lang.c (lto_post_options): Force flag_merge_constants = 1
+       if it was 0.
+
 2017-01-09  Jakub Jelinek  <jakub@redhat.com>
 
        PR translation/79019
index c2b49dc44b687e6b9655def2d5a8fcb07452ce16..fccb8c61f8f30a02347dcced088e7db46e864bfd 100644 (file)
@@ -857,6 +857,12 @@ lto_post_options (const char **pfilename ATTRIBUTE_UNUSED)
      support.  */
   flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
 
+  /* When partitioning, we can tear appart STRING_CSTs uses from the same
+     TU into multiple partitions.  Without constant merging the constants
+     might not be equal at runtime.  See PR50199.  */
+  if (!flag_merge_constants)
+    flag_merge_constants = 1;
+
   /* Initialize the compiler back end.  */
   return false;
 }
index c332d9062e045fa9f104618e2e2f76d9ef3e4f9b..2b5f3b9dca00c07b25dd18621c3040742fec17c4 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/50199
+       * gcc.dg/lto/pr50199_0.c: New test.
+
 2017-01-10  Martin Sebor  <msebor@redhat.com>
 
        PR testsuite/78960
diff --git a/gcc/testsuite/gcc.dg/lto/pr50199_0.c b/gcc/testsuite/gcc.dg/lto/pr50199_0.c
new file mode 100644 (file)
index 0000000..61d0012
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR middle-end/50199 */
+/* { dg-lto-options {{-O2 -flto -fno-merge-constants --param=lto-min-partition=1}} } */
+
+__attribute__ ((noinline)) const char *
+foo (const char *x)
+{
+  return x;
+}
+
+int
+main ()
+{
+  const char *a = "ab";
+  if (a != foo (a))
+    __builtin_abort ();
+  return 0;
+}