Skip to content

Commit e6b9834

Browse files
committed
[DebugInfo] When merging locations prefer unannotated empty locs
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.
1 parent 3b19717 commit e6b9834

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

llvm/lib/IR/DebugLoc.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,19 @@ DebugLoc DebugLoc::getMergedLocations(ArrayRef<DebugLoc> Locs) {
181181
return Merged;
182182
}
183183
DebugLoc DebugLoc::getMergedLocation(DebugLoc LocA, DebugLoc LocB) {
184-
if (!LocA)
185-
return LocA;
186-
if (!LocB)
184+
if (!LocA || !LocB) {
185+
// If coverage tracking is enabled, prioritize returning empty non-annotated
186+
// locations to empty annotated locations.
187+
#if LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
188+
if (!LocA && LocA.getKind() == DebugLocKind::Normal)
189+
return LocA;
190+
if (!LocB && LocB.getKind() == DebugLocKind::Normal)
191+
return LocB;
192+
#endif // LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
193+
if (!LocA)
194+
return LocA;
187195
return LocB;
196+
}
188197
return DILocation::getMergedLocation(LocA, LocB);
189198
}
190199

0 commit comments

Comments
 (0)