Author: Zequan Wu
Date: 2022-12-06T08:29:55+08:00
New Revision: bb5bcddcdbc151119f449be2d1e0d90f2e9c4258

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

LOG: [CodeView] Don't generate dummy unnamed strcut/class/union type.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp
    clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index b0fe96d6b8a08..2a67f58d22ced 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1653,10 +1653,15 @@ void CGDebugInfo::CollectRecordFields(
       } else if (CGM.getCodeGenOpts().EmitCodeView) {
         // Debug info for nested types is included in the member list only for
         // CodeView.
-        if (const auto *nestedType = dyn_cast<TypeDecl>(I))
+        if (const auto *nestedType = dyn_cast<TypeDecl>(I)) {
+          // MSVC doesn't generate nested type for anonymous struct/union.
+          if (isa<RecordDecl>(I) &&
+              cast<RecordDecl>(I)->isAnonymousStructOrUnion())
+            continue;
           if (!nestedType->isImplicit() &&
               nestedType->getDeclContext() == record)
             CollectRecordNestedType(nestedType, elements);
+        }
       }
   }
 }

diff  --git a/clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp 
b/clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp
index 7c8f78e7a0016..8caf177dab67e 100644
--- a/clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp
+++ b/clang/test/CodeGenCXX/debug-info-codeview-nested-types.cpp
@@ -5,6 +5,11 @@ struct HasNested {
   typedef int InnerTypedef;
   enum { InnerEnumerator = 2 };
   struct InnerStruct { };
+
+  union { int i1; };
+  union { int i2; } unnamed_union;
+  struct { int i3; };
+  struct { int i4; } unnamed_struct;
 };
 HasNested f;
 
@@ -12,7 +17,7 @@ HasNested f;
 // CHECK: ![[HASNESTED:[0-9]+]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "HasNested",
 // CHECK-SAME: elements: ![[MEMBERS:[0-9]+]],
 //
-// CHECK: ![[MEMBERS]] = !{![[INNERENUM]], ![[INNERTYPEDEF:[0-9]+]], 
![[UNNAMEDENUM:[0-9]+]], ![[INNERSTRUCT:[0-9]+]]}
+// CHECK: ![[MEMBERS]] = !{![[INNERENUM]], ![[INNERTYPEDEF:[0-9]+]], 
![[UNNAMEDENUM:[0-9]+]], ![[INNERSTRUCT:[0-9]+]], ![[ANONYMOUS_UNION:[0-9]+]], 
![[UNNAMED_UNION_TYPE:[0-9]+]], ![[UNNAMED_UNION:[0-9]+]], 
![[ANONYMOUS_STRUCT:[0-9]+]], ![[UNNAMED_STRUCT_TYPE:[0-9]+]], 
![[UNNAMED_STRUCT:[0-9]+]]}
 //
 // CHECK: ![[INNERTYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: 
"InnerTypedef", scope: ![[HASNESTED]]{{.*}})
 //
@@ -23,3 +28,31 @@ HasNested f;
 //
 // CHECK: ![[INNERSTRUCT]] = !DICompositeType(tag: DW_TAG_structure_type, 
name: "InnerStruct"
 // CHECK-SAME: flags: DIFlagFwdDecl
+
+// CHECK: ![[ANONYMOUS_UNION]] = !DIDerivedType(tag: DW_TAG_member, 
+// CHECK-SAME: baseType: ![[ANONYMOUS_UNION_TYPE:[0-9]+]]
+// CHECK: ![[ANONYMOUS_UNION_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_union_type,
+// CHECK-SAME: elements: ![[ANONYMOUS_UNION_MEMBERS:[0-9]+]], identifier: 
".?AT<unnamed-type-$S1>@HasNested@@")
+// CHECK: ![[ANONYMOUS_UNION_MEMBERS]] = !{![[ANONYMOUS_UNION_MEMBER:[0-9]+]]}
+// CHECK: ![[ANONYMOUS_UNION_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, 
name: "i1"
+
+// CHECK: ![[UNNAMED_UNION_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_union_type, name: "<unnamed-type-unnamed_union>"
+// CHECK-SAME: elements: ![[UNNAMED_UNION_MEMBERS:[0-9]+]], identifier: 
".?AT<unnamed-type-unnamed_union>@HasNested@@")
+// CHECK: ![[UNNAMED_UNION_MEMBERS]] = !{![[UNNAMED_UNION_MEMBER:[0-9]+]]}
+// CHECK: ![[UNNAMED_UNION_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, name: 
"i2"
+// CHECK: ![[UNNAMED_UNION]] = !DIDerivedType(tag: DW_TAG_member, name: 
"unnamed_union"
+// CHECK-SAME: baseType: ![[UNNAMED_UNION_TYPE]]
+
+// CHECK: ![[ANONYMOUS_STRUCT]] = !DIDerivedType(tag: DW_TAG_member
+// CHECK-SAME: baseType: ![[ANONYMOUS_STRUCT_TYPE:[0-9]+]]
+// CHECK: ![[ANONYMOUS_STRUCT_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type
+// CHECK-SAME: elements: ![[ANONYMOUS_STRUCT_MEMBERS:[0-9]+]], identifier: 
".?AU<unnamed-type-$S2>@HasNested@@")
+// CHECK: ![[ANONYMOUS_STRUCT_MEMBERS]] = 
!{![[ANONYMOUS_STRUCT_MEMBER:[0-9]+]]}
+// CHECK: ![[ANONYMOUS_STRUCT_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, 
name: "i3"
+
+// CHECK: ![[UNNAMED_STRUCT_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "<unnamed-type-unnamed_struct>"
+// CHECK-SAME: elements: ![[UNNAMED_STRUCT_MEMBERS:[0-9]+]], identifier: 
".?AU<unnamed-type-unnamed_struct>@HasNested@@")
+// CHECK: ![[UNNAMED_STRUCT_MEMBERS]] = !{![[UNNAMED_STRUCT_MEMBER:[0-9]+]]}
+// CHECK: ![[UNNAMED_STRUCT_MEMBER]] = !DIDerivedType(tag: DW_TAG_member, 
name: "i4"
+// CHECK: ![[UNNAMED_STRUCT]] = !DIDerivedType(tag: DW_TAG_member, name: 
"unnamed_struct"
+// CHECK-SAME: baseType: ![[UNNAMED_STRUCT_TYPE]]


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

Reply via email to