On Fri, 25 Jul 2025, Nathaniel Shead wrote:

> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?
> 
> -- >8 --
> 
> I noticed that C++26 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 to help people remember about modules when adding more.
> 
> As a drive-by improvement, update gcc_assert with gcc_checking_assert in
> lang_type_bools streaming.

LGTM

> 
> 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 <nathanielosh...@gmail.com>
> ---
>  gcc/cp/cp-tree.h                          |  4 ++-
>  gcc/cp/module.cc                          | 22 ++++++++++++--
>  gcc/testsuite/g++.dg/modules/class-11_a.H | 36 +++++++++++++++++++++++
>  gcc/testsuite/g++.dg/modules/class-11_b.C | 15 ++++++++++
>  4 files changed, 73 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/modules/class-11_a.H
>  create mode 100644 gcc/testsuite/g++.dg/modules/class-11_b.C
> 
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index 01112aa894e..22bb70136f5 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 a551509ec0b..ed51837433e 100644
> --- a/gcc/cp/module.cc
> +++ b/gcc/cp/module.cc
> @@ -6157,7 +6157,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);
> @@ -6183,6 +6183,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
>  }
>  
> @@ -6227,8 +6235,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);
>  
> @@ -6253,6 +6261,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 00000000000..b14a8adb1ed
> --- /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 00000000000..476cb63308f
> --- /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 } }
> +};
> -- 
> 2.47.0
> 
> 

Reply via email to