Skip to content

Commit 0f09f2c

Browse files
authored
[Sanitize] fix crash in -fsanitize-annotate-debug-info (#149237)
1 parent 1c541aa commit 0f09f2c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6480,24 +6480,27 @@ SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal) {
64806480
llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
64816481
ArrayRef<SanitizerKind::SanitizerOrdinal> Ordinals,
64826482
SanitizerHandler Handler) {
6483+
llvm::DILocation *CheckDebugLoc = Builder.getCurrentDebugLocation();
6484+
auto *DI = getDebugInfo();
6485+
if (!DI)
6486+
return CheckDebugLoc;
6487+
64836488
std::string Label;
64846489
if (Ordinals.size() == 1)
64856490
Label = SanitizerOrdinalToCheckLabel(Ordinals[0]);
64866491
else
64876492
Label = SanitizerHandlerToCheckLabel(Handler);
64886493

6489-
llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
6490-
64916494
for (auto Ord : Ordinals) {
64926495
// TODO: deprecate ClArrayBoundsPseudoFn
64936496
if (((ClArrayBoundsPseudoFn && Ord == SanitizerKind::SO_ArrayBounds) ||
64946497
CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo.has(Ord)) &&
6495-
CheckDI) {
6496-
return getDebugInfo()->CreateSyntheticInlineAt(CheckDI, Label);
6498+
CheckDebugLoc) {
6499+
return DI->CreateSyntheticInlineAt(CheckDebugLoc, Label);
64976500
}
64986501
}
64996502

6500-
return CheckDI;
6503+
return CheckDebugLoc;
65016504
}
65026505

65036506
SanitizerDebugLocation::SanitizerDebugLocation(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clangxx -g -fsanitize=null -fsanitize-trap=all -fsanitize-annotate-debug-info=all -O2 -std=c++17 -c -o /dev/null %s
2+
3+
struct foo {
4+
foo(int, long, const int & = int());
5+
} foo(0, 0);

0 commit comments

Comments
 (0)