[llvm-branch-commits] [clang] 12f27d8 - Revert "GCC ABI Compatibility: Preserve alignment of non-pod members in packed structs"

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 25 00:01:19 PDT 2022


Author: Tobias Hieta
Date: 2022-08-25T09:00:25+02:00
New Revision: 12f27d8bef9387e2e3837f604ccd8a457d927053

URL: https://github.com/llvm/llvm-project/commit/12f27d8bef9387e2e3837f604ccd8a457d927053
DIFF: https://github.com/llvm/llvm-project/commit/12f27d8bef9387e2e3837f604ccd8a457d927053.diff

LOG: Revert "GCC ABI Compatibility: Preserve alignment of non-pod members in packed structs"

This reverts commit 277123376ce08c98b07c154bf83e4092a5d4d3c6.

See issue: https://github.com/llvm/llvm-project/issues/57346

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/AST/RecordLayoutBuilder.cpp
    clang/test/SemaCXX/class-layout.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 906c1925bc823..87d906a302f83 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -574,11 +574,6 @@ OpenCL C Language Changes in Clang
 ABI Changes in Clang
 --------------------
 
-- GCC doesn't pack non-POD members in packed structs unless the packed
-  attribute is also specified on the member. Clang historically did perform
-  such packing. Clang now matches the gcc behavior (except on Darwin and PS4).
-  You can switch back to the old ABI behavior with the flag:
-  ``-fclang-abi-compat=14.0``.
 - When compiling C for ARM or AArch64, a zero-length bitfield in a ``struct``
   (e.g. ``int : 0``) no longer prevents the structure from being considered a
   homogeneous floating-point or vector aggregate. The new behavior agrees with

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp
index 6f3ede2ce42a7..5ddd95e2ecca6 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1889,12 +1889,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
   UnfilledBitsInLastUnit = 0;
   LastBitfieldStorageUnitSize = 0;
 
-  llvm::Triple Target = Context.getTargetInfo().getTriple();
-  bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
-                                 Context.getLangOpts().getClangABICompat() <=
-                                     LangOptions::ClangABI::Ver14 ||
-                                 Target.isPS() || Target.isOSDarwin())) ||
-                     D->hasAttr<PackedAttr>();
+  bool FieldPacked = Packed || D->hasAttr<PackedAttr>();
 
   AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
   CharUnits FieldSize;

diff  --git a/clang/test/SemaCXX/class-layout.cpp b/clang/test/SemaCXX/class-layout.cpp
index f81e526d0e2ad..5403bd6e6a6f6 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,10 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin    %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=14
-// RUN: %clang_cc1 -triple x86_64-scei-ps4        %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-sie-ps5         %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
 // expected-no-diagnostics
 
 #define SA(n, p) int a##n[(p) ? 1 : -1]
@@ -608,37 +604,3 @@ namespace PR37275 {
 #endif
 #pragma pack(pop)
 }
-
-namespace non_pod {
-struct t1 {
-protected:
-  int a;
-};
-// GCC prints warning: ignoring packed attribute because of unpacked non-POD field 't1 t2::v1'`
-struct t2 {
-  char c1;
-  short s1;
-  char c2;
-  t1 v1;
-} __attribute__((packed));
-#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
-_Static_assert(_Alignof(t1) == 4, "");
-_Static_assert(_Alignof(t2) == 1, "");
-#else
-_Static_assert(_Alignof(t1) == 4, "");
-_Static_assert(_Alignof(t2) == 4, "");
-#endif
-_Static_assert(sizeof(t2) == 8, ""); // it's still packing the rest of the struct
-} // namespace non_pod
-
-namespace non_pod_packed {
-struct t1 {
-protected:
-  int a;
-} __attribute__((packed));
-struct t2 {
-  t1 v1;
-} __attribute__((packed));
-_Static_assert(_Alignof(t1) == 1, "");
-_Static_assert(_Alignof(t2) == 1, "");
-} // namespace non_pod_packed


        


More information about the llvm-branch-commits mailing list