https://gcc.gnu.org/g:5c2a5bfcd4e62daeb7d7f25db088816fd1d54194

commit r16-7101-g5c2a5bfcd4e62daeb7d7f25db088816fd1d54194
Author: Jakub Jelinek <[email protected]>
Date:   Wed Jan 28 09:48:10 2026 +0100

    free-lang-data: Remove C++ annotations [PR123837]
    
    As mentioned in the PR and reproduced on the testcase, we ICE during
    LTO streaming because C++ annotation arguments can contain trees LTO
    streaming doesn't handle.
    We don't really need annotations when the FE is done with the whole
    TU, annotations are always TU local and not exposed to the rest and
    used in consteval only stuff, so the following patch just removes
    all annotations at free-lang-data time.
    
    2026-01-28  Jakub Jelinek  <[email protected]>
    
            PR c++/123837
            * ipa-free-lang-data.cc (find_decls_types_r): Remove C++ annotations
            from {DECL,TYPE}_ATRIBUTES.
    
            * g++.dg/reflect/annotations9.C: New test.

Diff:
---
 gcc/ipa-free-lang-data.cc                   |  8 ++++++++
 gcc/testsuite/g++.dg/reflect/annotations9.C | 14 ++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc
index edc4f1aed811..f32563fdd22d 100644
--- a/gcc/ipa-free-lang-data.cc
+++ b/gcc/ipa-free-lang-data.cc
@@ -730,6 +730,10 @@ find_decls_types_r (tree *tp, int *ws, void *data)
       if (TREE_CODE (t) != TYPE_DECL)
        fld_worklist_push (DECL_INITIAL (t), fld);
 
+      /* Remove C++ annotations, those aren't needed for LTO and contain
+        trees we sometimes can't stream.  */
+      DECL_ATTRIBUTES (t)
+       = remove_attribute ("annotation ", DECL_ATTRIBUTES (t));
       fld_worklist_push (DECL_ATTRIBUTES (t), fld);
       fld_worklist_push (DECL_ABSTRACT_ORIGIN (t), fld);
 
@@ -763,6 +767,10 @@ find_decls_types_r (tree *tp, int *ws, void *data)
        fld_worklist_push (TYPE_CACHED_VALUES (t), fld);
       fld_worklist_push (TYPE_SIZE (t), fld);
       fld_worklist_push (TYPE_SIZE_UNIT (t), fld);
+      /* Remove C++ annotations, those aren't needed for LTO and contain
+        trees we sometimes can't stream.  */
+      TYPE_ATTRIBUTES (t)
+       = remove_attribute ("annotation ", TYPE_ATTRIBUTES (t));
       fld_worklist_push (TYPE_ATTRIBUTES (t), fld);
       fld_worklist_push (TYPE_POINTER_TO (t), fld);
       fld_worklist_push (TYPE_REFERENCE_TO (t), fld);
diff --git a/gcc/testsuite/g++.dg/reflect/annotations9.C 
b/gcc/testsuite/g++.dg/reflect/annotations9.C
new file mode 100644
index 000000000000..32078f281e1f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/annotations9.C
@@ -0,0 +1,14 @@
+// PR c++/123837
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+// { dg-additional-options "-flto" { target lto } }
+
+struct A {};
+[[=A {}]] int a {};
+struct [[=A {}]] B { int b; };
+B b {};
+
+int
+main ()
+{
+}

Reply via email to