diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -1891,6 +1891,7 @@ llvm::Triple Target = Context.getTargetInfo().getTriple(); bool FieldPacked = (Packed && (!FieldClass || FieldClass->isPOD() || + FieldClass->hasAttr() || Context.getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver14 || Target.isPS() || Target.isOSDarwin())) || diff --git a/clang/test/SemaCXX/class-layout.cpp b/clang/test/SemaCXX/class-layout.cpp --- a/clang/test/SemaCXX/class-layout.cpp +++ b/clang/test/SemaCXX/class-layout.cpp @@ -642,3 +642,17 @@ _Static_assert(_Alignof(t1) == 1, ""); _Static_assert(_Alignof(t2) == 1, ""); } // namespace non_pod_packed + +namespace non_pod_packed_packed { +struct B { + int b; +}; +struct FromB : B { +} __attribute__((packed)); +struct C { + char a[3]; + FromB b; +} __attribute__((packed)); +_Static_assert(__builtin_offsetof(C, b) == 3, ""); +} +