[clang] [Sanitize] fix crash in -fsanitize-annotate-debug-info (PR #149237)

2025-07-22 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Next time can you add more details to the summary, these are especially helpful 
for downstream folks but also for reviewers. Something along the lines of 
"Perform a null check in SanitizerAnnotateDebugInfo for the result of 
getCurrentDebugLocation".

https://github.com/llvm/llvm-project/pull/149237
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sanitize] fix crash in -fsanitize-annotate-debug-info (PR #149237)

2025-07-16 Thread Thurston Dang via cfe-commits


@@ -6480,20 +6480,23 @@ 
SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal) {
 llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
 ArrayRef Ordinals,
 SanitizerHandler Handler) {
+  llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
+  auto *DI = getDebugInfo();
+  if (!DI)
+return CheckDI;
+
   std::string Label;
   if (Ordinals.size() == 1)
 Label = SanitizerOrdinalToCheckLabel(Ordinals[0]);
   else
 Label = SanitizerHandlerToCheckLabel(Handler);
 
-  llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
-
   for (auto Ord : Ordinals) {
 // TODO: deprecate ClArrayBoundsPseudoFn
 if (((ClArrayBoundsPseudoFn && Ord == SanitizerKind::SO_ArrayBounds) ||
  CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo.has(Ord)) &&
 CheckDI) {

thurstond wrote:

Q: does the DI check above provide any guarantees that CheckDI is non-null? 
(i.e., can `&& CheckDI` be safely elided or does it require further working 
group approval?)

https://github.com/llvm/llvm-project/pull/149237
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sanitize] fix crash in -fsanitize-annotate-debug-info (PR #149237)

2025-07-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Florian Mayer (fmayer)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/149237.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+6-3) 
- (added) clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp (+5) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 75ee08a2bcfa6..f1a3ae2e057b2 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -6480,20 +6480,23 @@ 
SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal) {
 llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
 ArrayRef Ordinals,
 SanitizerHandler Handler) {
+  llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
+  auto *DI = getDebugInfo();
+  if (!DI)
+return CheckDI;
+
   std::string Label;
   if (Ordinals.size() == 1)
 Label = SanitizerOrdinalToCheckLabel(Ordinals[0]);
   else
 Label = SanitizerHandlerToCheckLabel(Handler);
 
-  llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
-
   for (auto Ord : Ordinals) {
 // TODO: deprecate ClArrayBoundsPseudoFn
 if (((ClArrayBoundsPseudoFn && Ord == SanitizerKind::SO_ArrayBounds) ||
  CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo.has(Ord)) &&
 CheckDI) {
-  return getDebugInfo()->CreateSyntheticInlineAt(CheckDI, Label);
+  return DI->CreateSyntheticInlineAt(CheckDI, Label);
 }
   }
 
diff --git a/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp 
b/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp
new file mode 100644
index 0..0b62f24177bbd
--- /dev/null
+++ b/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp
@@ -0,0 +1,5 @@
+// RUN: %clangxx -g -fsanitize=null -fsanitize-trap=all 
-fsanitize-annotate-debug-info=all -O2 -std=c++17 -c -o /dev/null %s
+
+struct foo {
+  foo(int, long, const int & = int());
+} foo(0, 0);

``




https://github.com/llvm/llvm-project/pull/149237
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sanitize] fix crash in -fsanitize-annotate-debug-info (PR #149237)

2025-07-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Florian Mayer (fmayer)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/149237.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+6-3) 
- (added) clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp (+5) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 75ee08a2bcfa6..f1a3ae2e057b2 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -6480,20 +6480,23 @@ 
SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal) {
 llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
 ArrayRef Ordinals,
 SanitizerHandler Handler) {
+  llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
+  auto *DI = getDebugInfo();
+  if (!DI)
+return CheckDI;
+
   std::string Label;
   if (Ordinals.size() == 1)
 Label = SanitizerOrdinalToCheckLabel(Ordinals[0]);
   else
 Label = SanitizerHandlerToCheckLabel(Handler);
 
-  llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
-
   for (auto Ord : Ordinals) {
 // TODO: deprecate ClArrayBoundsPseudoFn
 if (((ClArrayBoundsPseudoFn && Ord == SanitizerKind::SO_ArrayBounds) ||
  CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo.has(Ord)) &&
 CheckDI) {
-  return getDebugInfo()->CreateSyntheticInlineAt(CheckDI, Label);
+  return DI->CreateSyntheticInlineAt(CheckDI, Label);
 }
   }
 
diff --git a/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp 
b/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp
new file mode 100644
index 0..0b62f24177bbd
--- /dev/null
+++ b/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp
@@ -0,0 +1,5 @@
+// RUN: %clangxx -g -fsanitize=null -fsanitize-trap=all 
-fsanitize-annotate-debug-info=all -O2 -std=c++17 -c -o /dev/null %s
+
+struct foo {
+  foo(int, long, const int & = int());
+} foo(0, 0);

``




https://github.com/llvm/llvm-project/pull/149237
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sanitize] fix crash in -fsanitize-annotate-debug-info (PR #149237)

2025-07-16 Thread Florian Mayer via cfe-commits

https://github.com/fmayer ready_for_review 
https://github.com/llvm/llvm-project/pull/149237
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sanitize] fix crash in -fsanitize-annotate-debug-info (PR #149237)

2025-07-16 Thread Florian Mayer via cfe-commits

https://github.com/fmayer created 
https://github.com/llvm/llvm-project/pull/149237

None

>From 6324602575fc5310b5ff49bfcb985d531035811b Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Wed, 16 Jul 2025 20:00:45 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGDebugInfo.cpp| 9 ++---
 .../CodeGen/null-sanitizer-debug-info-regression.cpp | 5 +
 2 files changed, 11 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 75ee08a2bcfa6..f1a3ae2e057b2 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -6480,20 +6480,23 @@ 
SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal) {
 llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
 ArrayRef Ordinals,
 SanitizerHandler Handler) {
+  llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
+  auto *DI = getDebugInfo();
+  if (!DI)
+return CheckDI;
+
   std::string Label;
   if (Ordinals.size() == 1)
 Label = SanitizerOrdinalToCheckLabel(Ordinals[0]);
   else
 Label = SanitizerHandlerToCheckLabel(Handler);
 
-  llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
-
   for (auto Ord : Ordinals) {
 // TODO: deprecate ClArrayBoundsPseudoFn
 if (((ClArrayBoundsPseudoFn && Ord == SanitizerKind::SO_ArrayBounds) ||
  CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo.has(Ord)) &&
 CheckDI) {
-  return getDebugInfo()->CreateSyntheticInlineAt(CheckDI, Label);
+  return DI->CreateSyntheticInlineAt(CheckDI, Label);
 }
   }
 
diff --git a/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp 
b/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp
new file mode 100644
index 0..0b62f24177bbd
--- /dev/null
+++ b/clang/test/CodeGen/null-sanitizer-debug-info-regression.cpp
@@ -0,0 +1,5 @@
+// RUN: %clangxx -g -fsanitize=null -fsanitize-trap=all 
-fsanitize-annotate-debug-info=all -O2 -std=c++17 -c -o /dev/null %s
+
+struct foo {
+  foo(int, long, const int & = int());
+} foo(0, 0);

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits