Regtested on x86_64-pc-linux-gnu (so far just modules.exp), OK for
trunk if full bootstrap+regtest succeeds?  And maybe 15?

-- >8 --

We need to mark type info decls as addressable if we take them by
reference; this is done by walking the declaration during parsing and
marking the decl as needed.

However, with modules we don't stream tinfo decls directly; rather we
stream just their name and type and reconstruct them in the importer
directly.  This means that any addressable flags are not propagated, and
we error because TREE_ADDRESSABLE is not set despite taking its address.

But tinfo decls should always have TREE_ADDRESSABLE set, as any attempt
to use the tinfo decl will go through build_address anyway.  So this
patch fixes the issue by eagerly marking the constructed decl as
TREE_ADDRESSABLE so that modules gets this flag correctly set as well.

        PR c++/120350

gcc/cp/ChangeLog:

        * rtti.c (get_tinfo_decl_direct): Mark TREE_ADDRESSABLE.

gcc/testsuite/ChangeLog:

        * g++.dg/modules/tinfo-3_a.H: New test.
        * g++.dg/modules/tinfo-3_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
---
 gcc/cp/rtti.cc                           | 1 +
 gcc/testsuite/g++.dg/modules/tinfo-3_a.H | 7 +++++++
 gcc/testsuite/g++.dg/modules/tinfo-3_b.C | 8 ++++++++
 3 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/modules/tinfo-3_a.H
 create mode 100644 gcc/testsuite/g++.dg/modules/tinfo-3_b.C

diff --git a/gcc/cp/rtti.cc b/gcc/cp/rtti.cc
index 18bc479dc50..c06a18b3ff1 100644
--- a/gcc/cp/rtti.cc
+++ b/gcc/cp/rtti.cc
@@ -468,6 +468,7 @@ get_tinfo_decl_direct (tree type, tree name, int pseudo_ix)
       DECL_IGNORED_P (d) = 1;
       TREE_READONLY (d) = 1;
       TREE_STATIC (d) = 1;
+      TREE_ADDRESSABLE (d) = 1;
       /* Tell equal_address_to that different tinfo decls never
         overlap.  */
       if (vec_safe_is_empty (unemitted_tinfo_decls))
diff --git a/gcc/testsuite/g++.dg/modules/tinfo-3_a.H 
b/gcc/testsuite/g++.dg/modules/tinfo-3_a.H
new file mode 100644
index 00000000000..8b53e9848b0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/tinfo-3_a.H
@@ -0,0 +1,7 @@
+// PR c++/120350
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+#include <typeinfo>
+struct S {};
+inline const std::type_info& tinfo = typeid(S);
diff --git a/gcc/testsuite/g++.dg/modules/tinfo-3_b.C 
b/gcc/testsuite/g++.dg/modules/tinfo-3_b.C
new file mode 100644
index 00000000000..95e02ab5c81
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/tinfo-3_b.C
@@ -0,0 +1,8 @@
+// PR c++/120350
+// { dg-additional-options "-fmodules" }
+
+import "tinfo-3_a.H";
+
+int main() {
+  return tinfo == typeid(int);
+}
-- 
2.47.0

Reply via email to