From feba9f2bdc5711894e452dfc67c9679482fbf897 Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Tue, 8 Oct 2013 00:08:49 +0000 Subject: TBAA: use the same format for scalar TBAA and struct-path aware TBAA. An updated version of r191586 with bug fix. Struct-path aware TBAA generates tags to specify the access path, while scalar TBAA only generates tags to scalar types. We should not generate a TBAA tag with null being the first field. When a TBAA type node is null, the tag should be null too. Make sure we don't decorate an instruction with a null TBAA tag. Added a testing case for the bug reported by Richard with -relaxed-aliasing and -fsanitizer=thread. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192145 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenTBAA.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'lib/CodeGen/CodeGenTBAA.cpp') diff --git a/lib/CodeGen/CodeGenTBAA.cpp b/lib/CodeGen/CodeGenTBAA.cpp index f104c2f2f5..11e376ff40 100644 --- a/lib/CodeGen/CodeGenTBAA.cpp +++ b/lib/CodeGen/CodeGenTBAA.cpp @@ -50,16 +50,11 @@ llvm::MDNode *CodeGenTBAA::getRoot() { return Root; } -// For struct-path aware TBAA, the scalar type has the same format as -// the struct type: name, offset, pointer to another node in the type DAG. -// For scalar TBAA, the scalar type is the same as the scalar tag: -// name and a parent pointer. +// For both scalar TBAA and struct-path aware TBAA, the scalar type has the +// same format: name, parent node, and offset. llvm::MDNode *CodeGenTBAA::createTBAAScalarType(StringRef Name, llvm::MDNode *Parent) { - if (CodeGenOpts.StructPathTBAA) - return MDHelper.createTBAAScalarTypeNode(Name, Parent); - else - return MDHelper.createTBAANode(Name, Parent); + return MDHelper.createTBAAScalarTypeNode(Name, Parent); } llvm::MDNode *CodeGenTBAA::getChar() { @@ -91,7 +86,7 @@ static bool TypeHasMayAlias(QualType QTy) { llvm::MDNode * CodeGenTBAA::getTBAAInfo(QualType QTy) { - // At -O0 TBAA is not emitted for regular types. + // At -O0 or relaxed aliasing, TBAA is not emitted for regular types. if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing) return NULL; @@ -211,8 +206,7 @@ CodeGenTBAA::CollectFields(uint64_t BaseOffset, uint64_t Offset = BaseOffset; uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity(); llvm::MDNode *TBAAInfo = MayAlias ? getChar() : getTBAAInfo(QTy); - llvm::MDNode *TBAATag = CodeGenOpts.StructPathTBAA ? - getTBAAScalarTagInfo(TBAAInfo) : TBAAInfo; + llvm::MDNode *TBAATag = getTBAAScalarTagInfo(TBAAInfo); Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag)); return true; } @@ -293,11 +287,15 @@ CodeGenTBAA::getTBAAStructTypeInfo(QualType QTy) { return StructMetadataCache[Ty] = NULL; } +/// Return a TBAA tag node for both scalar TBAA and struct-path aware TBAA. llvm::MDNode * CodeGenTBAA::getTBAAStructTagInfo(QualType BaseQTy, llvm::MDNode *AccessNode, uint64_t Offset) { + if (!AccessNode) + return NULL; + if (!CodeGenOpts.StructPathTBAA) - return AccessNode; + return getTBAAScalarTagInfo(AccessNode); const Type *BTy = Context.getCanonicalType(BaseQTy).getTypePtr(); TBAAPathTag PathTag = TBAAPathTag(BTy, AccessNode, Offset); @@ -317,6 +315,8 @@ CodeGenTBAA::getTBAAStructTagInfo(QualType BaseQTy, llvm::MDNode *AccessNode, llvm::MDNode * CodeGenTBAA::getTBAAScalarTagInfo(llvm::MDNode *AccessNode) { + if (!AccessNode) + return NULL; if (llvm::MDNode *N = ScalarTagMetadataCache[AccessNode]) return N; -- cgit v1.2.3