https://gcc.gnu.org/g:251f6ba9131ebc8deab463c052e099a065796c2a

commit r12-10942-g251f6ba9131ebc8deab463c052e099a065796c2a
Author: Lewis Hyatt <lhy...@gmail.com>
Date:   Sun Jan 26 18:57:00 2025 -0500

    options: Adjust cl_optimization_compare to avoid checking ICE [PR115913]
    
    At the end of a sequence like:
     #pragma GCC push_options
     ...
     #pragma GCC pop_options
    
    the handler for pop_options calls cl_optimization_compare() (as generated by
    optc-save-gen.awk) to make sure that all global state has been restored to
    the value it had prior to the push_options call. The verification is
    performed for almost all entries in the global_options struct. This leads to
    unexpected checking asserts, as discussed in the PR, in case the state of
    warnings-related options has been intentionally modified in between
    push_options and pop_options via a call to #pragma GCC diagnostic. Address
    that by skipping the verification for CL_WARNING-flagged options.
    
    gcc/ChangeLog:
    
            PR middle-end/115913
            * optc-save-gen.awk (cl_optimization_compare): Skip options with
            CL_WARNING flag.
    
    gcc/testsuite/ChangeLog:
    
            PR middle-end/115913
            * c-c++-common/cpp/pr115913.c: New test.

Diff:
---
 gcc/optc-save-gen.awk                     | 5 +++++
 gcc/testsuite/c-c++-common/cpp/pr115913.c | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index 76e9b3cb9402..dd09fd38c87b 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -1451,6 +1451,11 @@ for (i = 0; i < n_opts; i++) {
        if (name == "")
                continue;
 
+       # We do not want to compare warning-related options, since they
+       # might have been modified by a #pragma GCC diagnostic.
+       if (flag_set_p("Warning", flags[i]))
+               continue;
+
        if (name in checked_options)
                continue;
        checked_options[name]++
diff --git a/gcc/testsuite/c-c++-common/cpp/pr115913.c 
b/gcc/testsuite/c-c++-common/cpp/pr115913.c
new file mode 100644
index 000000000000..b9d10cda8d24
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cpp/pr115913.c
@@ -0,0 +1,7 @@
+/* { dg-do preprocess } */
+/* PR middle-end/115913 */
+#pragma GCC push_options
+#pragma GCC diagnostic warning "-Wundef"
+/* The call to cl_optimization_compare performed by pop_options should not
+   lead to a checking failure.  */
+#pragma GCC pop_options

Reply via email to