summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp33
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h5
-rw-r--r--clang/lib/CodeGen/CodeGenTBAA.cpp42
-rw-r--r--clang/lib/CodeGen/CodeGenTBAA.h19
4 files changed, 32 insertions, 67 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 50d116ec7d8..88116f7d810 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3723,6 +3723,9 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
if (base.getTBAAInfo().isMayAlias() ||
rec->hasAttr<MayAliasAttr>() || FieldType->isVectorType()) {
FieldTBAAInfo = TBAAAccessInfo::getMayAliasInfo();
+ } else if (rec->isUnion()) {
+ // TODO: Support TBAA for unions.
+ FieldTBAAInfo = TBAAAccessInfo::getMayAliasInfo();
} else {
// If no base type been assigned for the base access, then try to generate
// one for this base lvalue.
@@ -3733,26 +3736,16 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
"Nonzero offset for an access with no base type!");
}
- // All union members are encoded to be of the same special type.
- if (FieldTBAAInfo.BaseType && rec->isUnion())
- FieldTBAAInfo = TBAAAccessInfo::getUnionMemberInfo(FieldTBAAInfo.BaseType,
- FieldTBAAInfo.Offset,
- FieldTBAAInfo.Size);
-
- // For now we describe accesses to direct and indirect union members as if
- // they were at the offset of their outermost enclosing union.
- if (!FieldTBAAInfo.isUnionMember()) {
- // Adjust offset to be relative to the base type.
- const ASTRecordLayout &Layout =
- getContext().getASTRecordLayout(field->getParent());
- unsigned CharWidth = getContext().getCharWidth();
- if (FieldTBAAInfo.BaseType)
- FieldTBAAInfo.Offset +=
- Layout.getFieldOffset(field->getFieldIndex()) / CharWidth;
-
- // Update the final access type.
- FieldTBAAInfo.AccessType = CGM.getTBAATypeInfo(FieldType);
- }
+ // Adjust offset to be relative to the base type.
+ const ASTRecordLayout &Layout =
+ getContext().getASTRecordLayout(field->getParent());
+ unsigned CharWidth = getContext().getCharWidth();
+ if (FieldTBAAInfo.BaseType)
+ FieldTBAAInfo.Offset +=
+ Layout.getFieldOffset(field->getFieldIndex()) / CharWidth;
+
+ // Update the final access type.
+ FieldTBAAInfo.AccessType = CGM.getTBAATypeInfo(FieldType);
}
Address addr = base.getAddress();
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index ff9866a3696..8b142933a7d 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -688,9 +688,8 @@ public:
/// getTBAAInfoForSubobject - Get TBAA information for an access with a given
/// base lvalue.
TBAAAccessInfo getTBAAInfoForSubobject(LValue Base, QualType AccessType) {
- TBAAAccessInfo TBAAInfo = Base.getTBAAInfo();
- if (TBAAInfo.isMayAlias() || TBAAInfo.isUnionMember())
- return TBAAInfo;
+ if (Base.getTBAAInfo().isMayAlias())
+ return TBAAAccessInfo::getMayAliasInfo();
return getTBAAAccessInfo(AccessType);
}
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;
diff --git a/clang/lib/CodeGen/CodeGenTBAA.h b/clang/lib/CodeGen/CodeGenTBAA.h
index 7b3473fe63f..a5b1f66bcd1 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.h
+++ b/clang/lib/CodeGen/CodeGenTBAA.h
@@ -34,10 +34,9 @@ class CGRecordLayout;
// TBAAAccessKind - A kind of TBAA memory access descriptor.
enum class TBAAAccessKind : unsigned {
- Ordinary, // An ordinary memory access.
- MayAlias, // An access that may alias with any other accesses.
- Incomplete, // Used to designate pointee values of incomplete types.
- UnionMember, // An access to a direct or indirect union member.
+ Ordinary,
+ MayAlias,
+ Incomplete,
};
// TBAAAccessInfo - Describes a memory access in terms of TBAA.
@@ -78,14 +77,6 @@ struct TBAAAccessInfo {
bool isIncomplete() const { return Kind == TBAAAccessKind::Incomplete; }
- static TBAAAccessInfo getUnionMemberInfo(llvm::MDNode *BaseType,
- uint64_t Offset, uint64_t Size) {
- return TBAAAccessInfo(TBAAAccessKind::UnionMember, BaseType,
- /* AccessType= */ nullptr, Offset, Size);
- }
-
- bool isUnionMember() const { return Kind == TBAAAccessKind::UnionMember; }
-
bool operator==(const TBAAAccessInfo &Other) const {
return Kind == Other.Kind &&
BaseType == Other.BaseType &&
@@ -157,10 +148,6 @@ class CodeGenTBAA {
/// considered to be equivalent to it.
llvm::MDNode *getChar();
- /// getUnionMemberType - Get metadata that represents the type of union
- /// members.
- llvm::MDNode *getUnionMemberType(uint64_t Size);
-
/// CollectFields - Collect information about the fields of a type for
/// !tbaa.struct metadata formation. Return false for an unsupported type.
bool CollectFields(uint64_t BaseOffset,
OpenPOWER on IntegriCloud