summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenTBAA.cpp
diff options
context:
space:
mode:
authorHal Finkel <hfinkel@anl.gov>2017-12-03 03:10:13 +0000
committerHal Finkel <hfinkel@anl.gov>2017-12-03 03:10:13 +0000
commita5986b9e91be95771a034b5efe400e99149f919c (patch)
tree6661a2270eb6f0e6bec286a186f18b382c23349e /clang/lib/CodeGen/CodeGenTBAA.cpp
parentf3470e1ed4f6322711f6fc059b834d2ce0094c2b (diff)
downloadbcm5719-llvm-a5986b9e91be95771a034b5efe400e99149f919c.tar.gz
bcm5719-llvm-a5986b9e91be95771a034b5efe400e99149f919c.zip
Revert "[CodeGen] Add initial support for union members in TBAA"
This reverts commit r319413. See PR35503. We can't use "union member" as the access type here like this. llvm-svn: 319629
Diffstat (limited to 'clang/lib/CodeGen/CodeGenTBAA.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenTBAA.cpp42
1 files changed, 14 insertions, 28 deletions
diff --git a/clang/lib/CodeGen/CodeGenTBAA.cpp b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 80ad9aecfed..2bc4b8a542b 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -74,10 +74,6 @@ llvm::MDNode *CodeGenTBAA::getChar() {
return Char;
}
-llvm::MDNode *CodeGenTBAA::getUnionMemberType(uint64_t Size) {
- return createScalarTypeNode("union member", getChar(), Size);
-}
-
static bool TypeHasMayAlias(QualType QTy) {
// Tagged types have declarations, and therefore may have attributes.
if (const TagType *TTy = dyn_cast<TagType>(QTy))
@@ -105,8 +101,9 @@ static bool isValidBaseType(QualType QTy) {
return false;
if (RD->hasFlexibleArrayMember())
return false;
- // For now, we do not allow interface classes to be base access types.
- if (RD->isStruct() || RD->isClass() || RD->isUnion())
+ // RD can be struct, union, class, interface or enum.
+ // For now, we only handle struct and class.
+ if (RD->isStruct() || RD->isClass())
return true;
}
return false;
@@ -280,27 +277,18 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
const RecordDecl *RD = TTy->getDecl()->getDefinition();
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
SmallVector<llvm::MDBuilder::TBAAStructField, 4> Fields;
- if (RD->isUnion()) {
- // Unions are represented as structures with a single member that has a
- // special type and occupies the whole object.
- uint64_t Size = Context.getTypeSizeInChars(Ty).getQuantity();
- llvm::MDNode *TypeNode = getUnionMemberType(Size);
- Fields.push_back(llvm::MDBuilder::TBAAStructField(/* Offset= */ 0, Size,
+ for (FieldDecl *Field : RD->fields()) {
+ QualType FieldQTy = Field->getType();
+ llvm::MDNode *TypeNode = isValidBaseType(FieldQTy) ?
+ getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
+ if (!TypeNode)
+ return BaseTypeMetadataCache[Ty] = nullptr;
+
+ uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
+ uint64_t Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
+ uint64_t Size = Context.getTypeSizeInChars(FieldQTy).getQuantity();
+ Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size,
TypeNode));
- } else {
- for (FieldDecl *Field : RD->fields()) {
- QualType FieldQTy = Field->getType();
- llvm::MDNode *TypeNode = isValidBaseType(FieldQTy) ?
- getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
- if (!TypeNode)
- return nullptr;
-
- uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
- uint64_t Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
- uint64_t Size = Context.getTypeSizeInChars(FieldQTy).getQuantity();
- Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size,
- TypeNode));
- }
}
SmallString<256> OutName;
@@ -345,8 +333,6 @@ llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {
if (Info.isMayAlias())
Info = TBAAAccessInfo(getChar(), Info.Size);
- else if (Info.isUnionMember())
- Info.AccessType = getUnionMemberType(Info.Size);
if (!Info.AccessType)
return nullptr;
OpenPOWER on IntegriCloud