summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2015-04-26 04:43:26 +0000
committerJohn McCall <rjmccall@apple.com>2015-04-26 04:43:26 +0000
commit9fc700e76d74e1bc57e709ca7b096c7dc7025950 (patch)
treee6427a0bbb36d95f06c24283643502f48df06a82 /clang/lib/CodeGen
parentf26c748b1b0ac9544a09c8cd5f4423cc604fa7b4 (diff)
downloadbcm5719-llvm-9fc700e76d74e1bc57e709ca7b096c7dc7025950.tar.gz
bcm5719-llvm-9fc700e76d74e1bc57e709ca7b096c7dc7025950.zip
Correctly handle zero-sized but non-empty base classes in IRGen.
Fixes rdar://20621065. A more elegant fix would preclude this case by defining the rules such that zero-size classes are always formally empty. I believe the only extensions which create zero-size classes right now are flexible arrays and zero-length arrays; it's not abstractly unreasonable to say that those don't count as members for the purposes of emptiness, just as zero-width bitfields don't count. But that's an ABI-affecting change and requires further discussion; in the meantime, let's not assert / miscompile. llvm-svn: 235815
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGRecordLayoutBuilder.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 202ea972f8d..c33d2d9f86d 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -438,8 +438,12 @@ void CGRecordLowering::accumulateBases() {
for (const auto &Base : RD->bases()) {
if (Base.isVirtual())
continue;
+
+ // Bases can be zero-sized even if not technically empty if they
+ // contain only a trailing array member.
const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
- if (!BaseDecl->isEmpty())
+ if (!BaseDecl->isEmpty() &&
+ !Context.getASTRecordLayout(BaseDecl).getSize().isZero())
Members.push_back(MemberInfo(Layout.getBaseClassOffset(BaseDecl),
MemberInfo::Base, getStorageType(BaseDecl), BaseDecl));
}
OpenPOWER on IntegriCloud