[llvm] [DebugInfo] getMergedLocation: match scopes based on their location (PR #132286)
Stephen Tozer via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 17 12:24:22 PDT 2025
================
@@ -975,6 +1025,162 @@ TEST_F(DILocationTest, Merge) {
EXPECT_EQ(N, M->getScope());
}
+ {
+ // Different files, same line numbers, same subprogram.
+ auto *F1 = DIFile::getDistinct(Context, "file1.c", "/path/to/dir");
+ auto *F2 = DIFile::getDistinct(Context, "file2.c", "/path/to/dir");
+ DISubprogram *N = getSubprogram(F1);
+ auto *LBF = DILexicalBlockFile::get(Context, N, F2, 0);
+ auto *A = DILocation::get(Context, 1, 6, N);
+ auto *B = DILocation::get(Context, 1, 6, LBF);
+ auto *M = DILocation::getMergedLocation(A, B);
+ EXPECT_EQ(0u, M->getLine());
+ EXPECT_EQ(0u, M->getColumn());
+ EXPECT_EQ(N, M->getScope());
+ }
+
+ {
+ // Different files, same line numbers.
+ auto *F1 = DIFile::getDistinct(Context, "file1.c", "/path/to/dir");
+ auto *F2 = DIFile::getDistinct(Context, "file2.c", "/path/to/dir");
+ DISubprogram *N = getSubprogram(F1);
+ auto *LB = DILexicalBlock::getDistinct(Context, N, F1, 4, 9);
+ auto *LBF = DILexicalBlockFile::get(Context, LB, F2, 0);
+ auto *A = DILocation::get(Context, 1, 6, LB);
+ auto *B = DILocation::get(Context, 1, 6, LBF);
+ auto *M = DILocation::getMergedLocation(A, B);
+ EXPECT_EQ(4u, M->getLine());
+ EXPECT_EQ(9u, M->getColumn());
+ EXPECT_EQ(LB, M->getScope());
+ }
+
+ {
+ // Different files, same line numbers,
+ // both locations have DILexicalBlockFile scopes.
+ auto *F1 = DIFile::getDistinct(Context, "file1.c", "/path/to/dir");
+ auto *F2 = DIFile::getDistinct(Context, "file2.c", "/path/to/dir");
+ auto *F3 = DIFile::getDistinct(Context, "file3.c", "/path/to/dir");
+ DISubprogram *N = getSubprogram(F1);
+ auto *LB = DILexicalBlock::getDistinct(Context, N, F1, 4, 9);
+ auto *LBF1 = DILexicalBlockFile::get(Context, LB, F2, 0);
+ auto *LBF2 = DILexicalBlockFile::get(Context, LB, F3, 0);
+ auto *A = DILocation::get(Context, 1, 6, LBF1);
+ auto *B = DILocation::get(Context, 1, 6, LBF2);
+ auto *M = DILocation::getMergedLocation(A, B);
+ EXPECT_EQ(4u, M->getLine());
+ EXPECT_EQ(9u, M->getColumn());
+ EXPECT_EQ(LB, M->getScope());
+ }
+
+ {
+ // Same file, same line numbers, but different LBF objects.
+ // both locations have DILexicalBlockFile scope.
+ auto *F1 = DIFile::getDistinct(Context, "file1.c", "/path/to/dir");
+ DISubprogram *N = getSubprogram(F1);
+ auto *LB1 = DILexicalBlock::getDistinct(Context, N, F1, 4, 9);
+ auto *LB2 = DILexicalBlock::getDistinct(Context, N, F1, 5, 9);
+ auto *F2 = DIFile::getDistinct(Context, "file2.c", "/path/to/dir");
+ auto *LBF1 = DILexicalBlockFile::get(Context, LB1, F2, 0);
+ auto *LBF2 = DILexicalBlockFile::get(Context, LB2, F2, 0);
+ auto *A = DILocation::get(Context, 1, 6, LBF1);
+ auto *B = DILocation::get(Context, 1, 6, LBF2);
+ llvm::errs() << "Check\n";
+ auto *M = DILocation::getMergedLocation(A, B);
+ M->dump();
+ M->getScope()->dump();
+ LBF1->dump();
----------------
SLTozer wrote:
Looks like some debug dumps left hanging around.
https://github.com/llvm/llvm-project/pull/132286
More information about the llvm-commits
mailing list