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

Michael Buch via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 16 16:11:13 PST 2025


https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/123253

>From 33b128cc2fd83894506f27ad730c3ac145c49f6f Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Thu, 16 Jan 2025 23:02:10 +0000
Subject: [PATCH 1/2] [clang][PCH] Don't try to create standalone debug-info
 for types marked nodebug

Fixes one of the crashes uncovered by
https://github.com/llvm/llvm-project/pull/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.
---
 clang/lib/CodeGen/ObjectFilePCHContainerWriter.cpp |  3 +++
 clang/test/Modules/gmodules-nodebug.cpp            | 12 ++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 clang/test/Modules/gmodules-nodebug.cpp

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

>From 0f6d6f30871bfc9779ad656e1031aa33cc2ce55e Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Fri, 17 Jan 2025 00:11:03 +0000
Subject: [PATCH 2/2] fixup! add REQUIRES: asserts

---
 clang/test/Modules/gmodules-nodebug.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/Modules/gmodules-nodebug.cpp b/clang/test/Modules/gmodules-nodebug.cpp
index ac987c074f18c9..d83103768e838a 100644
--- a/clang/test/Modules/gmodules-nodebug.cpp
+++ b/clang/test/Modules/gmodules-nodebug.cpp
@@ -1,3 +1,5 @@
+// REQUIRES: asserts
+
 // 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



More information about the cfe-commits mailing list