kosarev created this revision.
kosarev added a project: clang.
Repository:
rL LLVM
https://reviews.llvm.org/D39953
Files:
lib/CodeGen/CodeGenTBAA.cpp
Index: lib/CodeGen/CodeGenTBAA.cpp
===================================================================
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -127,7 +127,8 @@
return getBaseTypeInfo(QTy);
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
- if (llvm::MDNode *N = MetadataCache[Ty])
+ llvm::MDNode *&N = MetadataCache[Ty];
+ if (N)
return N;
// Handle builtin types.
@@ -160,23 +161,21 @@
// treating wchar_t, char16_t, and char32_t as distinct from their
// "underlying types".
default:
- return MetadataCache[Ty] =
- createTBAAScalarType(BTy->getName(Features), getChar());
+ return N = createTBAAScalarType(BTy->getName(Features), getChar());
}
}
// C++1z [basic.lval]p10: "If a program attempts to access the stored value of
// an object through a glvalue of other than one of the following types the
// behavior is undefined: [...] a char, unsigned char, or std::byte type."
if (Ty->isStdByteType())
- return MetadataCache[Ty] = getChar();
+ return N = getChar();
// Handle pointers and references.
// TODO: Implement C++'s type "similarity" and consider dis-"similar"
// pointers distinct.
if (Ty->isPointerType() || Ty->isReferenceType())
- return MetadataCache[Ty] = createTBAAScalarType("any pointer",
- getChar());
+ return N = createTBAAScalarType("any pointer", getChar());
// Enum types are distinct types. In C++ they have "underlying types",
// however they aren't related for TBAA.
@@ -186,16 +185,16 @@
// TODO: Is there a way to get a program-wide unique name for a
// decl with local linkage or no linkage?
if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
- return MetadataCache[Ty] = getChar();
+ return N = getChar();
SmallString<256> OutName;
llvm::raw_svector_ostream Out(OutName);
MContext.mangleTypeName(QualType(ETy, 0), Out);
- return MetadataCache[Ty] = createTBAAScalarType(OutName, getChar());
+ return N = createTBAAScalarType(OutName, getChar());
}
// For now, handle any other kind of type conservatively.
- return MetadataCache[Ty] = getChar();
+ return N = getChar();
}
TBAAAccessInfo CodeGenTBAA::getVTablePtrAccessInfo() {
@@ -244,27 +243,27 @@
return true;
}
-llvm::MDNode *
-CodeGenTBAA::getTBAAStructInfo(QualType QTy) {
+llvm::MDNode *CodeGenTBAA::getTBAAStructInfo(QualType QTy) {
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
-
- if (llvm::MDNode *N = StructMetadataCache[Ty])
+ llvm::MDNode *&N = StructMetadataCache[Ty];
+ if (N)
return N;
SmallVector<llvm::MDBuilder::TBAAStructField, 4> Fields;
if (CollectFields(0, QTy, Fields, TypeHasMayAlias(QTy)))
return MDHelper.createTBAAStructNode(Fields);
// For now, handle any other kind of type conservatively.
- return StructMetadataCache[Ty] = nullptr;
+ return N = nullptr;
}
llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
if (!isValidBaseType(QTy))
return nullptr;
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
- if (llvm::MDNode *N = BaseTypeMetadataCache[Ty])
+ llvm::MDNode *&N = BaseTypeMetadataCache[Ty];
+ if (N)
return N;
if (const RecordType *TTy = QTy->getAs<RecordType>()) {
@@ -279,7 +278,7 @@
llvm::MDNode *FieldNode = isValidBaseType(FieldQTy) ?
getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
if (!FieldNode)
- return BaseTypeMetadataCache[Ty] = nullptr;
+ return N = nullptr;
Fields.push_back(std::make_pair(
FieldNode, Layout.getFieldOffset(idx) / Context.getCharWidth()));
}
@@ -293,11 +292,10 @@
OutName = RD->getName();
}
// Create the struct type node with a vector of pairs (offset, type).
- return BaseTypeMetadataCache[Ty] =
- MDHelper.createTBAAStructTypeNode(OutName, Fields);
+ return N = MDHelper.createTBAAStructTypeNode(OutName, Fields);
}
- return BaseTypeMetadataCache[Ty] = nullptr;
+ return N = nullptr;
}
llvm::MDNode *CodeGenTBAA::getAccessTagInfo(TBAAAccessInfo Info) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits