]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/50199 (wrong code with -flto -fno-merge-constants)
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 07:54:21 +0000 (09:54 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 07:54:21 +0000 (09:54 +0200)
Backported from mainline
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.

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

From-SVN: r248638

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 045d632c016b141098c117ce0682e5c37262198a..e7ec0c7bc0748dedfb7ba8896b6995be7e003147 100644 (file)
@@ -1,3 +1,12 @@
+2017-05-30  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       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.
+
 2016-06-03  Release Manager
 
        * GCC 5.4.0 released.
index 073bf17cd10ff9fa84790da831289fa45202aaa7..7651143cb857cacb0cbbcbb3aa7a66b6f0106b8d 100644 (file)
@@ -827,6 +827,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 9424d657d5075f75c21487c51cca1ce0f731bd39..6015fe17c121d534540856acd0239b8856df6a98 100644 (file)
@@ -1,6 +1,11 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2017-01-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/50199
+       * gcc.dg/lto/pr50199_0.c: New test.
+
        2017-01-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/78949
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;
+}