diff --git a/llvm/unittests/Analysis/AliasAnalysisTest.cpp b/llvm/unittests/Analysis/AliasAnalysisTest.cpp --- a/llvm/unittests/Analysis/AliasAnalysisTest.cpp +++ b/llvm/unittests/Analysis/AliasAnalysisTest.cpp @@ -364,6 +364,48 @@ EXPECT_EQ(AR, AliasResult::PartialAlias); EXPECT_EQ(-1, AR.getOffset()); } +TEST_F(AliasAnalysisTest, CallBr) { + LLVMContext C; + SMDiagnostic Err; + std::unique_ptr M = parseAssemblyString(R"( +@y = global i32 0 +@x = global i32 0 +define i32 @foo4() { +entry: + callbr void asm "", "=*m,!i"(ptr elementtype(i32) @x) + to label %a [label %b] + +a: ; preds = %entry + %z = load i32, ptr @y + ret i32 %z + +b: ; preds = %entry + %w = load i32, ptr @y + ret i32 %w +} +)", Err, C); + if (!M) + Err.print("CallBr", errs()); + + Function *F = M->getFunction("foo4"); + const auto Loc1 = MemoryLocation::get(getInstructionByName(*F, "z")); + const auto Loc2 = MemoryLocation::get(getInstructionByName(*F, "w")); + auto &AA = getAAResults(*F); + auto AR = AA.alias(Loc1, Loc2); + EXPECT_EQ(AR, AliasResult::MustAlias); + + CallBrInst *CBR; + for (BasicBlock &BB : *F) + for (Instruction &I : BB) + if (isa(I)) + CBR = cast(&I); + + const auto Loc3 = MemoryLocation::getForArgument(CBR, 0, nullptr); + AR = AA.alias(Loc1, Loc3); + EXPECT_EQ(AR, AliasResult::NoAlias); + AR = AA.alias(Loc2, Loc3); + EXPECT_EQ(AR, AliasResult::NoAlias); +} class AAPassInfraTest : public testing::Test { protected: LLVMContext C;