TBAA: make sure zero-length bitfield works for tbaa.struct and path-aware tbaa
For ms structs, zero-length bitfields following non-bitfield members are
completely ignored, we should not increase the field index.
Before the fix, we will have an assertion failure.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180038 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenTBAA.cpp b/lib/CodeGen/CodeGenTBAA.cpp
index bb1ebda..95b9714 100644
--- a/lib/CodeGen/CodeGenTBAA.cpp
+++ b/lib/CodeGen/CodeGenTBAA.cpp
@@ -204,8 +204,18 @@
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
unsigned idx = 0;
+ const FieldDecl *LastFD = 0;
+ bool IsMsStruct = RD->isMsStruct(Context);
for (RecordDecl::field_iterator i = RD->field_begin(),
e = RD->field_end(); i != e; ++i, ++idx) {
+ if (IsMsStruct) {
+ // Zero-length bitfields following non-bitfield members are ignored.
+ if (Context.ZeroBitfieldFollowsNonBitfield(*i, LastFD)) {
+ --idx;
+ continue;
+ }
+ LastFD = *i;
+ }
uint64_t Offset = BaseOffset +
Layout.getFieldOffset(idx) / Context.getCharWidth();
QualType FieldQTy = i->getType();
@@ -220,7 +230,9 @@
uint64_t Offset = BaseOffset;
uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity();
llvm::MDNode *TBAAInfo = MayAlias ? getChar() : getTBAAInfo(QTy);
- Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAAInfo));
+ llvm::MDNode *TBAATag = CodeGenOpts.StructPathTBAA ?
+ getTBAAScalarTagInfo(TBAAInfo) : TBAAInfo;
+ Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
return true;
}
@@ -265,8 +277,19 @@
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
SmallVector <std::pair<uint64_t, llvm::MDNode*>, 4> Fields;
unsigned idx = 0;
+ const FieldDecl *LastFD = 0;
+ bool IsMsStruct = RD->isMsStruct(Context);
for (RecordDecl::field_iterator i = RD->field_begin(),
e = RD->field_end(); i != e; ++i, ++idx) {
+ if (IsMsStruct) {
+ // Zero-length bitfields following non-bitfield members are ignored.
+ if (Context.ZeroBitfieldFollowsNonBitfield(*i, LastFD)) {
+ --idx;
+ continue;
+ }
+ LastFD = *i;
+ }
+
QualType FieldQTy = i->getType();
llvm::MDNode *FieldNode;
if (isTBAAPathStruct(FieldQTy))