aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/MetadataTest.cpp
diff options
context:
space:
mode:
authorSnehasish Kumar <snehasishk@google.com>2025-05-02 09:36:52 -0700
committerGitHub <noreply@github.com>2025-05-02 09:36:52 -0700
commit5d16a18c4bd0fed88086bc1e93e6fb6f1be4caab (patch)
tree64f6d856ebb5309bcda3c9ed75e2b1b1f9ba8a43 /llvm/unittests/IR/MetadataTest.cpp
parent8313d2a8dbc5e23741d7c67c3b009fc3f6de4875 (diff)
downloadllvm-5d16a18c4bd0fed88086bc1e93e6fb6f1be4caab.zip
llvm-5d16a18c4bd0fed88086bc1e93e6fb6f1be4caab.tar.gz
llvm-5d16a18c4bd0fed88086bc1e93e6fb6f1be4caab.tar.bz2
[Metadata] Return the valid DebugLoc if one of them is null with -pick-merged-source-locations. (#138148)
Previously when getMergedLocation was passed nullptr as one of the parameters we returned nullptr. Change that behaviour to instead return a valid DebugLoc. This is beneficial for binaries from which SamplePGO profiles are obtained.
Diffstat (limited to 'llvm/unittests/IR/MetadataTest.cpp')
-rw-r--r--llvm/unittests/IR/MetadataTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index e710f78..45860d6 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -25,6 +25,10 @@
#include <optional>
using namespace llvm;
+namespace llvm {
+extern cl::opt<bool> PickMergedSourceLocations;
+} // namespace llvm
+
namespace {
TEST(ContextAndReplaceableUsesTest, FromContext) {
@@ -1444,6 +1448,25 @@ TEST_F(DILocationTest, Merge) {
auto *M2 = DILocation::getMergedLocation(A2, B);
EXPECT_EQ(M1, M2);
}
+
+ {
+ // If PickMergedSourceLocation is enabled, when one source location is null
+ // we should return the valid location.
+ PickMergedSourceLocations = true;
+ auto *A = DILocation::get(Context, 2, 7, N);
+ auto *M1 = DILocation::getMergedLocation(A, nullptr);
+ ASSERT_NE(nullptr, M1);
+ EXPECT_EQ(2u, M1->getLine());
+ EXPECT_EQ(7u, M1->getColumn());
+ EXPECT_EQ(N, M1->getScope());
+
+ auto *M2 = DILocation::getMergedLocation(nullptr, A);
+ ASSERT_NE(nullptr, M2);
+ EXPECT_EQ(2u, M2->getLine());
+ EXPECT_EQ(7u, M2->getColumn());
+ EXPECT_EQ(N, M2->getScope());
+ PickMergedSourceLocations = false;
+ }
}
TEST_F(DILocationTest, getDistinct) {