summaryrefslogtreecommitdiff
path: root/unittests/IR/IRBuilderTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/IR/IRBuilderTest.cpp')
-rw-r--r--unittests/IR/IRBuilderTest.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp
index bb74756d81a9..720967cb136d 100644
--- a/unittests/IR/IRBuilderTest.cpp
+++ b/unittests/IR/IRBuilderTest.cpp
@@ -48,6 +48,27 @@ protected:
GlobalVariable *GV;
};
+TEST_F(IRBuilderTest, Intrinsics) {
+ IRBuilder<> Builder(BB);
+ Value *V;
+ CallInst *Call;
+ IntrinsicInst *II;
+
+ V = Builder.CreateLoad(GV);
+
+ Call = Builder.CreateMinNum(V, V);
+ II = cast<IntrinsicInst>(Call);
+ EXPECT_EQ(II->getIntrinsicID(), Intrinsic::minnum);
+
+ Call = Builder.CreateMaxNum(V, V);
+ II = cast<IntrinsicInst>(Call);
+ EXPECT_EQ(II->getIntrinsicID(), Intrinsic::maxnum);
+
+ Call = Builder.CreateIntrinsic(Intrinsic::readcyclecounter);
+ II = cast<IntrinsicInst>(Call);
+ EXPECT_EQ(II->getIntrinsicID(), Intrinsic::readcyclecounter);
+}
+
TEST_F(IRBuilderTest, Lifetime) {
IRBuilder<> Builder(BB);
AllocaInst *Var1 = Builder.CreateAlloca(Builder.getInt8Ty());
@@ -438,6 +459,62 @@ TEST_F(IRBuilderTest, DIBuilder) {
EXPECT_TRUE(verifyModule(*M));
}
+TEST_F(IRBuilderTest, createArtificialSubprogram) {
+ IRBuilder<> Builder(BB);
+ DIBuilder DIB(*M);
+ auto File = DIB.createFile("main.c", "/");
+ auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "clang",
+ /*isOptimized=*/true, /*Flags=*/"",
+ /*Runtime Version=*/0);
+ auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None));
+ auto SP = DIB.createFunction(CU, "foo", /*LinkageName=*/"", File,
+ /*LineNo=*/1, Type, /*isLocalToUnit=*/false,
+ /*isDefinition=*/true, /*ScopeLine=*/2,
+ DINode::FlagZero, /*isOptimized=*/true);
+ EXPECT_TRUE(SP->isDistinct());
+
+ F->setSubprogram(SP);
+ AllocaInst *I = Builder.CreateAlloca(Builder.getInt8Ty());
+ ReturnInst *R = Builder.CreateRetVoid();
+ I->setDebugLoc(DebugLoc::get(3, 2, SP));
+ R->setDebugLoc(DebugLoc::get(4, 2, SP));
+ DIB.finalize();
+ EXPECT_FALSE(verifyModule(*M));
+
+ Function *G = Function::Create(F->getFunctionType(),
+ Function::ExternalLinkage, "", M.get());
+ BasicBlock *GBB = BasicBlock::Create(Ctx, "", G);
+ Builder.SetInsertPoint(GBB);
+ I->removeFromParent();
+ Builder.Insert(I);
+ Builder.CreateRetVoid();
+ EXPECT_FALSE(verifyModule(*M));
+
+ DISubprogram *GSP = DIBuilder::createArtificialSubprogram(F->getSubprogram());
+ EXPECT_EQ(SP->getFile(), GSP->getFile());
+ EXPECT_EQ(SP->getType(), GSP->getType());
+ EXPECT_EQ(SP->getLine(), GSP->getLine());
+ EXPECT_EQ(SP->getScopeLine(), GSP->getScopeLine());
+ EXPECT_TRUE(GSP->isDistinct());
+
+ G->setSubprogram(GSP);
+ EXPECT_TRUE(verifyModule(*M));
+
+ auto *InlinedAtNode =
+ DILocation::getDistinct(Ctx, GSP->getScopeLine(), 0, GSP);
+ DebugLoc DL = I->getDebugLoc();
+ DenseMap<const MDNode *, MDNode *> IANodes;
+ auto IA = DebugLoc::appendInlinedAt(DL, InlinedAtNode, Ctx, IANodes);
+ auto NewDL = DebugLoc::get(DL.getLine(), DL.getCol(), DL.getScope(), IA);
+ I->setDebugLoc(NewDL);
+ EXPECT_FALSE(verifyModule(*M));
+
+ EXPECT_EQ("foo", SP->getName());
+ EXPECT_EQ("foo", GSP->getName());
+ EXPECT_FALSE(SP->isArtificial());
+ EXPECT_TRUE(GSP->isArtificial());
+}
+
TEST_F(IRBuilderTest, InsertExtractElement) {
IRBuilder<> Builder(BB);