Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Sanitize] fix crash in -fsanitize-annotate-debug-info#149237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

fmayer
Copy link
Contributor

No description provided.

Created using spr 1.3.4
@fmayerfmayer requested a review fromthurstondJuly 17, 2025 03:01
@fmayerfmayer marked this pull request as ready for reviewJuly 17, 2025 03:01
@llvmbotllvmbot added clangClang issues not falling into any other category clang:codegenIR generation bugs: mangling, exceptions, etc. debuginfo labelsJul 17, 2025
@llvmbot
Copy link
Member

llvmbot commentedJul 17, 2025
edited
Loading

@llvm/pr-subscribers-debuginfo

@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 --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cppindex 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<SanitizerKind::SanitizerOrdinal> 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.cppnew file mode 100644index 0000000000000..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);

@llvmbot
Copy link
Member

@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 --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cppindex 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<SanitizerKind::SanitizerOrdinal> 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.cppnew file mode 100644index 0000000000000..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);

@@ -6480,20 +6480,23 @@ SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal) {
llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
ArrayRef<SanitizerKind::SanitizerOrdinal> Ordinals,
SanitizerHandler Handler) {
llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nit: variable naming - "CheckDI" is a DILocation, not DebugInfo like the similarly named "DI".

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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?)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No, we need to check both.

Created using spr 1.3.4
@fmayerfmayer requested a review fromthurstondJuly 17, 2025 03:16
@fmayerfmayer merged commit0f09f2c intomainJul 17, 2025
9 checks passed
@fmayerfmayer deleted the users/fmayer/spr/sanitize-fix-crash-in-fsanitize-annotate-debug-info branchJuly 17, 2025 04:28
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@thurstondthurstondthurstond approved these changes

Assignees
No one assigned
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.clangClang issues not falling into any other categorydebuginfo
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@fmayer@llvmbot@thurstond

[8]ページ先頭

©2009-2025 Movatter.jp