Skip to content

Commit

Permalink
Revert "GCC ABI Compatibility: Preserve alignment of non-pod members …
Browse files Browse the repository at this point in the history
…in packed structs"

This reverts commit 2771233.

See issue: #57346
  • Loading branch information
tru committed Aug 25, 2022
1 parent 4e4252f commit 12f27d8
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 49 deletions.
5 changes: 0 additions & 5 deletions clang/docs/ReleaseNotes.rst
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions clang/lib/AST/RecordLayoutBuilder.cpp
Expand Up @@ -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;
Expand Down
38 changes: 0 additions & 38 deletions 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]
Expand Down Expand Up @@ -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

0 comments on commit 12f27d8

Please sign in to comment.