Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 829f200

Browse files
committed
Fix regression with @encode string. rdar://9624314.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133312 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4020cae commit 829f200

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/AST/ASTContext.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -4511,6 +4511,8 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
45114511
BE = CXXRec->bases_end(); BI != BE; ++BI) {
45124512
if (!BI->isVirtual()) {
45134513
CXXRecordDecl *base = BI->getType()->getAsCXXRecordDecl();
4514+
if (base->isEmpty())
4515+
continue;
45144516
uint64_t offs = layout.getBaseClassOffsetInBits(base);
45154517
FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs),
45164518
std::make_pair(offs, base));
@@ -4532,6 +4534,8 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
45324534
BI = CXXRec->vbases_begin(),
45334535
BE = CXXRec->vbases_end(); BI != BE; ++BI) {
45344536
CXXRecordDecl *base = BI->getType()->getAsCXXRecordDecl();
4537+
if (base->isEmpty())
4538+
continue;
45354539
uint64_t offs = layout.getVBaseClassOffsetInBits(base);
45364540
FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs),
45374541
std::make_pair(offs, base));
@@ -4595,8 +4599,8 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
45954599
// expands virtual bases each time one is encountered in the hierarchy,
45964600
// making the encoding type bigger than it really is.
45974601
getObjCEncodingForStructureImpl(base, S, FD, /*includeVBases*/false);
4598-
if (!base->isEmpty())
4599-
CurOffs += toBits(getASTRecordLayout(base).getNonVirtualSize());
4602+
assert(!base->isEmpty());
4603+
CurOffs += toBits(getASTRecordLayout(base).getNonVirtualSize());
46004604
} else {
46014605
FieldDecl *field = cast<FieldDecl>(dcl);
46024606
if (FD) {

test/CodeGenObjCXX/encode.mm

+14
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ @implementation RedBalloonHGXFormWrapper
9191
const char gg[] = @encode(vector4f);
9292
}
9393

94+
// rdar://9624314
95+
namespace rdar9624314 {
96+
struct B2 { int x; };
97+
struct B3 {};
98+
struct S : B2, B3 {};
99+
100+
// CHECK: @_ZN11rdar9624314L2ggE = internal constant [6 x i8] c"{S=i}\00"
101+
const char gg[] = @encode(S);
102+
103+
struct S2 { unsigned : 0; int x; unsigned : 0; };
104+
// CHECK: @_ZN11rdar9624314L2g2E = internal constant [11 x i8] c"{S2=b0ib0}\00"
105+
const char g2[] = @encode(S2);
106+
}
107+
94108
struct Base1 {
95109
char x;
96110
};

0 commit comments

Comments
 (0)