Skip to content

Commit 12f27d8

Browse files
committed
Revert "GCC ABI Compatibility: Preserve alignment of non-pod members in packed structs"
This reverts commit 2771233. See issue: #57346
1 parent 4e4252f commit 12f27d8

File tree

3 files changed

+1
-49
lines changed

3 files changed

+1
-49
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,6 @@ OpenCL C Language Changes in Clang
574574
ABI Changes in Clang
575575
--------------------
576576

577-
- GCC doesn't pack non-POD members in packed structs unless the packed
578-
attribute is also specified on the member. Clang historically did perform
579-
such packing. Clang now matches the gcc behavior (except on Darwin and PS4).
580-
You can switch back to the old ABI behavior with the flag:
581-
``-fclang-abi-compat=14.0``.
582577
- When compiling C for ARM or AArch64, a zero-length bitfield in a ``struct``
583578
(e.g. ``int : 0``) no longer prevents the structure from being considered a
584579
homogeneous floating-point or vector aggregate. The new behavior agrees with

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,12 +1889,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
18891889
UnfilledBitsInLastUnit = 0;
18901890
LastBitfieldStorageUnitSize = 0;
18911891

1892-
llvm::Triple Target = Context.getTargetInfo().getTriple();
1893-
bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
1894-
Context.getLangOpts().getClangABICompat() <=
1895-
LangOptions::ClangABI::Ver14 ||
1896-
Target.isPS() || Target.isOSDarwin())) ||
1897-
D->hasAttr<PackedAttr>();
1892+
bool FieldPacked = Packed || D->hasAttr<PackedAttr>();
18981893

18991894
AlignRequirementKind AlignRequirement = AlignRequirementKind::None;
19001895
CharUnits FieldSize;

clang/test/SemaCXX/class-layout.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base
22
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base
3-
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=14
4-
// RUN: %clang_cc1 -triple x86_64-scei-ps4 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
5-
// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
63
// 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
7-
// 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
84
// expected-no-diagnostics
95

106
#define SA(n, p) int a##n[(p) ? 1 : -1]
@@ -608,37 +604,3 @@ namespace PR37275 {
608604
#endif
609605
#pragma pack(pop)
610606
}
611-
612-
namespace non_pod {
613-
struct t1 {
614-
protected:
615-
int a;
616-
};
617-
// GCC prints warning: ignoring packed attribute because of unpacked non-POD field 't1 t2::v1'`
618-
struct t2 {
619-
char c1;
620-
short s1;
621-
char c2;
622-
t1 v1;
623-
} __attribute__((packed));
624-
#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
625-
_Static_assert(_Alignof(t1) == 4, "");
626-
_Static_assert(_Alignof(t2) == 1, "");
627-
#else
628-
_Static_assert(_Alignof(t1) == 4, "");
629-
_Static_assert(_Alignof(t2) == 4, "");
630-
#endif
631-
_Static_assert(sizeof(t2) == 8, ""); // it's still packing the rest of the struct
632-
} // namespace non_pod
633-
634-
namespace non_pod_packed {
635-
struct t1 {
636-
protected:
637-
int a;
638-
} __attribute__((packed));
639-
struct t2 {
640-
t1 v1;
641-
} __attribute__((packed));
642-
_Static_assert(_Alignof(t1) == 1, "");
643-
_Static_assert(_Alignof(t2) == 1, "");
644-
} // namespace non_pod_packed

0 commit comments

Comments
 (0)