aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/DebugInfoTest.cpp
diff options
context:
space:
mode:
authorJonas Hahnfeld <jonas.hahnfeld@cern.ch>2022-12-01 14:14:43 +0100
committerJonas Hahnfeld <jonas.hahnfeld@cern.ch>2022-12-08 09:58:33 +0100
commitc9cb4fc761cd78d3a04feb211d363e91933a8e08 (patch)
treeb4b8eb077835ed56b452928875d5713281cc34c9 /llvm/unittests/IR/DebugInfoTest.cpp
parent61318fa5c764d6af60baeb1c00d793f1bd95f5ea (diff)
downloadllvm-c9cb4fc761cd78d3a04feb211d363e91933a8e08.zip
llvm-c9cb4fc761cd78d3a04feb211d363e91933a8e08.tar.gz
llvm-c9cb4fc761cd78d3a04feb211d363e91933a8e08.tar.bz2
[DebugInfo] Store optional DIFile::Source as pointer
getCanonicalMDString() also returns a nullptr for empty strings, which tripped over the getSource() method. Solve the ambiguity of no source versus an optional containing a nullptr by simply storing a pointer. Differential Revision: https://reviews.llvm.org/D138658
Diffstat (limited to 'llvm/unittests/IR/DebugInfoTest.cpp')
-rw-r--r--llvm/unittests/IR/DebugInfoTest.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp
index 439c0d0..1930ecd 100644
--- a/llvm/unittests/IR/DebugInfoTest.cpp
+++ b/llvm/unittests/IR/DebugInfoTest.cpp
@@ -190,6 +190,24 @@ TEST(MetadataTest, DeleteInstUsedByDbgValue) {
EXPECT_TRUE(isa<UndefValue>(DVIs[0]->getValue(0)));
}
+TEST(DIBuiler, CreateFile) {
+ LLVMContext Ctx;
+ std::unique_ptr<Module> M(new Module("MyModule", Ctx));
+ DIBuilder DIB(*M);
+
+ DIFile *F = DIB.createFile("main.c", "/");
+ EXPECT_EQ(std::nullopt, F->getSource());
+
+ std::optional<DIFile::ChecksumInfo<StringRef>> Checksum = std::nullopt;
+ std::optional<StringRef> Source = std::nullopt;
+ F = DIB.createFile("main.c", "/", Checksum, Source);
+ EXPECT_EQ(Source, F->getSource());
+
+ Source = "";
+ F = DIB.createFile("main.c", "/", Checksum, Source);
+ EXPECT_EQ(Source, F->getSource());
+}
+
TEST(DIBuilder, CreateFortranArrayTypeWithAttributes) {
LLVMContext Ctx;
std::unique_ptr<Module> M(new Module("MyModule", Ctx));