Skip to content

Commit

Permalink
When @encode'ing a C++ class that has empty base classes, we can end
Browse files Browse the repository at this point in the history
up with gaps when the class inherits from the same empty base class
more than once. Fixes <rdar://problem/11324167>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155738 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
DougGregor committed Apr 27, 2012
1 parent 0eed2cb commit 58db7a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4787,11 +4787,8 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
std::multimap<uint64_t, NamedDecl *>::iterator
CurLayObj = FieldOrBaseOffsets.begin();

if ((CurLayObj != FieldOrBaseOffsets.end() && CurLayObj->first != 0) ||
(CurLayObj == FieldOrBaseOffsets.end() &&
CXXRec && CXXRec->isDynamicClass())) {
assert(CXXRec && CXXRec->isDynamicClass() &&
"Offset 0 was empty but no VTable ?");
if (CXXRec && CXXRec->isDynamicClass() &&
(CurLayObj == FieldOrBaseOffsets.end() || CurLayObj->first != 0)) {
if (FD) {
S += "\"_vptr$";
std::string recname = CXXRec->getNameAsString();
Expand Down
14 changes: 14 additions & 0 deletions test/CodeGenObjCXX/encode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,17 @@ @implementation RedBalloonHGXFormWrapper
class CefBrowserImpl2 : public CefBrowser2 {};
// CHECK: @_ZL2g7 = internal constant [26 x i8] c"{CefBrowserImpl2=^^?^^?i}\00"
const char g7[] = @encode(CefBrowserImpl2);

// <rdar://problem/11324167>
struct Empty {};

struct X : Empty {
int array[10];
};

struct Y : Empty {
X vec;
};

// CHECK: @_ZL2g8 = internal constant [14 x i8] c"{Y={X=[10i]}}\00"
const char g8[] = @encode(Y);

0 comments on commit 58db7a5

Please sign in to comment.