Permalink
Browse files

Fix ObjC @encode for C++ classes w/virtual bases.

PR17142.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190912 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information...
1 parent 71687a0 commit 1a973447d0524b6dbb67605c33481687b24cd862 @eefriedman eefriedman committed Sep 18, 2013
Showing with 12 additions and 1 deletion.
  1. +2 −1 lib/AST/ASTContext.cpp
  2. +10 −0 test/CodeGenObjCXX/encode.mm
View
3 lib/AST/ASTContext.cpp
@@ -5552,7 +5552,8 @@ void ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl,
if (base->isEmpty())
continue;
uint64_t offs = toBits(layout.getVBaseClassOffset(base));
- if (FieldOrBaseOffsets.find(offs) == FieldOrBaseOffsets.end())
+ if (offs >= uint64_t(toBits(layout.getNonVirtualSize())) &&
+ FieldOrBaseOffsets.find(offs) == FieldOrBaseOffsets.end())
FieldOrBaseOffsets.insert(FieldOrBaseOffsets.end(),
std::make_pair(offs, base));
}
View
10 test/CodeGenObjCXX/encode.mm
@@ -214,3 +214,13 @@ @implementation has_dynamic_class_ivar {
}
@end
// CHECK: internal global [41 x i8] c"{dynamic_class=\22_vptr$dynamic_class\22^^?}\00"
+
+namespace PR17142 {
+ struct A { virtual ~A(); };
+ struct B : virtual A { int y; };
+ struct C { virtual ~C(); int z; };
+ struct D : C, B { int a; };
+ struct E : D {};
+ // CHECK: @_ZN7PR171421xE = constant [14 x i8] c"{E=^^?i^^?ii}\00"
+ extern const char x[] = @encode(E);
+}

0 comments on commit 1a97344

Please sign in to comment.