[clang] 19d300f - Revert "[clang][CodeGen] Use base subobject type layout for potentially-overlapping fields"

Vladislav Dzhidzhoev via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 15 07:12:45 PST 2022


Author: Vladislav Dzhidzhoev
Date: 2022-12-15T18:12:26+03:00
New Revision: 19d300fb4150b94f6dc7d8d230553d36349a3002

URL: https://github.com/llvm/llvm-project/commit/19d300fb4150b94f6dc7d8d230553d36349a3002
DIFF: https://github.com/llvm/llvm-project/commit/19d300fb4150b94f6dc7d8d230553d36349a3002.diff

LOG: Revert "[clang][CodeGen] Use base subobject type layout for potentially-overlapping fields"

This reverts commit 731abdfdcc33d813e6c3b4b89eff307aa5c18083.

This commit breaks some tests in libcxx, e.g.
`std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp`

Added: 
    

Modified: 
    clang/include/clang/AST/Decl.h
    clang/lib/AST/Decl.cpp
    clang/lib/AST/RecordLayoutBuilder.cpp
    clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Removed: 
    clang/test/CodeGenCXX/no-unique-address-3.cpp


################################################################################
diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 268ec7deeb81..cd33fcef5661 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3062,10 +3062,6 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
   /// [[no_unique_address]] attribute.
   bool isZeroSize(const ASTContext &Ctx) const;
 
-  /// Determine if this field is of potentially-overlapping class type, that
-  /// is, subobject with the [[no_unique_address]] attribute
-  bool isPotentiallyOverlapping() const;
-
   /// Get the kind of (C++11) default member initializer that this field has.
   InClassInitStyle getInClassInitStyle() const {
     InitStorageKind storageKind = InitStorage.getInt();

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 0f15d7b3b6d3..b1fdc897bf27 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4339,10 +4339,6 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
   return true;
 }
 
-bool FieldDecl::isPotentiallyOverlapping() const {
-  return hasAttr<NoUniqueAddressAttr>() && getType()->getAsCXXRecordDecl();
-}
-
 unsigned FieldDecl::getFieldIndex() const {
   const FieldDecl *Canonical = getCanonicalDecl();
   if (Canonical != this)

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp
index 56cdbb75dd4b..52bd3f20221f 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1853,8 +1853,9 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
 void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
                                              bool InsertExtraPadding) {
   auto *FieldClass = D->getType()->getAsCXXRecordDecl();
+  bool PotentiallyOverlapping = D->hasAttr<NoUniqueAddressAttr>() && FieldClass;
   bool IsOverlappingEmptyField =
-      D->isPotentiallyOverlapping() && FieldClass->isEmpty();
+      PotentiallyOverlapping && FieldClass->isEmpty();
 
   CharUnits FieldOffset =
       (IsUnion || IsOverlappingEmptyField) ? CharUnits::Zero() : getDataSize();
@@ -1915,7 +1916,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
 
     // A potentially-overlapping field occupies its dsize or nvsize, whichever
     // is larger.
-    if (D->isPotentiallyOverlapping()) {
+    if (PotentiallyOverlapping) {
       const ASTRecordLayout &Layout = Context.getASTRecordLayout(FieldClass);
       EffectiveFieldSize =
           std::max(Layout.getNonVirtualSize(), Layout.getDataSize());

diff  --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 0f2d764bc949..6f85bca8a201 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -379,14 +379,9 @@ void CGRecordLowering::accumulateFields() {
       for (++Field; Field != FieldEnd && Field->isBitField(); ++Field);
       accumulateBitFields(Start, Field);
     } else if (!Field->isZeroSize(Context)) {
-      // Use base subobject layout for the potentially-overlapping field,
-      // as it is done in RecordLayoutBuilder
       Members.push_back(MemberInfo(
           bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
-          Field->isPotentiallyOverlapping()
-              ? getStorageType(Field->getType()->getAsCXXRecordDecl())
-              : getStorageType(*Field),
-          *Field));
+          getStorageType(*Field), *Field));
       ++Field;
     } else {
       ++Field;

diff  --git a/clang/test/CodeGenCXX/no-unique-address-3.cpp b/clang/test/CodeGenCXX/no-unique-address-3.cpp
deleted file mode 100644
index f21e9d1d2b01..000000000000
--- a/clang/test/CodeGenCXX/no-unique-address-3.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm -fdump-record-layouts -std=c++17 %s -o %t | FileCheck %s
-
-// CHECK:       *** Dumping AST Record Layout
-// CHECK-NEXT:           0 | class Empty (empty)
-// CHECK-NEXT:             | [sizeof=1, dsize=1, align=1,
-// CHECK-NEXT:             |  nvsize=1, nvalign=1]
-// CHECK:       *** Dumping AST Record Layout
-// CHECK-NEXT:           0 | class Second
-// CHECK-NEXT:           0 |   class Empty (base) (empty)
-// CHECK-NEXT:       0:0-0 |   short A
-// CHECK-NEXT:             | [sizeof=2, dsize=1, align=2,
-// CHECK-NEXT:             |  nvsize=1, nvalign=2]
-// CHECK:       *** Dumping AST Record Layout
-// CHECK-NEXT:           0 | class Foo
-// CHECK-NEXT:           0 |   class Empty (base) (empty)
-// CHECK-NEXT:           2 |   class Second NZNoUnique
-// CHECK-NEXT:           2 |     class Empty (base) (empty)
-// CHECK-NEXT:       2:0-0 |     short A
-// CHECK-NEXT:           3 |   char B
-// CHECK-NEXT:             | [sizeof=4, dsize=4, align=2,
-// CHECK-NEXT:             |  nvsize=4, nvalign=2]
-
-class Empty {};
-
-// CHECK-LABEL: LLVMType:%class.Second = type { i8, i8 }
-// CHECK-NEXT:  NonVirtualBaseLLVMType:%class.Second.base = type { i8 }
-class Second : Empty {
-  short A : 1;
-};
-
-// CHECK-LABEL:   LLVMType:%class.Foo = type { [2 x i8], %class.Second.base, i8 }
-// CHECK-NEXT:    NonVirtualBaseLLVMType:%class.Foo = type { [2 x i8], %class.Second.base, i8 }
-class Foo : Empty {
-  [[no_unique_address]] Second NZNoUnique;
-  char B;
-};
-Foo I;
-
-// CHECK:       *** Dumping AST Record Layout
-// CHECK-NEXT:           0 | class SecondEmpty (empty)
-// CHECK-NEXT:           0 |   class Empty (base) (empty)
-// CHECK-NEXT:             | [sizeof=1, dsize=0, align=1,
-// CHECK-NEXT:             |  nvsize=1, nvalign=1]
-class SecondEmpty: Empty {
-};
-
-// CHECK:       *** Dumping AST Record Layout
-// CHECK-NEXT:           0 | class Bar
-// CHECK-NEXT:           0 |   class Empty (base) (empty)
-// CHECK-NEXT:           1 |   class SecondEmpty ZNoUnique (empty)
-// CHECK-NEXT:           1 |     class Empty (base) (empty)
-// CHECK-NEXT:           0 |   char C
-// CHECK-NEXT:             | [sizeof=2, dsize=1, align=1,
-// CHECK-NEXT:             |  nvsize=2, nvalign=1]
-
-// CHECK-LABEL:  LLVMType:%class.Bar = type { i8, i8 }
-// CHECK-NEXT:   NonVirtualBaseLLVMType:%class.Bar = type { i8, i8 }
-class Bar : Empty {
-  [[no_unique_address]] SecondEmpty ZNoUnique;
-  char C;
-};
-Bar J;
-
-// CHECK:       *** Dumping AST Record Layout
-// CHECK-NEXT:           0 | class IntFieldClass
-// CHECK-NEXT:           0 |   class Empty (base) (empty)
-// CHECK-NEXT:           2 |   class Second Field
-// CHECK-NEXT:           2 |     class Empty (base) (empty)
-// CHECK-NEXT:       2:0-0 |     short A
-// CHECK-NEXT:           4 |   int C
-// CHECK-NEXT:             | [sizeof=8, dsize=8, align=4,
-// CHECK-NEXT:             |  nvsize=8, nvalign=4]
-
-// CHECK-LABEL:   LLVMType:%class.IntFieldClass = type { [2 x i8], %class.Second.base, i32 }
-// CHECK-NEXT:    NonVirtualBaseLLVMType:%class.IntFieldClass = type { [2 x i8], %class.Second.base, i32 }
-class IntFieldClass : Empty {
-  [[no_unique_address]] Second Field;
-  int C;
-};
-IntFieldClass K;


        


More information about the cfe-commits mailing list