Skip to content

[clang][PCH] Don't try to create standalone debug-info for types marked nodebug #123253

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

Michael137
Copy link
Member

Fixes one of the crashes uncovered by
#118710

getOrCreateStandaloneType asserts that a DIType was created for the requested type. If the Decl was marked nodebug, however, we can't generate debug-info for it, so we would previously trigger the assert. For now keep the assertion around and check the nodebug at the callsite.

…ed nodebug

Fixes one of the crashes uncovered by
llvm#118710

`getOrCreateStandaloneType` asserts that a `DIType` was created for the
requested type. If the `Decl` was marked `nodebug`, however, we can't
generate debug-info for it, so we would previously trigger the assert.
For now keep the assertion around and check the `nodebug` at the
callsite.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules clang:codegen IR generation bugs: mangling, exceptions, etc. labels Jan 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2025

@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Michael Buch (Michael137)

Changes

Fixes one of the crashes uncovered by
#118710

getOrCreateStandaloneType asserts that a DIType was created for the requested type. If the Decl was marked nodebug, however, we can't generate debug-info for it, so we would previously trigger the assert. For now keep the assertion around and check the nodebug at the callsite.


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

2 Files Affected:

  • (modified) clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp (+3)
  • (added) clang/test/Modules/gmodules-nodebug.cpp (+12)
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
index 5447b98d7105e0..02635ce235a12b 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
@@ -81,6 +81,9 @@ class PCHContainerGenerator : public ASTConsumer {
         if (!TD->isCompleteDefinition())
           return true;
 
+      if (D->hasAttr<NoDebugAttr>())
+        return true;
+
       QualType QualTy = Ctx.getTypeDeclType(D);
       if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))
         DI.getOrCreateStandaloneType(QualTy, D->getLocation());
diff --git a/clang/test/Modules/gmodules-nodebug.cpp b/clang/test/Modules/gmodules-nodebug.cpp
new file mode 100644
index 00000000000000..ac987c074f18c9
--- /dev/null
+++ b/clang/test/Modules/gmodules-nodebug.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++23 -x c++-header -emit-pch -fmodule-format=obj \
+// RUN:   -o %t.pch %s \
+// RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
+// RUN: cat %t-pch.ll | FileCheck %s
+
+template<class...>                     
+using __void_t [[gnu::nodebug]] = void;
+                                       
+__void_t<> func() {}                   
+
+// CHECK: !DICompileUnit
+// CHECK-NOT: __void_t

@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2025

@llvm/pr-subscribers-clang-codegen

Author: Michael Buch (Michael137)

Changes

Fixes one of the crashes uncovered by
#118710

getOrCreateStandaloneType asserts that a DIType was created for the requested type. If the Decl was marked nodebug, however, we can't generate debug-info for it, so we would previously trigger the assert. For now keep the assertion around and check the nodebug at the callsite.


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

2 Files Affected:

  • (modified) clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp (+3)
  • (added) clang/test/Modules/gmodules-nodebug.cpp (+12)
diff --git a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
index 5447b98d7105e0..02635ce235a12b 100644
--- a/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
+++ b/clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp
@@ -81,6 +81,9 @@ class PCHContainerGenerator : public ASTConsumer {
         if (!TD->isCompleteDefinition())
           return true;
 
+      if (D->hasAttr<NoDebugAttr>())
+        return true;
+
       QualType QualTy = Ctx.getTypeDeclType(D);
       if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))
         DI.getOrCreateStandaloneType(QualTy, D->getLocation());
diff --git a/clang/test/Modules/gmodules-nodebug.cpp b/clang/test/Modules/gmodules-nodebug.cpp
new file mode 100644
index 00000000000000..ac987c074f18c9
--- /dev/null
+++ b/clang/test/Modules/gmodules-nodebug.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++23 -x c++-header -emit-pch -fmodule-format=obj \
+// RUN:   -o %t.pch %s \
+// RUN:   -mllvm -debug-only=pchcontainer &>%t-pch.ll
+// RUN: cat %t-pch.ll | FileCheck %s
+
+template<class...>                     
+using __void_t [[gnu::nodebug]] = void;
+                                       
+__void_t<> func() {}                   
+
+// CHECK: !DICompileUnit
+// CHECK-NOT: __void_t

// RUN: -mllvm -debug-only=pchcontainer &>%t-pch.ll
// RUN: cat %t-pch.ll | FileCheck %s

template<class...>
Copy link
Member Author

Choose a reason for hiding this comment

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

I just used exactly the template alias that was crashing in the libc++ case. I suppose it doesn't actually have to be a template

Copy link
Collaborator

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

That looks very correct :-)

// RUN: -o %t.pch %s \
// RUN: -mllvm -debug-only=pchcontainer &>%t-pch.ll
// RUN: cat %t-pch.ll | FileCheck %s

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't forget the REQUIRE: assertions! (because of -debug-only)

@Michael137 Michael137 merged commit 30e276d into llvm:main Jan 17, 2025
8 checks passed
@Michael137 Michael137 deleted the clang/modules-crash-fix-nodebug branch January 17, 2025 09:35
Michael137 added a commit to swiftlang/llvm-project that referenced this pull request Mar 14, 2025
…ed nodebug (llvm#123253)

Fixes one of the crashes uncovered by
llvm#118710

`getOrCreateStandaloneType` asserts that a `DIType` was created for the
requested type. If the `Decl` was marked `nodebug`, however, we can't
generate debug-info for it, so we would previously trigger the assert.
For now keep the assertion around and check the `nodebug` at the
callsite.

(cherry picked from commit 30e276d)
Michael137 added a commit to swiftlang/llvm-project that referenced this pull request Mar 14, 2025
…ed nodebug (llvm#123253)

Fixes one of the crashes uncovered by
llvm#118710

`getOrCreateStandaloneType` asserts that a `DIType` was created for the
requested type. If the `Decl` was marked `nodebug`, however, we can't
generate debug-info for it, so we would previously trigger the assert.
For now keep the assertion around and check the `nodebug` at the
callsite.

(cherry picked from commit 30e276d)
Michael137 added a commit to swiftlang/llvm-project that referenced this pull request Mar 17, 2025
🍒[clang][PCH] Don't try to create standalone debug-info for types marked nodebug (llvm#123253)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants