diff options
author | Nathaniel Shead <nathanieloshead@gmail.com> | 2025-07-25 08:21:55 +1000 |
---|---|---|
committer | Nathaniel Shead <nathanieloshead@gmail.com> | 2025-07-27 10:07:14 +1000 |
commit | 68ddec92d4066328c127fdaa28ccadf10a738446 (patch) | |
tree | f2d4de66c308d31e224d3e6928ca79149d331cf7 | |
parent | 11518c841dda4d417573e41ded69bd1469ad6d1f (diff) | |
download | gcc-68ddec92d4066328c127fdaa28ccadf10a738446.zip gcc-68ddec92d4066328c127fdaa28ccadf10a738446.tar.gz gcc-68ddec92d4066328c127fdaa28ccadf10a738446.tar.bz2 |
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 <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
-rw-r--r-- | gcc/cp/cp-tree.h | 4 | ||||
-rw-r--r-- | gcc/cp/module.cc | 22 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/modules/class-11_a.H | 36 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/modules/class-11_b.C | 15 |
4 files changed, 73 insertions, 4 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index c8391d6..0ac3ecb 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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 diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 0a689bb..2f6a8ab 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -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 index 0000000..f7bbf9d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/class-11_a.H @@ -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 index 0000000..2450a45 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/class-11_b.C @@ -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 } } +}; |