]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Stream some missing lang_type flags
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 24 Jul 2025 22:21:55 +0000 (08:21 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sun, 27 Jul 2025 00:07:14 +0000 (10:07 +1000)
I noticed that trivial relocation didn't work in modules yet, and there
are a couple of other flags that seem potentially useful we weren't
streaming.  This streams those flags and adds a comment to cp-tree.h in
the hope that people will remember about modules when adding more!

As a drive-by improvement, update gcc_assert with gcc_checking_assert in
lang_type_bools streaming.

gcc/cp/ChangeLog:

* cp-tree.h (struct lang_type): Add comment mentioning modules.
* module.cc (trees_out::lang_type_bools): Stream new flags, use
gcc_checking_assert.
(trees_in::lang_type_bools): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/modules/class-11_a.H: New test.
* g++.dg/modules/class-11_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
gcc/cp/cp-tree.h
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/class-11_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/class-11_b.C [new file with mode: 0644]

index c8391d60cdac26129edb8f762415ee36a948f2d3..0ac3ecbd4c3a2985124a0b07a45415e50925ad90 100644 (file)
@@ -2508,7 +2508,9 @@ struct GTY(()) lang_type {
 
   /* When adding a flag here, consider whether or not it ought to
      apply to a template instance if it applies to the template.  If
-     so, make sure to copy it in instantiate_class_template!  */
+     so, make sure to copy it in instantiate_class_template!
+
+     Also make sure new flags here are streamed in module.cc.  */
 
   /* There are some bits left to fill out a 32-bit word.  Keep track
      of this by updating the size of this bitfield whenever you add or
index 0a689bb32233325624045aabf84a5798c8373885..2f6a8ab98fa9806e84d53f9182186c2b45920031 100644 (file)
@@ -6158,7 +6158,7 @@ trees_out::lang_type_bools (tree t, bits_out& bits)
   WB (lang->declared_class);
   WB (lang->diamond_shaped);
   WB (lang->repeated_base);
-  gcc_assert (!lang->being_defined);
+  gcc_checking_assert (!lang->being_defined);
   // lang->debug_requested
   WB (lang->fields_readonly);
   WB (lang->ptrmemfunc_flag);
@@ -6184,6 +6184,14 @@ trees_out::lang_type_bools (tree t, bits_out& bits)
   WB (lang->has_constexpr_ctor);
   WB (lang->unique_obj_representations);
   WB (lang->unique_obj_representations_set);
+  gcc_checking_assert (!lang->erroneous);
+  WB (lang->non_pod_aggregate);
+  WB (lang->non_aggregate_pod);
+  WB (lang->trivially_relocatable);
+  WB (lang->trivially_relocatable_computed);
+
+  WB (lang->replaceable);
+  WB (lang->replaceable_computed);
 #undef WB
 }
 
@@ -6228,8 +6236,8 @@ trees_in::lang_type_bools (tree t, bits_in& bits)
   RB (lang->declared_class);
   RB (lang->diamond_shaped);
   RB (lang->repeated_base);
-  gcc_assert (!lang->being_defined);
-  gcc_assert (!lang->debug_requested);
+  gcc_checking_assert (!lang->being_defined);
+  gcc_checking_assert (!lang->debug_requested);
   RB (lang->fields_readonly);
   RB (lang->ptrmemfunc_flag);
 
@@ -6254,6 +6262,14 @@ trees_in::lang_type_bools (tree t, bits_in& bits)
   RB (lang->has_constexpr_ctor);
   RB (lang->unique_obj_representations);
   RB (lang->unique_obj_representations_set);
+  gcc_checking_assert (!lang->erroneous);
+  RB (lang->non_pod_aggregate);
+  RB (lang->non_aggregate_pod);
+  RB (lang->trivially_relocatable);
+  RB (lang->trivially_relocatable_computed);
+
+  RB (lang->replaceable);
+  RB (lang->replaceable_computed);
 #undef RB
   return !get_overrun ();
 }
diff --git a/gcc/testsuite/g++.dg/modules/class-11_a.H b/gcc/testsuite/g++.dg/modules/class-11_a.H
new file mode 100644 (file)
index 0000000..f7bbf9d
--- /dev/null
@@ -0,0 +1,36 @@
+// Check for some additional lang_type flags that we'd missed.
+// { dg-additional-options "-fmodule-header -fabi-version=21 -Wabi=15" }
+// { dg-module-cmi {} }
+
+#if __cpp_trivial_relocatability < 202502L
+#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible
+#define replaceable_if_eligible __replaceable_if_eligible
+#endif
+
+struct A trivially_relocatable_if_eligible { A(A&&); };
+struct B replaceable_if_eligible { B(B&&); B& operator=(B&&); };
+struct C {};
+static_assert(__builtin_is_trivially_relocatable(C) && __builtin_is_replaceable(C), "");
+
+
+struct pr106381 {
+  long l;
+  char c = -1;
+};
+struct L1 : pr106381 {
+  char x;  // { dg-warning "offset" "" { target c++14 } }
+};
+static_assert(sizeof(L1) == sizeof(pr106381));
+
+
+struct pr120012 {
+  pr120012(const pr120012&) = default;
+  pr120012(pr120012&&) = default;
+  pr120012& operator=(pr120012&&) = default;
+  unsigned int a;
+  unsigned char b;
+};
+struct L2 : pr120012 {
+  unsigned char y;  // { dg-warning "offset" "" { target c++20 } }
+};
+static_assert(sizeof(L2) > sizeof(pr120012));
diff --git a/gcc/testsuite/g++.dg/modules/class-11_b.C b/gcc/testsuite/g++.dg/modules/class-11_b.C
new file mode 100644 (file)
index 0000000..2450a45
--- /dev/null
@@ -0,0 +1,15 @@
+// { dg-additional-options "-fmodules -fabi-version=21 -Wabi=15" }
+
+import "class-11_a.H";
+
+static_assert(__builtin_is_trivially_relocatable(A), "");
+static_assert(__builtin_is_replaceable(B), "");
+static_assert(__builtin_is_trivially_relocatable(C) && __builtin_is_replaceable(C), "");
+
+struct M1 : pr106381 {
+  char x;  // { dg-warning "offset" "" { target c++14 } }
+};
+
+struct M2 : pr120012 {
+  unsigned char y;  // { dg-warning "offset" "" { target c++20 } }
+};