Author: Nico Weber Date: 2020-11-13T11:39:10-05:00 New Revision: 46ca880fcae24693d381ca05c16c704675545433
URL: https://github.com/llvm/llvm-project/commit/46ca880fcae24693d381ca05c16c704675545433 DIFF: https://github.com/llvm/llvm-project/commit/46ca880fcae24693d381ca05c16c704675545433.diff LOG: clang: Don't assert on no_unique_address fields in @encode() Just skip (non-bitfield) zero-sized fields, like we do with empty bases. The class->struct conversion in the test is because -std=c++20 else deletes some default methods due to non-accessible base dtors otherwise. As a side-effect of writing the test, I discovered that D76801 did an ABI breaking change of sorts for Objective-C's @encode. But it's been in for a while, so I'm not sure if we want to row back on that or now. Fixes PR48048. Differential Revision: https://reviews.llvm.org/D90622 Added: Modified: clang/lib/AST/ASTContext.cpp clang/test/CodeGenObjCXX/encode.mm Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 68d6a2435c23..d63f299f021f 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -7677,7 +7677,9 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl, } unsigned i = 0; - for (auto *Field : RDecl->fields()) { + for (FieldDecl *Field : RDecl->fields()) { + if (!Field->isZeroLengthBitField(*this) && Field->isZeroSize(*this)) + continue; uint64_t offs = layout.getFieldOffset(i); FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), std::make_pair(offs, Field)); diff --git a/clang/test/CodeGenObjCXX/encode.mm b/clang/test/CodeGenObjCXX/encode.mm index 7bc64dafb476..61d0791a637c 100644 --- a/clang/test/CodeGenObjCXX/encode.mm +++ b/clang/test/CodeGenObjCXX/encode.mm @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -std=gnu++98 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -Wno-objc-root-class -std=gnu++98 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck --check-prefixes CHECK,CHECKCXX98 %s +// RUN: %clang_cc1 -Wno-objc-root-class -std=gnu++20 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck --check-prefixes CHECK,CHECKCXX20 %s // CHECK: v17@0:8{vector<float, float, float>=}16 // CHECK: {vector<float, float, float>=} @@ -87,7 +88,9 @@ @implementation RedBalloonHGXFormWrapper typedef vector< float, fixed<4> > vector4f; - // CHECK: @_ZN11rdar93574002ggE = constant [49 x i8] c"{vector<float, rdar9357400::fixed<4, -1> >=[4f]}\00" + // FIXME: This diff erence is due to D76801. It was probably an unintentional change. Maybe we want to undo it? + // CHECKCXX98: @_ZN11rdar93574002ggE = constant [49 x i8] c"{vector<float, rdar9357400::fixed<4, -1> >=[4f]}\00" + // CHECKCXX20: @_ZN11rdar93574002ggE = constant [48 x i8] c"{vector<float, rdar9357400::fixed<4, -1>>=[4f]}\00" extern const char gg[] = @encode(vector4f); } @@ -170,21 +173,21 @@ @implementation RedBalloonHGXFormWrapper // PR10990 -class CefBase { +struct CefBase { virtual ~CefBase() {} }; -class CefBrowser : public virtual CefBase {}; -class CefBrowserImpl : public CefBrowser {}; +struct CefBrowser : public virtual CefBase {}; +struct CefBrowserImpl : public CefBrowser {}; // CHECK: @g6 = constant [21 x i8] c"{CefBrowserImpl=^^?}\00" extern const char g6[] = @encode(CefBrowserImpl); // PR10990_2 -class CefBase2 { +struct CefBase2 { virtual ~CefBase2() {} int i; }; -class CefBrowser2 : public virtual CefBase2 {}; -class CefBrowserImpl2 : public CefBrowser2 {}; +struct CefBrowser2 : public virtual CefBase2 {}; +struct CefBrowserImpl2 : public CefBrowser2 {}; // CHECK: @g7 = constant [26 x i8] c"{CefBrowserImpl2=^^?^^?i}\00" extern const char g7[] = @encode(CefBrowserImpl2); @@ -245,3 +248,15 @@ @implementation N // CHECK: @{{.*}} = private unnamed_addr constant [13 x i8] c"{N={S<N>=@}}\00" return @encode(N); } + +#if __cplusplus >= 202002L +namespace PR48048 { + struct F {}; + struct I { + int m; + [[no_unique_address]] F n; + }; + // CHECKCXX20: @_ZN7PR480481xE = constant [6 x i8] c"{I=i}\00" + extern const char x[] = @encode(I); +} +#endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits