Skip to content

Commit 9363071

Browse files
committed
Move GCC-compatible pod-packing change to v16/old behavior available at v15 and below
Change matches D126334/e59f648d698e since this change got punted from v15 too.
1 parent 88da0de commit 9363071

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ OpenCL C Language Changes in Clang
524524
ABI Changes in Clang
525525
--------------------
526526

527+
- GCC doesn't pack non-POD members in packed structs unless the packed
528+
attribute is also specified on the member. Clang historically did perform
529+
such packing. Clang now matches the gcc behavior (except on Darwin and PS4).
530+
You can switch back to the old ABI behavior with the flag:
531+
``-fclang-abi-compat=15.0``.
532+
527533
OpenMP Support in Clang
528534
-----------------------
529535

clang/include/clang/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ class LangOptions : public LangOptionsBase {
220220
/// Attempt to be ABI-compatible with code generated by Clang 14.0.x.
221221
/// This causes clang to:
222222
/// - mangle dependent nested names incorrectly.
223-
/// - pack non-POD members of packed structs.
224223
/// - make trivial only those defaulted copy constructors with a
225224
/// parameter-type-list equivalent to the parameter-type-list of an
226225
/// implicit declaration.
@@ -229,6 +228,7 @@ class LangOptions : public LangOptionsBase {
229228
/// Attempt to be ABI-compatible with code generated by Clang 15.0.x.
230229
/// This causes clang to:
231230
/// - Reverse the implementation for DR692, DR1395 and DR1432.
231+
/// - pack non-POD members of packed structs.
232232
Ver15,
233233

234234
/// Conform to the underlying platform's C and C++ ABIs as closely

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const FieldDecl *D,
18921892
llvm::Triple Target = Context.getTargetInfo().getTriple();
18931893
bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() ||
18941894
Context.getLangOpts().getClangABICompat() <=
1895-
LangOptions::ClangABI::Ver14 ||
1895+
LangOptions::ClangABI::Ver15 ||
18961896
Target.isPS() || Target.isOSDarwin())) ||
18971897
D->hasAttr<PackedAttr>();
18981898

clang/test/SemaCXX/class-layout.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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
3+
// RUN: %clang_cc1 -triple x86_64-apple-darwin %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
44
// RUN: %clang_cc1 -triple x86_64-scei-ps4 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
55
// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
66
// 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
7+
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
88
// expected-no-diagnostics
99

1010
#define SA(n, p) int a##n[(p) ? 1 : -1]
@@ -621,7 +621,7 @@ struct t2 {
621621
char c2;
622622
t1 v1;
623623
} __attribute__((packed));
624-
#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
624+
#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 15
625625
_Static_assert(_Alignof(t1) == 4, "");
626626
_Static_assert(_Alignof(t2) == 1, "");
627627
#else

0 commit comments

Comments
 (0)