Skip to content

Commit 68ddec9

Browse files
committed
c++/modules: Stream some missing lang_type flags
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 <[email protected]> Reviewed-by: Patrick Palka <[email protected]>
1 parent 11518c8 commit 68ddec9

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

gcc/cp/cp-tree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,9 @@ struct GTY(()) lang_type {
25082508

25092509
/* When adding a flag here, consider whether or not it ought to
25102510
apply to a template instance if it applies to the template. If
2511-
so, make sure to copy it in instantiate_class_template! */
2511+
so, make sure to copy it in instantiate_class_template!
2512+
2513+
Also make sure new flags here are streamed in module.cc. */
25122514

25132515
/* There are some bits left to fill out a 32-bit word. Keep track
25142516
of this by updating the size of this bitfield whenever you add or

gcc/cp/module.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6158,7 +6158,7 @@ trees_out::lang_type_bools (tree t, bits_out& bits)
61586158
WB (lang->declared_class);
61596159
WB (lang->diamond_shaped);
61606160
WB (lang->repeated_base);
6161-
gcc_assert (!lang->being_defined);
6161+
gcc_checking_assert (!lang->being_defined);
61626162
// lang->debug_requested
61636163
WB (lang->fields_readonly);
61646164
WB (lang->ptrmemfunc_flag);
@@ -6184,6 +6184,14 @@ trees_out::lang_type_bools (tree t, bits_out& bits)
61846184
WB (lang->has_constexpr_ctor);
61856185
WB (lang->unique_obj_representations);
61866186
WB (lang->unique_obj_representations_set);
6187+
gcc_checking_assert (!lang->erroneous);
6188+
WB (lang->non_pod_aggregate);
6189+
WB (lang->non_aggregate_pod);
6190+
WB (lang->trivially_relocatable);
6191+
WB (lang->trivially_relocatable_computed);
6192+
6193+
WB (lang->replaceable);
6194+
WB (lang->replaceable_computed);
61876195
#undef WB
61886196
}
61896197

@@ -6228,8 +6236,8 @@ trees_in::lang_type_bools (tree t, bits_in& bits)
62286236
RB (lang->declared_class);
62296237
RB (lang->diamond_shaped);
62306238
RB (lang->repeated_base);
6231-
gcc_assert (!lang->being_defined);
6232-
gcc_assert (!lang->debug_requested);
6239+
gcc_checking_assert (!lang->being_defined);
6240+
gcc_checking_assert (!lang->debug_requested);
62336241
RB (lang->fields_readonly);
62346242
RB (lang->ptrmemfunc_flag);
62356243

@@ -6254,6 +6262,14 @@ trees_in::lang_type_bools (tree t, bits_in& bits)
62546262
RB (lang->has_constexpr_ctor);
62556263
RB (lang->unique_obj_representations);
62566264
RB (lang->unique_obj_representations_set);
6265+
gcc_checking_assert (!lang->erroneous);
6266+
RB (lang->non_pod_aggregate);
6267+
RB (lang->non_aggregate_pod);
6268+
RB (lang->trivially_relocatable);
6269+
RB (lang->trivially_relocatable_computed);
6270+
6271+
RB (lang->replaceable);
6272+
RB (lang->replaceable_computed);
62576273
#undef RB
62586274
return !get_overrun ();
62596275
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Check for some additional lang_type flags that we'd missed.
2+
// { dg-additional-options "-fmodule-header -fabi-version=21 -Wabi=15" }
3+
// { dg-module-cmi {} }
4+
5+
#if __cpp_trivial_relocatability < 202502L
6+
#define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible
7+
#define replaceable_if_eligible __replaceable_if_eligible
8+
#endif
9+
10+
struct A trivially_relocatable_if_eligible { A(A&&); };
11+
struct B replaceable_if_eligible { B(B&&); B& operator=(B&&); };
12+
struct C {};
13+
static_assert(__builtin_is_trivially_relocatable(C) && __builtin_is_replaceable(C), "");
14+
15+
16+
struct pr106381 {
17+
long l;
18+
char c = -1;
19+
};
20+
struct L1 : pr106381 {
21+
char x; // { dg-warning "offset" "" { target c++14 } }
22+
};
23+
static_assert(sizeof(L1) == sizeof(pr106381));
24+
25+
26+
struct pr120012 {
27+
pr120012(const pr120012&) = default;
28+
pr120012(pr120012&&) = default;
29+
pr120012& operator=(pr120012&&) = default;
30+
unsigned int a;
31+
unsigned char b;
32+
};
33+
struct L2 : pr120012 {
34+
unsigned char y; // { dg-warning "offset" "" { target c++20 } }
35+
};
36+
static_assert(sizeof(L2) > sizeof(pr120012));
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// { dg-additional-options "-fmodules -fabi-version=21 -Wabi=15" }
2+
3+
import "class-11_a.H";
4+
5+
static_assert(__builtin_is_trivially_relocatable(A), "");
6+
static_assert(__builtin_is_replaceable(B), "");
7+
static_assert(__builtin_is_trivially_relocatable(C) && __builtin_is_replaceable(C), "");
8+
9+
struct M1 : pr106381 {
10+
char x; // { dg-warning "offset" "" { target c++14 } }
11+
};
12+
13+
struct M2 : pr120012 {
14+
unsigned char y; // { dg-warning "offset" "" { target c++20 } }
15+
};

0 commit comments

Comments
 (0)