IR: Specialize MDScope::getFile() for MDFile
Fix `MDScope::getFile()` so that it correctly returns a valid `MDFile`
even when it's an instance of `MDFile`. This logic is necessary because
of r230057. I'm working on moving the new hierarchy into place
out-of-tree (on track to commit Monday morning, BTW), and this was
exposed by a few failing tests.
llvm-svn: 230871
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index 6f2372d..4de6ecc 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -1041,6 +1041,12 @@
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
+TEST_F(MDFileTest, ScopeGetFile) {
+ // Ensure that MDScope::getFile() returns itself.
+ MDScope *N = MDFile::get(Context, "file", "dir");
+ EXPECT_EQ(N, N->getFile());
+}
+
typedef MetadataTest MDCompileUnitTest;
TEST_F(MDCompileUnitTest, get) {