Bootstrapped and regtested on x86_64-pc-linux-gnu.

I did a quick skim to see if I could find any more likely missing flags
but I think this should be all of them now.

-- >8 --

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 <nathanielosh...@gmail.com>
---
 gcc/cp/module.cc                          | 20 +++++++++++++++++++-
 gcc/testsuite/g++.dg/modules/class-10_a.H |  6 ++++++
 gcc/testsuite/g++.dg/modules/class-10_b.C | 19 +++++++++++++++++++
 gcc/tree.h                                |  8 +++++---
 4 files changed, 49 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/class-10_a.H
 create mode 100644 gcc/testsuite/g++.dg/modules/class-10_b.C

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index fd9b1d3bf2e..e8c9a876903 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -12379,8 +12379,12 @@ 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);
@@ -12388,12 +12392,26 @@ trees_in::read_class_def (tree defn, tree 
maybe_template)
            = 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))
            {
diff --git a/gcc/testsuite/g++.dg/modules/class-10_a.H 
b/gcc/testsuite/g++.dg/modules/class-10_a.H
new file mode 100644
index 00000000000..177cf57fec1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/class-10_a.H
@@ -0,0 +1,6 @@
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+struct alignas(16) Align {};
+struct Final final {};
+struct NeedsConstructing { NeedsConstructing(); };
diff --git a/gcc/testsuite/g++.dg/modules/class-10_b.C 
b/gcc/testsuite/g++.dg/modules/class-10_b.C
new file mode 100644
index 00000000000..2f982124f3e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/class-10_b.C
@@ -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" }
+  };
+};
diff --git a/gcc/tree.h b/gcc/tree.h
index f4c89f5477c..1bd43531b9c 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -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.
-- 
2.46.0

Reply via email to