Author: David Blaikie
Date: 2025-01-15T23:20:40Z
New Revision: 504dd577675e8c85cdc8525990a7c8b517a38a89

URL: 
https://github.com/llvm/llvm-project/commit/504dd577675e8c85cdc8525990a7c8b517a38a89
DIFF: 
https://github.com/llvm/llvm-project/commit/504dd577675e8c85cdc8525990a7c8b517a38a89.diff

LOG: DebugInfo: Avoid emitting null members for nodebug nested typedefs

Only comes up for CodeView, since it forcibly emits even unused nested
typedefs.

Part of issue #122350

Added: 
    clang/test/CodeGenCXX/debug-info-codeview-nodebug.cpp

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index f9cba414dcfe2c..f88f56c98186da 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1907,8 +1907,8 @@ void CGDebugInfo::CollectRecordNestedType(
   if (isa<InjectedClassNameType>(Ty))
     return;
   SourceLocation Loc = TD->getLocation();
-  llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc));
-  elements.push_back(nestedType);
+  if (llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc)))
+    elements.push_back(nestedType);
 }
 
 void CGDebugInfo::CollectRecordFields(

diff  --git a/clang/test/CodeGenCXX/debug-info-codeview-nodebug.cpp 
b/clang/test/CodeGenCXX/debug-info-codeview-nodebug.cpp
new file mode 100644
index 00000000000000..c57133d8ac7212
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-codeview-nodebug.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -DSETNODEBUG=0 -gcodeview -emit-llvm -std=c++14 
-debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=YESINFO
+// RUN: %clang_cc1 -DSETNODEBUG=1 -gcodeview -emit-llvm -std=c++14 
-debug-info-kind=limited %s -o - | FileCheck %s --check-prefix=NOINFO
+
+#if SETNODEBUG
+#define NODEBUG __attribute__((nodebug))
+#else
+#define NODEBUG
+#endif
+
+struct t1 {
+  using t2 NODEBUG = void;
+};
+void func6() {
+  t1 v1;
+}
+// YESINFO-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "t2"
+// NOINFO: [[ELEMENTS:!.*]] = !{}
+// NOINFO: !DICompositeType(tag: DW_TAG_structure_type, name: "t1", {{.*}}, 
elements: [[ELEMENTS]],
+// NOINFO-NOT:  !DIDerivedType(tag: DW_TAG_typedef, name: "t2"
+


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to