[llvm] r289403 - [TBAA] Don't generate invalid TBAA when merging nodes
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 11 12:07:26 PST 2016
Author: sanjoy
Date: Sun Dec 11 14:07:25 2016
New Revision: 289403
URL: http://llvm.org/viewvc/llvm-project?rev=289403&view=rev
Log:
[TBAA] Don't generate invalid TBAA when merging nodes
Summary:
Fix a corner case in `MDNode::getMostGenericTBAA` where we can sometimes
generate invalid TBAA metadata.
Reviewers: chandlerc, hfinkel, mehdi_amini, manmanren
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D26635
Modified:
llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp
llvm/trunk/unittests/Analysis/TBAATest.cpp
Modified: llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp?rev=289403&r1=289402&r2=289403&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/TypeBasedAliasAnalysis.cpp Sun Dec 11 14:07:25 2016
@@ -457,8 +457,12 @@ MDNode *MDNode::getMostGenericTBAA(MDNod
--IB;
}
- if (!Ret)
+ // We either did not find a match, or the only common base "type" is
+ // the root node. In either case, we don't have any useful TBAA
+ // metadata to attach.
+ if (!Ret || Ret->getNumOperands() < 2)
return nullptr;
+
// We need to convert from a type node to a tag node.
Type *Int64 = IntegerType::get(A->getContext(), 64);
Metadata *Ops[3] = {Ret, Ret,
Modified: llvm/trunk/unittests/Analysis/TBAATest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/TBAATest.cpp?rev=289403&r1=289402&r2=289403&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/TBAATest.cpp (original)
+++ llvm/trunk/unittests/Analysis/TBAATest.cpp Sun Dec 11 14:07:25 2016
@@ -22,20 +22,19 @@
namespace llvm {
namespace {
-class OldTBAATest : public testing::Test {
+class TBAATest : public testing::Test {
protected:
- OldTBAATest() : M("MixedTBAATest", C), MD(C) {}
+ TBAATest() : M("TBAATest", C), MD(C) {}
LLVMContext C;
Module M;
MDBuilder MD;
};
-TEST_F(OldTBAATest, checkVerifierBehavior) {
- // C++ unit test case to avoid going through the auto upgrade logic.
-
+static StoreInst *getFunctionWithSingleStore(Module *M, StringRef Name) {
+ auto &C = M->getContext();
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), {});
- auto *F = cast<Function>(M.getOrInsertFunction("f", FTy));
+ auto *F = cast<Function>(M->getOrInsertFunction(Name, FTy));
auto *BB = BasicBlock::Create(C, "entry", F);
auto *IntType = Type::getInt32Ty(C);
auto *PtrType = Type::getInt32PtrTy(C);
@@ -43,6 +42,14 @@ TEST_F(OldTBAATest, checkVerifierBehavio
ConstantPointerNull::get(PtrType), BB);
ReturnInst::Create(C, nullptr, BB);
+ return SI;
+}
+
+TEST_F(TBAATest, checkVerifierBehaviorForOldTBAA) {
+ auto *SI = getFunctionWithSingleStore(&M, "f1");
+ auto *F = SI->getFunction();
+
+ // C++ unit test case to avoid going through the auto upgrade logic.
auto *RootMD = MD.createTBAARoot("Simple C/C++ TBAA");
auto *MD1 = MD.createTBAANode("omnipotent char", RootMD);
auto *MD2 = MD.createTBAANode("int", MD1);
@@ -59,5 +66,26 @@ TEST_F(OldTBAATest, checkVerifierBehavio
.startswith(ExpectedFailureMsg));
}
+TEST_F(TBAATest, checkTBAAMerging) {
+ auto *SI = getFunctionWithSingleStore(&M, "f2");
+ auto *F = SI->getFunction();
+
+ auto *RootMD = MD.createTBAARoot("tbaa-root");
+ auto *MD1 = MD.createTBAANode("scalar-a", RootMD);
+ auto *StructTag1 = MD.createTBAAStructTagNode(MD1, MD1, 0);
+ auto *MD2 = MD.createTBAANode("scalar-b", RootMD);
+ auto *StructTag2 = MD.createTBAAStructTagNode(MD2, MD2, 0);
+
+ auto *GenericMD = MDNode::getMostGenericTBAA(StructTag1, StructTag2);
+
+ EXPECT_EQ(GenericMD, nullptr);
+
+ // Despite GenericMD being nullptr, we expect the setMetadata call to be well
+ // defined and produce a well-formed function.
+ SI->setMetadata(LLVMContext::MD_tbaa, GenericMD);
+
+ EXPECT_TRUE(!verifyFunction(*F));
+}
+
} // end anonymous namspace
} // end llvm namespace
More information about the llvm-commits
mailing list