[llvm] 79e9317 - [DebugInfo] When merging locations prefer unannotated empty locs (#157707)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 10 05:30:25 PDT 2025
Author: Stephen Tozer
Date: 2025-09-10T13:30:21+01:00
New Revision: 79e93178934eb93acf252de093c263f4db9eb8b7
URL: https://github.com/llvm/llvm-project/commit/79e93178934eb93acf252de093c263f4db9eb8b7
DIFF: https://github.com/llvm/llvm-project/commit/79e93178934eb93acf252de093c263f4db9eb8b7.diff
LOG: [DebugInfo] When merging locations prefer unannotated empty locs (#157707)
When merging DILocations, we prefer to use DebugLoc::getMergedLocation
when possible to better preserve DebugLoc coverage tracking information
through transformations (as conversion to DILocations drops all coverage
tracking data). Currently, DebugLoc::getMergedLocation checks to see if
either DebugLoc is empty and returns it directly if so, to propagate
that DebugLoc's coverage tracking data to the merged location; however,
it only checks whether either location is valid, not whether they are
annotated.
This is significant because an annotated location is not a bug, while an
empty unannotated location may be one; therefore, we check to see if
either location is unannotated, and prefer to return that location if it
exists rather than an annotated one.
This change is NFC outside of DebugLoc coverage tracking builds.
Added:
Modified:
llvm/lib/IR/DebugLoc.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp
index 79c5b896f8f25..01dafcab94ce9 100644
--- a/llvm/lib/IR/DebugLoc.cpp
+++ b/llvm/lib/IR/DebugLoc.cpp
@@ -181,10 +181,19 @@ DebugLoc DebugLoc::getMergedLocations(ArrayRef<DebugLoc> Locs) {
return Merged;
}
DebugLoc DebugLoc::getMergedLocation(DebugLoc LocA, DebugLoc LocB) {
- if (!LocA)
- return LocA;
- if (!LocB)
+ if (!LocA || !LocB) {
+ // If coverage tracking is enabled, prioritize returning empty non-annotated
+ // locations to empty annotated locations.
+#if LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
+ if (!LocA && LocA.getKind() == DebugLocKind::Normal)
+ return LocA;
+ if (!LocB && LocB.getKind() == DebugLocKind::Normal)
+ return LocB;
+#endif // LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
+ if (!LocA)
+ return LocA;
return LocB;
+ }
return DILocation::getMergedLocation(LocA, LocB);
}
More information about the llvm-commits
mailing list