]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Warn for optimize attributes instead of ICEing [PR108080]
authorNathaniel Shead <nathanieloshead@gmail.com>
Tue, 29 Jul 2025 11:46:59 +0000 (21:46 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 1 Aug 2025 02:34:00 +0000 (12:34 +1000)
This PR is the most frequently reported modules bug for 15, as the ICE
message does not indicate the issue at all and reducing to find the
underlying cause can be tricky.

I have a WIP patch to fix this issue by just reconstructing these nodes
on stream-in from any attributes applied to the functions, but since at
this stage it may still take a while to be ready, it seems useful to me
to at least make the error here more friendly and guide users to what
they could do to work around this issue.

In fact, as noted on the PR, a lot of the time it should be harmless to
just ignore the optimize etc. attribute and continue translation, at the
user's own risk; this patch as such turns the ICE into a warning with no
option to silence.

PR c++/108080

gcc/cp/ChangeLog:

* module.cc (trees_out::core_vals): Warn when streaming
target/optimize node; adjust comments.
(trees_in::core_vals): Don't stream a target/optimize node.

gcc/testsuite/ChangeLog:

* g++.dg/modules/pr108080.H: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
(cherry picked from commit 643c5b42e21dbc02e9bde01865c880b26aa5f938)

gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/pr108080.H [new file with mode: 0644]

index 0aa2992cf5b7c7e58bee3d09af0bbff0d775543b..1deadcc189abc9fdd6028df0f56f7fa8493e02e7 100644 (file)
@@ -6542,8 +6542,14 @@ trees_out::core_vals (tree t)
        }
 
       WT (t->function_decl.personality);
-      WT (t->function_decl.function_specific_target);
-      WT (t->function_decl.function_specific_optimization);
+      /* Rather than streaming target/optimize nodes, we should reconstruct
+        them on stream-in from any attributes applied to the function.  */
+      if (streaming_p () && t->function_decl.function_specific_target)
+       warning_at (DECL_SOURCE_LOCATION (t), 0,
+                   "%<target%> attribute currently unsupported in modules");
+      if (streaming_p () && t->function_decl.function_specific_optimization)
+       warning_at (DECL_SOURCE_LOCATION (t), 0,
+                   "%<optimize%> attribute currently unsupported in modules");
       WT (t->function_decl.vindex);
 
       if (DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (t))
@@ -6633,11 +6639,12 @@ trees_out::core_vals (tree t)
     case TARGET_OPTION_NODE:
       // FIXME: Our representation for these two nodes is a cache of
       // the resulting set of options.  Not a record of the options
-      // that got changed by a particular attribute or pragma.  Should
-      // we record that, or should we record the diff from the command
-      // line options?  The latter seems the right behaviour, but is
-      // (a) harder, and I guess could introduce strangeness if the
-      // importer has set some incompatible set of optimization flags?
+      // that got changed by a particular attribute or pragma.  Instead
+      // of recording that, we probably should just rebuild the options
+      // on stream-in from the function attributes.  This could introduce
+      // strangeness if the importer has some incompatible set of flags
+      // but we currently assume users "know what they're doing" in such
+      // a case anyway.
       gcc_unreachable ();
       break;
 
@@ -7096,8 +7103,10 @@ trees_in::core_vals (tree t)
          }
 
        RT (t->function_decl.personality);
-       RT (t->function_decl.function_specific_target);
-       RT (t->function_decl.function_specific_optimization);
+       /* These properties are not streamed, and should be reconstructed
+          from any function attributes.  */
+       // t->function_decl.function_specific_target);
+       // t->function_decl.function_specific_optimization);
        RT (t->function_decl.vindex);
 
        if (DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (t))
@@ -7203,7 +7212,7 @@ trees_in::core_vals (tree t)
 
     case OPTIMIZATION_NODE:
     case TARGET_OPTION_NODE:
-      /* Not yet implemented, see trees_out::core_vals.  */
+      /* Not implemented, see trees_out::core_vals.  */
       gcc_unreachable ();
       break;
 
diff --git a/gcc/testsuite/g++.dg/modules/pr108080.H b/gcc/testsuite/g++.dg/modules/pr108080.H
new file mode 100644 (file)
index 0000000..b05d957
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/108080
+// { dg-additional-options "-fmodules" }
+// Give a diagnostic message rather than a crash for unsupported features.
+
+[[gnu::optimize("-O3")]] void foo();  // { dg-warning "optimize" }