summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/IRBuilderTest.cpp
diff options
context:
space:
mode:
authorAmjad Aboud <amjad.aboud@intel.com>2017-01-12 15:49:46 +0000
committerAmjad Aboud <amjad.aboud@intel.com>2017-01-12 15:49:46 +0000
commit9607571861698d7805ee710be23526be6e4559a0 (patch)
tree9cf3d6083f7f0e980ce0b1881f6d329a8290dd3e /llvm/unittests/IR/IRBuilderTest.cpp
parentae03595bfbe8fa825a3f19c37c06fb9033375b38 (diff)
downloadbcm5719-llvm-9607571861698d7805ee710be23526be6e4559a0.tar.gz
bcm5719-llvm-9607571861698d7805ee710be23526be6e4559a0.zip
[DebugInfo] Added DI macro creation API to DIBuilder.
Differential Revision: https://reviews.llvm.org/D16077 llvm-svn: 291769
Diffstat (limited to 'llvm/unittests/IR/IRBuilderTest.cpp')
-rw-r--r--llvm/unittests/IR/IRBuilderTest.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp
index 579384c5a5f..833d13bed83 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -435,4 +435,73 @@ TEST_F(IRBuilderTest, DIImportedEntity) {
EXPECT_TRUE(verifyModule(*M));
EXPECT_TRUE(CU->getImportedEntities().size() == 2);
}
+
+// 0: #define M0 V0 <-- command line definition
+// 0: main.c <-- main file
+// 3: #define M1 V1 <-- M1 definition in main.c
+// 5: #include "file.h" <-- inclusion of file.h from main.c
+// 1: #define M2 <-- M2 definition in file.h with no value
+// 7: #undef M1 V1 <-- M1 un-definition in main.c
+TEST_F(IRBuilderTest, DIBuilderMacro) {
+ IRBuilder<> Builder(BB);
+ DIBuilder DIB(*M);
+ auto File1 = DIB.createFile("main.c", "/");
+ auto File2 = DIB.createFile("file.h", "/");
+ auto CU = DIB.createCompileUnit(
+ dwarf::DW_LANG_C, DIB.createFile("main.c", "/"), "llvm-c", true, "", 0);
+ auto MDef0 =
+ DIB.createMacro(nullptr, 0, dwarf::DW_MACINFO_define, "M0", "V0");
+ auto TMF1 = DIB.createTempMacroFile(nullptr, 0, File1);
+ auto MDef1 = DIB.createMacro(TMF1, 3, dwarf::DW_MACINFO_define, "M1", "V1");
+ auto TMF2 = DIB.createTempMacroFile(TMF1, 5, File2);
+ auto MDef2 = DIB.createMacro(TMF2, 1, dwarf::DW_MACINFO_define, "M2");
+ auto MUndef1 = DIB.createMacro(TMF1, 7, dwarf::DW_MACINFO_undef, "M1");
+
+ EXPECT_EQ(dwarf::DW_MACINFO_define, MDef1->getMacinfoType());
+ EXPECT_EQ(3, MDef1->getLine());
+ EXPECT_EQ("M1", MDef1->getName());
+ EXPECT_EQ("V1", MDef1->getValue());
+
+ EXPECT_EQ(dwarf::DW_MACINFO_undef, MUndef1->getMacinfoType());
+ EXPECT_EQ(7, MUndef1->getLine());
+ EXPECT_EQ("M1", MUndef1->getName());
+ EXPECT_EQ("", MUndef1->getValue());
+
+ EXPECT_EQ(dwarf::DW_MACINFO_start_file, TMF2->getMacinfoType());
+ EXPECT_EQ(5, TMF2->getLine());
+ EXPECT_EQ(File2, TMF2->getFile());
+
+ DIB.finalize();
+
+ SmallVector<Metadata *, 4> Elements;
+ Elements.push_back(MDef2);
+ auto MF2 = DIMacroFile::get(Ctx, dwarf::DW_MACINFO_start_file, 5, File2,
+ DIB.getOrCreateMacroArray(Elements));
+
+ Elements.clear();
+ Elements.push_back(MDef1);
+ Elements.push_back(MF2);
+ Elements.push_back(MUndef1);
+ auto MF1 = DIMacroFile::get(Ctx, dwarf::DW_MACINFO_start_file, 0, File1,
+ DIB.getOrCreateMacroArray(Elements));
+
+ Elements.clear();
+ Elements.push_back(MDef0);
+ Elements.push_back(MF1);
+ auto MN0 = MDTuple::get(Ctx, Elements);
+ EXPECT_EQ(MN0, CU->getRawMacros());
+
+ Elements.clear();
+ Elements.push_back(MDef1);
+ Elements.push_back(MF2);
+ Elements.push_back(MUndef1);
+ auto MN1 = MDTuple::get(Ctx, Elements);
+ EXPECT_EQ(MN1, MF1->getRawElements());
+
+ Elements.clear();
+ Elements.push_back(MDef2);
+ auto MN2 = MDTuple::get(Ctx, Elements);
+ EXPECT_EQ(MN2, MF2->getRawElements());
+ EXPECT_TRUE(verifyModule(*M));
+}
}
OpenPOWER on IntegriCloud