[PATCH] D51238: Add a unit test for DILocation::getMergedLocation()
Adrian Prantl via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 24 15:49:42 PDT 2018
aprantl created this revision.
aprantl added a reviewer: dblaikie.
This is a unit test for DILocation::getMergedLocation() that exposes a bug in the implementation of r340583. (You'll need to build with assertions enabled to see it.)
https://reviews.llvm.org/D51238
Files:
unittests/IR/MetadataTest.cpp
Index: unittests/IR/MetadataTest.cpp
===================================================================
--- unittests/IR/MetadataTest.cpp
+++ unittests/IR/MetadataTest.cpp
@@ -860,6 +860,72 @@
}
}
+TEST_F(DILocationTest, Merge) {
+ DISubprogram *N = getSubprogram();
+ DIScope *S = DILexicalBlock::get(Context, N, getFile(), 3, 4);
+
+ {
+ // Identical.
+ auto *A = DILocation::get(Context, 2, 7, N);
+ auto *B = DILocation::get(Context, 2, 7, N);
+ auto *M = DILocation::getMergedLocation(A, B);
+ EXPECT_EQ(2u, M->getLine());
+ EXPECT_EQ(7u, M->getColumn());
+ EXPECT_EQ(N, M->getScope());
+ }
+
+ {
+ // Identical, different scopes.
+ auto *A = DILocation::get(Context, 2, 7, N);
+ auto *B = DILocation::get(Context, 2, 7, S);
+ auto *M = DILocation::getMergedLocation(A, B);
+ EXPECT_EQ(0u, M->getLine()); // FIXME: Should this be 2?
+ EXPECT_EQ(0u, M->getColumn()); // FIXME: Should this be 7?
+ EXPECT_EQ(N, M->getScope());
+ }
+
+ {
+ // Different lines, same scopes.
+ auto *A = DILocation::get(Context, 1, 6, N);
+ auto *B = DILocation::get(Context, 2, 7, N);
+ auto *M = DILocation::getMergedLocation(A, B);
+ EXPECT_EQ(0u, M->getLine());
+ EXPECT_EQ(0u, M->getColumn());
+ EXPECT_EQ(N, M->getScope());
+ }
+
+ {
+ // Twisty locations, all different, same function.
+ auto *A = DILocation::get(Context, 1, 6, N);
+ auto *B = DILocation::get(Context, 2, 7, S);
+ auto *M = DILocation::getMergedLocation(A, B);
+ EXPECT_EQ(0u, M->getLine());
+ EXPECT_EQ(0u, M->getColumn());
+ EXPECT_EQ(N, M->getScope());
+ }
+
+ {
+ // Different function, same inlined-at.
+ auto *F = getFile();
+ auto *SP1 = DISubprogram::getDistinct(Context, F, "a", "a", F, 0, nullptr,
+ false, false, 0, nullptr, 0, 0, 0,
+ DINode::FlagZero, false, nullptr);
+ auto *SP2 = DISubprogram::getDistinct(Context, F, "b", "b", F, 0, nullptr,
+ false, false, 0, nullptr, 0, 0, 0,
+ DINode::FlagZero, false, nullptr);
+
+ auto *I = DILocation::get(Context, 2, 7, N);
+ auto *A = DILocation::get(Context, 1, 6, SP1, I);
+ auto *B = DILocation::get(Context, 2, 7, SP2, I);
+ auto *M = DILocation::getMergedLocation(A, B);
+ EXPECT_EQ(0u, M->getLine());
+ EXPECT_EQ(0u, M->getColumn());
+ // FIXME: What scope?
+ EXPECT_TRUE(isa<DILocalScope>(M->getScope()));
+ EXPECT_EQ(I, M->getInlinedAt());
+ }
+}
+
TEST_F(DILocationTest, getDistinct) {
MDNode *N = getSubprogram();
DILocation *L0 = DILocation::getDistinct(Context, 2, 7, N);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51238.162492.patch
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180824/67d46a46/attachment.bin>
More information about the llvm-commits
mailing list