Skip to content

Commit

Permalink
c++/modules: Propagate some missing flags on type definitions
Browse files Browse the repository at this point in the history
Noticed while testing my fix for PR c++/113814.  Not all of these are
easily testable but I've tested a couple that were straight-forward.

For consistency also adds a new TYPE_WARN_IF_NOT_ALIGN_RAW flag to match
the decl version Nathan added.

gcc/cp/ChangeLog:

	* module.cc (trees_in::read_class_def): Propagate some missing
	flags from the streamed-in definition.

gcc/ChangeLog:

	* tree.h (TYPE_WARN_IF_NOT_ALIGN_RAW): New accessor.
	(TYPE_WARN_IF_NOT_ALIGN): Use it.
	(SET_TYPE_WARN_IF_NOT_ALIGN): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Nathaniel Shead <[email protected]>
  • Loading branch information
wreien committed Oct 24, 2024
1 parent 29efc62 commit 6aba48a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
20 changes: 19 additions & 1 deletion gcc/cp/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12379,21 +12379,39 @@ trees_in::read_class_def (tree defn, tree maybe_template)

/* Core pieces. */
TYPE_MODE_RAW (type) = TYPE_MODE_RAW (type_dup);
TYPE_ALIGN_RAW (type) = TYPE_ALIGN_RAW (type_dup);
TYPE_WARN_IF_NOT_ALIGN_RAW (type)
= TYPE_WARN_IF_NOT_ALIGN_RAW (type_dup);
TYPE_USER_ALIGN (type) = TYPE_USER_ALIGN (type_dup);

SET_DECL_MODE (defn, DECL_MODE (maybe_dup));
TREE_ADDRESSABLE (type) = TREE_ADDRESSABLE (type_dup);
DECL_SIZE (defn) = DECL_SIZE (maybe_dup);
DECL_SIZE_UNIT (defn) = DECL_SIZE_UNIT (maybe_dup);
DECL_ALIGN_RAW (defn) = DECL_ALIGN_RAW (maybe_dup);
DECL_WARN_IF_NOT_ALIGN_RAW (defn)
= DECL_WARN_IF_NOT_ALIGN_RAW (maybe_dup);
DECL_USER_ALIGN (defn) = DECL_USER_ALIGN (maybe_dup);

TYPE_TYPELESS_STORAGE (type) = TYPE_TYPELESS_STORAGE (type_dup);
TYPE_CXX_ODR_P (type) = TYPE_CXX_ODR_P (type_dup);
TYPE_NO_FORCE_BLK (type) = TYPE_NO_FORCE_BLK (type_dup);
TYPE_TRANSPARENT_AGGR (type) = TYPE_TRANSPARENT_AGGR (type_dup);
TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type)
= TYPE_CONTAINS_PLACEHOLDER_INTERNAL (type_dup);

TYPE_EMPTY_P (type) = TYPE_EMPTY_P (type_dup);
TREE_ADDRESSABLE (type) = TREE_ADDRESSABLE (type_dup);

/* C++ pieces. */
TYPE_POLYMORPHIC_P (type) = TYPE_POLYMORPHIC_P (type_dup);
CLASSTYPE_FINAL (type) = CLASSTYPE_FINAL (type_dup);

TYPE_HAS_USER_CONSTRUCTOR (type)
= TYPE_HAS_USER_CONSTRUCTOR (type_dup);
TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
= TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type_dup);
TYPE_NEEDS_CONSTRUCTING (type)
= TYPE_NEEDS_CONSTRUCTING (type_dup);

if (auto ls = TYPE_LANG_SPECIFIC (type_dup))
{
Expand Down
6 changes: 6 additions & 0 deletions gcc/testsuite/g++.dg/modules/class-10_a.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// { dg-additional-options "-fmodule-header" }
// { dg-module-cmi {} }

struct alignas(16) Align {};
struct Final final {};
struct NeedsConstructing { NeedsConstructing(); };
19 changes: 19 additions & 0 deletions gcc/testsuite/g++.dg/modules/class-10_b.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// { dg-additional-options "-fmodules-ts -Wno-pedantic" }
// Test bits and pieces of merging information
// from class defs into forward declarations

struct Align;
struct Final;
struct NeedsConstructing;

import "class-10_a.H";

static_assert(alignof(Align) == 16);

struct TestFinal : Final {}; // { dg-error "cannot derive" }

struct TestNeedsConstructing {
struct {
NeedsConstructing a; // { dg-error "with constructor not allowed in anonymous aggregate" }
};
};
8 changes: 5 additions & 3 deletions gcc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2357,13 +2357,15 @@ extern tree vector_element_bits_tree (const_tree);

/* The minimum alignment necessary for objects of this type without
warning. The value is an int, measured in bits. */
#define TYPE_WARN_IF_NOT_ALIGN_RAW(NODE) \
(TYPE_CHECK (NODE)->type_common.warn_if_not_align)
#define TYPE_WARN_IF_NOT_ALIGN(NODE) \
(TYPE_CHECK (NODE)->type_common.warn_if_not_align \
? ((unsigned)1) << ((NODE)->type_common.warn_if_not_align - 1) : 0)
(TYPE_WARN_IF_NOT_ALIGN_RAW (NODE) \
? ((unsigned)1) << (TYPE_WARN_IF_NOT_ALIGN_RAW (NODE) - 1) : 0)

/* Specify that TYPE_WARN_IF_NOT_ALIGN(NODE) is X. */
#define SET_TYPE_WARN_IF_NOT_ALIGN(NODE, X) \
(TYPE_CHECK (NODE)->type_common.warn_if_not_align = ffs_hwi (X))
(TYPE_WARN_IF_NOT_ALIGN_RAW (NODE) = ffs_hwi (X))

/* If your language allows you to declare types, and you want debug info
for them, then you need to generate corresponding TYPE_DECL nodes.
Expand Down

0 comments on commit 6aba48a

Please sign in to comment.