From 2e0bb9eec2d455840bc4773391b3313a320b3c23 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 1 Mar 2021 05:41:10 -0800 Subject: c++: Completeness of typedef structs [PR 99294] When we read in a class definition, we use fixup_type_variants to propagate the now-completed fields of the class's TYPE to other variants. Unfortunately that doesn't propagate all of them, and in this case we had a typedef to an (incomplete) instantiation. That typedef ended up with a VOIDmode, which blew up gimple expansion as the type itself isn't VOID. Without modules, that information is propagated in finalize_type_size when laying out the class. But that doesn't happen with stream-in -- we already know the layout. There is already some overlap between the two functions, now there's a bit more. In fixup_type_variants, I pay attention to the TYPE_NAME to decide whether to override a user's TYPE_ALIGN -- variants of the main-variant typedef just copy the main-variant. Other variants recalculate. Overaligning is still permitted. I also added a TYPE_ALIGN_RAW accessor, and fixed a bug in the alignment streaming I noticed. I did not refactor TYPE_ALIGN beyond using the new accessor. (It could be written as ((1 << align_raw) >> 1), rather than use the conditional.) PR c++/99294 gcc/ * tree.h (TYPE_ALIGN_RAW): New accessor. (TYPE_ALIGN): Use it. gcc/cp/ * class.c (fixup_type_variants): Propagate mode, precision, alignment & emptiness. * module.cc (trees_out::type_node): Use TYPE_ALIGN_RAW. (trees_in::tree_node): Rematerialize alignment here. gcc/testsuite/ * g++.dg/modules/pr99294.h: New. * g++.dg/modules/pr99294_a.C: New. * g++.dg/modules/pr99294_b.C: New. --- gcc/tree.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'gcc/tree.h') diff --git a/gcc/tree.h b/gcc/tree.h index 4f33868..f00ea2e 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -2078,12 +2078,16 @@ extern tree vector_element_bits_tree (const_tree); to this type. */ #define TYPE_ATTRIBUTES(NODE) (TYPE_CHECK (NODE)->type_common.attributes) +/* Raw access to the alignment field. */ +#define TYPE_ALIGN_RAW(NODE) \ + (TYPE_CHECK (NODE)->type_common.align) + /* The alignment necessary for objects of this type. The value is an int, measured in bits and must be a power of two. We support also an "alignment" of zero. */ -#define TYPE_ALIGN(NODE) \ - (TYPE_CHECK (NODE)->type_common.align \ - ? ((unsigned)1) << ((NODE)->type_common.align - 1) : 0) +#define TYPE_ALIGN(NODE) \ + (TYPE_ALIGN_RAW (NODE) \ + ? ((unsigned)1) << (TYPE_ALIGN_RAW(NODE) - 1) : 0) /* Specify that TYPE_ALIGN(NODE) is X. */ #define SET_TYPE_ALIGN(NODE, X) \ -- cgit v1.1