re PR c++/61564 (#pragma GCC optimize ("-fno-lto") causes the compiler to crash)
authorRichard Biener <rguenther@suse.de>
Tue, 7 Jun 2016 12:41:46 +0000 (12:41 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 7 Jun 2016 12:41:46 +0000 (12:41 +0000)
2016-06-07  Richard Biener  <rguenther@suse.de>

PR c/61564
* c-common.c (parse_optimize_options): Only apply CL_OPTIMIZATION
options and warn about others.
* common.opt (ffast-math): Make Optimization.

* gcc.dg/Wpragmas-1.c: New testcase.
* gcc.dg/Wattributes-4.c: Likewise.
* gcc.dg/ipa/pr70646.c: Drop optimize pragma in favor of dg-option
entry.

From-SVN: r237174

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/common.opt
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wattributes-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wpragmas-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/pr70646.c

index 4b278b18a4b79d1bc7695e54d802f86408211985..64ec93ff5a28f73c4ebaa474e3d9994a6ab91e7d 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-07  Richard Biener  <rguenther@suse.de>
+
+       PR c/61564
+       * common.opt (ffast-math): Make Optimization.
+
 2016-06-07  Simon Dardis  <simon.dardis@imgtec.com>
            Prachi Godbole  <prachi.godbole@imgtec.com>
 
index 7c589acf20c8a9a531d2aaac5b8ad70c4a77fa3f..6d8307d9f2ae8a4d73818d6da602800226a93be8 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-07  Richard Biener  <rguenther@suse.de>
+
+       PR c/61564
+       * c-common.c (parse_optimize_options): Only apply CL_OPTIMIZATION
+       options and warn about others.
+
 2016-06-01  Eduard Sanou  <dhole@openmailbox.org>
 
        * c-common.c (get_source_date_epoch): Rename to
index 93ca274e7c8d711c2b011b399ebad96fa1b91ce9..2e29dfc6a1774f119c1d0721a3d6ee3e6d1fcff4 100644 (file)
@@ -9580,6 +9580,29 @@ parse_optimize_options (tree args, bool attr_p)
   decode_cmdline_options_to_array_default_mask (opt_argc, opt_argv,
                                                &decoded_options,
                                                &decoded_options_count);
+  /* Drop non-Optimization options.  */
+  unsigned j = 1;
+  for (i = 1; i < decoded_options_count; ++i)
+    {
+      if (! (cl_options[decoded_options[i].opt_index].flags & CL_OPTIMIZATION))
+       {
+         ret = false;
+         if (attr_p)
+           warning (OPT_Wattributes,
+                    "bad option %s to optimize attribute",
+                    decoded_options[i].orig_option_with_args_text);
+         else
+           warning (OPT_Wpragmas,
+                    "bad option %s to pragma attribute",
+                    decoded_options[i].orig_option_with_args_text);
+         continue;
+       }
+      if (i != j)
+       decoded_options[j] = decoded_options[i];
+      j++;
+    }
+  decoded_options_count = j;
+  /* And apply them.  */
   decode_options (&global_options, &global_options_set,
                  decoded_options, decoded_options_count,
                  input_location, global_dc);
index 632dd311fba3a94cb22c3bf7ffbb0919a6533bdc..f0d71966cdf3e17945dd57892ba41dbb06d06a47 100644 (file)
@@ -1287,7 +1287,7 @@ EnumValue
 Enum(excess_precision) String(standard) Value(EXCESS_PRECISION_STANDARD)
 
 ffast-math
-Common
+Common Optimization
 
 ffat-lto-objects
 Common Var(flag_fat_lto_objects)
index 14bcd131a65888a4f191577989c6681c50f6faa8..33540eaa20e982516c50aec75fc0aba1233bd7c8 100644 (file)
@@ -1,3 +1,11 @@
+2016-06-07  Richard Biener  <rguenther@suse.de>
+
+       PR c/61564
+       * gcc.dg/Wpragmas-1.c: New testcase.
+       * gcc.dg/Wattributes-4.c: Likewise.
+       * gcc.dg/ipa/pr70646.c: Drop optimize pragma in favor of dg-option
+       entry.
+
 2016-06-07  Christophe Lyon  <christophe.lyon@linaro.org>
 
        * gcc.target/aarch64/advsimd-intrinsics/p64_p128.c: Remove
diff --git a/gcc/testsuite/gcc.dg/Wattributes-4.c b/gcc/testsuite/gcc.dg/Wattributes-4.c
new file mode 100644 (file)
index 0000000..abda5a3
--- /dev/null
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+
+int __attribute__((optimize("no-lto"))) main(void){return 0;} /* { dg-warning "bad option" } */
diff --git a/gcc/testsuite/gcc.dg/Wpragmas-1.c b/gcc/testsuite/gcc.dg/Wpragmas-1.c
new file mode 100644 (file)
index 0000000..139519e
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+
+#pragma GCC push_options
+#pragma GCC optimize ("-fno-lto") /* { dg-warning "bad option" } */
+int main(void){return 0;}
+#pragma GCC pop_options
+
+/* ???  The FEs still apply the pragma string as optimize attribute to
+   all functions thus the diagnostic will be repeated for each function
+   affected.  */
+/* { dg-message "bad option" "" { target *-*-* } 0 } */
index f85816e7303dfa637033a9b8dc565d4c49314ca1..ba6f781a1458531d279ea7f7830e32f92a7746c6 100644 (file)
@@ -1,7 +1,5 @@
 /* { dg-do run } */
-/* { dg-options "-O2" } */
-
-#pragma GCC optimize("no-unit-at-a-time")
+/* { dg-options "-O2 -fno-unit-at-a-time" } */
 
 typedef unsigned char u8;
 typedef unsigned long long u64;