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 4b278b1..64ec93f 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 7c589ac..6d8307d 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 93ca274..2e29dfc 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 632dd31..f0d7196 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 14bcd13..33540ea 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 f85816e..ba6f781 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;