[llvm] r334382 - [CodeView] Omit forward references for unnamed structs and unions

Brock Wyma via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 10 18:39:35 PDT 2018


Author: bwyma
Date: Sun Jun 10 18:39:34 2018
New Revision: 334382

URL: http://llvm.org/viewvc/llvm-project?rev=334382&view=rev
Log:

[CodeView] Omit forward references for unnamed structs and unions

Codeview references to unnamed structs and unions are expected to refer to the
complete type definition instead of a forward reference so Visual Studio can
resolve the type properly.

Differential Revision: https://reviews.llvm.org/D32498


Added:
    llvm/trunk/test/DebugInfo/COFF/lambda.ll
    llvm/trunk/test/DebugInfo/COFF/types-recursive-unnamed.ll
    llvm/trunk/test/DebugInfo/COFF/unnamed.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/trunk/test/DebugInfo/COFF/bitfields.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=334382&r1=334381&r2=334382&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Sun Jun 10 18:39:34 2018
@@ -2004,7 +2004,28 @@ ClassInfo CodeViewDebug::collectClassInf
   return Info;
 }
 
+static bool shouldAlwaysEmitCompleteClassType(const DICompositeType *Ty) {
+  // This routine is used by lowerTypeClass and lowerTypeUnion to determine
+  // if a complete type should be emitted instead of a forward reference.
+  return Ty->getName().empty() && Ty->getIdentifier().empty() &&
+      !Ty->isForwardDecl();
+}
+
 TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
+  // Emit the complete type for unnamed structs.  C++ classes with methods
+  // which have a circular reference back to the class type are expected to
+  // be named by the front-end and should not be "unnamed".  C unnamed
+  // structs should not have circular references.
+  if (shouldAlwaysEmitCompleteClassType(Ty)) {
+    // If this unnamed complete type is already in the process of being defined
+    // then the description of the type is malformed and cannot be emitted
+    // into CodeView correctly so report a fatal error.
+    auto I = CompleteTypeIndices.find(Ty);
+    if (I != CompleteTypeIndices.end() && I->second == TypeIndex())
+      report_fatal_error("cannot debug circular reference to unnamed type");
+    return getCompleteTypeIndex(Ty);
+  }
+
   // First, construct the forward decl.  Don't look into Ty to compute the
   // forward decl options, since it might not be available in all TUs.
   TypeRecordKind Kind = getRecordKind(Ty);
@@ -2049,6 +2070,10 @@ TypeIndex CodeViewDebug::lowerCompleteTy
 }
 
 TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
+  // Emit the complete type for unnamed unions.
+  if (shouldAlwaysEmitCompleteClassType(Ty))
+    return getCompleteTypeIndex(Ty);
+
   ClassOptions CO =
       ClassOptions::ForwardReference | getCommonClassOptions(Ty);
   std::string FullName = getFullyQualifiedName(Ty);
@@ -2278,9 +2303,7 @@ TypeIndex CodeViewDebug::getCompleteType
     return getTypeIndex(Ty);
   }
 
-  // Check if we've already translated the complete record type.  Lowering a
-  // complete type should never trigger lowering another complete type, so we
-  // can reuse the hash table lookup result.
+  // Check if we've already translated the complete record type.
   const auto *CTy = cast<DICompositeType>(Ty);
   auto InsertResult = CompleteTypeIndices.insert({CTy, TypeIndex()});
   if (!InsertResult.second)
@@ -2291,13 +2314,16 @@ TypeIndex CodeViewDebug::getCompleteType
   // Make sure the forward declaration is emitted first. It's unclear if this
   // is necessary, but MSVC does it, and we should follow suit until we can show
   // otherwise.
-  TypeIndex FwdDeclTI = getTypeIndex(CTy);
-
-  // Just use the forward decl if we don't have complete type info. This might
-  // happen if the frontend is using modules and expects the complete definition
-  // to be emitted elsewhere.
-  if (CTy->isForwardDecl())
-    return FwdDeclTI;
+  // We only emit a forward declaration for named types.
+  if (!CTy->getName().empty() || !CTy->getIdentifier().empty()) {
+    TypeIndex FwdDeclTI = getTypeIndex(CTy);
+
+    // Just use the forward decl if we don't have complete type info. This
+    // might happen if the frontend is using modules and expects the complete
+    // definition to be emitted elsewhere.
+    if (CTy->isForwardDecl())
+      return FwdDeclTI;
+  }
 
   TypeIndex TI;
   switch (CTy->getTag()) {
@@ -2312,7 +2338,11 @@ TypeIndex CodeViewDebug::getCompleteType
     llvm_unreachable("not a record");
   }
 
-  InsertResult.first->second = TI;
+  // Update the type index associated with this CompositeType.  This cannot
+  // use the 'InsertResult' iterator above because it is potentially
+  // invalidated by map insertions which can occur while lowering the class
+  // type above.
+  CompleteTypeIndices[CTy] = TI;
   return TI;
 }
 

Modified: llvm/trunk/test/DebugInfo/COFF/bitfields.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/bitfields.ll?rev=334382&r1=334381&r2=334382&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/bitfields.ll (original)
+++ llvm/trunk/test/DebugInfo/COFF/bitfields.ll Sun Jun 10 18:39:34 2018
@@ -63,15 +63,29 @@
 ; CHECK:    BitSize: 2
 ; CHECK:    BitOffset: 23
 ; CHECK:  }
+; CHECK:  FieldList ([[anon_fl:.*]]) {
+; CHECK:    TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK:    DataMember {
+; CHECK:      TypeLeafKind: LF_MEMBER (0x150D)
+; CHECK:      Type: char (0x70)
+; CHECK:      FieldOffset: 0x0
+; CHECK:      Name: c
+; CHECK:    }
+; CHECK:    DataMember {
+; CHECK:      TypeLeafKind: LF_MEMBER (0x150D)
+; CHECK:      Type: short (0x11)
+; CHECK:      FieldOffset: 0x1
+; CHECK:      Name: s
+; CHECK:    }
+; CHECK:  }
 ; CHECK:  Struct ([[anon_ty:.*]]) {
 ; CHECK:    TypeLeafKind: LF_STRUCTURE (0x1505)
-; CHECK:    MemberCount: 0
-; CHECK:    Properties [ (0x88)
-; CHECK:      ForwardReference (0x80)
+; CHECK:    MemberCount: 2
+; CHECK:    Properties [ (0x8)
 ; CHECK:      Nested (0x8)
 ; CHECK:    ]
-; CHECK:    FieldList: 0x0
-; CHECK:    SizeOf: 0
+; CHECK:    FieldList: <field list> ([[anon_fl]])
+; CHECK:    SizeOf: 3
 ; CHECK:    Name: S1::<unnamed-tag>
 ; CHECK:  }
 ; CHECK:  BitField ([[S1_u:.*]]) {
@@ -126,29 +140,6 @@
 ; CHECK:    SizeOf: 16
 ; CHECK:    Name: S1
 ; CHECK:  }
-; CHECK:  FieldList ([[anon_fl:.*]]) {
-; CHECK:    TypeLeafKind: LF_FIELDLIST (0x1203)
-; CHECK:    DataMember {
-; CHECK:      Type: char (0x70)
-; CHECK:      FieldOffset: 0x0
-; CHECK:      Name: c
-; CHECK:    }
-; CHECK:    DataMember {
-; CHECK:      Type: short (0x11)
-; CHECK:      FieldOffset: 0x1
-; CHECK:      Name: s
-; CHECK:    }
-; CHECK:  }
-; CHECK:  Struct ({{.*}}) {
-; CHECK:    TypeLeafKind: LF_STRUCTURE (0x1505)
-; CHECK:    MemberCount: 2
-; CHECK:    Properties [ (0x8)
-; CHECK:      Nested (0x8)
-; CHECK:    ]
-; CHECK:    FieldList: <field list> ([[anon_fl]])
-; CHECK:    SizeOf: 3
-; CHECK:    Name: S1::<unnamed-tag>
-; CHECK:  }
 ; CHECK:  BitField ([[S2_y:.*]]) {
 ; CHECK:    TypeLeafKind: LF_BITFIELD (0x1205)
 ; CHECK:    Type: int (0x74)

Added: llvm/trunk/test/DebugInfo/COFF/lambda.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/lambda.ll?rev=334382&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/lambda.ll (added)
+++ llvm/trunk/test/DebugInfo/COFF/lambda.ll Sun Jun 10 18:39:34 2018
@@ -0,0 +1,149 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
+;
+; Verify lambda routines are emitted properly in CodeView.
+;
+; The original source code:
+; -----------------------------------------------------------------------------
+; int main(int argc, char* argv[], char* arge[]) {
+;   auto Lambda = [argc](int count) -> int { return argc == count ? 1 : 0; };
+;   return Lambda(0);
+; }
+; -----------------------------------------------------------------------------
+;
+; To regenerate the IR below compile the source code:
+;   $ clang lambda.cxx -S -emit-llvm -g -gcodeview
+;
+; CHECK:      FieldList ([[FIELDLIST_ID:0x[0-9A-F]+]]) {
+; CHECK-NEXT:   TypeLeafKind: LF_FIELDLIST ({{.*}})
+; CHECK-NEXT:   DataMember {
+; CHECK-NEXT:     TypeLeafKind: LF_MEMBER ({{.*}})
+; CHECK-NEXT:     AccessSpecifier: Private ({{.*}})
+; CHECK-NEXT:     Type: int ({{.*}})
+; CHECK-NEXT:     FieldOffset: {{.*}}
+; CHECK-NEXT:     Name: argc
+; CHECK-NEXT:   }
+; CHECK-NEXT:   OneMethod {
+; CHECK-NEXT:     TypeLeafKind: LF_ONEMETHOD (0x1511)
+; CHECK-NEXT:     AccessSpecifier: Public (0x3)
+; CHECK-NEXT:     Type: int main::<unnamed-tag>::(int) ({{.*}})
+; CHECK-NEXT:     Name: operator()
+; CHECK-NEXT:   }
+; CHECK-NEXT: }
+; CHECK-NEXT: Class ([[CLASS_ID:0x[0-9A-F]+]]) {
+; CHECK-NEXT:   TypeLeafKind: LF_CLASS ({{.*}})
+; CHECK-NEXT:   MemberCount: {{.*}}
+; CHECK-NEXT:   Properties [ ({{.*}})
+; CHECK-NEXT:     HasUniqueName ({{.*}})
+; CHECK-NEXT:     Scoped ({{.*}})
+; CHECK-NEXT:   ]
+; CHECK-NEXT:   FieldList: <field list> ([[FIELDLIST_ID]])
+; CHECK-NEXT:   DerivedFrom: {{.*}}
+; CHECK-NEXT:   VShape: {{.*}}
+; CHECK-NEXT:   SizeOf: {{.*}}
+; CHECK-NEXT:   Name: main::<unnamed-tag>
+; CHECK-NEXT:   LinkageName: {{.*lambda.*}}
+; CHECK-NEXT: }
+;             LocalSym {
+;               Kind: S_LOCAL ({{.*}})
+; CHECK:        Type: main::<unnamed-tag> ([[CLASS_ID]])
+;               Flags [ (0x0)
+;               ]
+; CHECK:        VarName: Lambda
+;             }
+
+; ModuleID = 'lambda.cxx'
+source_filename = "lambda.cxx"
+target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "i686-pc-windows-msvc19.0.24210"
+
+%class.anon = type { i32 }
+
+; Function Attrs: noinline norecurse optnone
+define dso_local i32 @main(i32 %argc, i8** %argv, i8** %arge) #0 !dbg !8 {
+entry:
+  %retval = alloca i32, align 4
+  %arge.addr = alloca i8**, align 4
+  %argv.addr = alloca i8**, align 4
+  %argc.addr = alloca i32, align 4
+  %Lambda = alloca %class.anon, align 4
+  store i32 0, i32* %retval, align 4
+  store i8** %arge, i8*** %arge.addr, align 4
+  call void @llvm.dbg.declare(metadata i8*** %arge.addr, metadata !15, metadata !DIExpression()), !dbg !16
+  store i8** %argv, i8*** %argv.addr, align 4
+  call void @llvm.dbg.declare(metadata i8*** %argv.addr, metadata !17, metadata !DIExpression()), !dbg !16
+  store i32 %argc, i32* %argc.addr, align 4
+  call void @llvm.dbg.declare(metadata i32* %argc.addr, metadata !18, metadata !DIExpression()), !dbg !16
+  call void @llvm.dbg.declare(metadata %class.anon* %Lambda, metadata !19, metadata !DIExpression()), !dbg !28
+  %0 = getelementptr inbounds %class.anon, %class.anon* %Lambda, i32 0, i32 0, !dbg !28
+  %1 = load i32, i32* %argc.addr, align 4, !dbg !28
+  store i32 %1, i32* %0, align 4, !dbg !28
+  %call = call x86_thiscallcc i32 @"??R<lambda_0>@?0??main@@9 at QBE@H at Z"(%class.anon* %Lambda, i32 0), !dbg !29
+  ret i32 %call, !dbg !29
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline nounwind optnone
+define internal x86_thiscallcc i32 @"??R<lambda_0>@?0??main@@9 at QBE@H at Z"(%class.anon* %this, i32 %count) #2 align 2 !dbg !30 {
+entry:
+  %count.addr = alloca i32, align 4
+  %this.addr = alloca %class.anon*, align 4
+  store i32 %count, i32* %count.addr, align 4
+  call void @llvm.dbg.declare(metadata i32* %count.addr, metadata !31, metadata !DIExpression()), !dbg !32
+  store %class.anon* %this, %class.anon** %this.addr, align 4
+  call void @llvm.dbg.declare(metadata %class.anon** %this.addr, metadata !33, metadata !DIExpression()), !dbg !35
+  %this1 = load %class.anon*, %class.anon** %this.addr, align 4
+  %0 = getelementptr inbounds %class.anon, %class.anon* %this1, i32 0, i32 0, !dbg !32
+  %1 = load i32, i32* %0, align 4, !dbg !32
+  %2 = load i32, i32* %count.addr, align 4, !dbg !32
+  %cmp = icmp eq i32 %1, %2, !dbg !32
+  %3 = zext i1 %cmp to i64, !dbg !32
+  %cond = select i1 %cmp, i32 1, i32 0, !dbg !32
+  ret i32 %cond, !dbg !32
+}
+
+attributes #0 = { noinline norecurse optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone speculatable }
+attributes #2 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6}
+!llvm.ident = !{!7}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 7.0.0 (trunk)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "lambda.cxx", directory: "C:\5Cpath\5Cto", checksumkind: CSK_MD5, checksum: "8d860c432e3763effaf1658460a496c0")
+!2 = !{}
+!3 = !{i32 1, !"NumRegisterParameters", i32 0}
+!4 = !{i32 2, !"CodeView", i32 1}
+!5 = !{i32 2, !"Debug Info Version", i32 3}
+!6 = !{i32 1, !"wchar_size", i32 2}
+!7 = !{!"clang version 7.0.0 (trunk)"}
+!8 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
+!9 = !DISubroutineType(types: !10)
+!10 = !{!11, !11, !12, !12}
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 32)
+!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 32)
+!14 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!15 = !DILocalVariable(name: "arge", arg: 3, scope: !8, file: !1, line: 1, type: !12)
+!16 = !DILocation(line: 1, scope: !8)
+!17 = !DILocalVariable(name: "argv", arg: 2, scope: !8, file: !1, line: 1, type: !12)
+!18 = !DILocalVariable(name: "argc", arg: 1, scope: !8, file: !1, line: 1, type: !11)
+!19 = !DILocalVariable(name: "Lambda", scope: !8, file: !1, line: 2, type: !20)
+!20 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !8, file: !1, line: 2, size: 32, flags: DIFlagTypePassByValue, elements: !21, identifier: "??R<lambda_0>@?0??main@@9 at QBE@H at Z")
+!21 = !{!22, !23}
+!22 = !DIDerivedType(tag: DW_TAG_member, name: "argc", scope: !20, file: !1, line: 2, baseType: !11, size: 32)
+!23 = !DISubprogram(name: "operator()", scope: !20, file: !1, line: 2, type: !24, isLocal: false, isDefinition: false, scopeLine: 2, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: false)
+!24 = !DISubroutineType(cc: DW_CC_BORLAND_thiscall, types: !25)
+!25 = !{!11, !26, !11}
+!26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !27, size: 32, flags: DIFlagArtificial | DIFlagObjectPointer)
+!27 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !20)
+!28 = !DILocation(line: 2, scope: !8)
+!29 = !DILocation(line: 3, scope: !8)
+!30 = distinct !DISubprogram(name: "operator()", linkageName: "??R<lambda_0>@?0??main@@9 at QBE@H at Z", scope: !20, file: !1, line: 2, type: !24, isLocal: true, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !23, retainedNodes: !2)
+!31 = !DILocalVariable(name: "count", arg: 2, scope: !30, file: !1, line: 2, type: !11)
+!32 = !DILocation(line: 2, scope: !30)
+!33 = !DILocalVariable(name: "this", arg: 1, scope: !30, type: !34, flags: DIFlagArtificial | DIFlagObjectPointer)
+!34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !27, size: 32)
+!35 = !DILocation(line: 0, scope: !30)

Added: llvm/trunk/test/DebugInfo/COFF/types-recursive-unnamed.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/types-recursive-unnamed.ll?rev=334382&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/types-recursive-unnamed.ll (added)
+++ llvm/trunk/test/DebugInfo/COFF/types-recursive-unnamed.ll Sun Jun 10 18:39:34 2018
@@ -0,0 +1,78 @@
+; RUN: not llc < %s -filetype=obj 2>&1 | FileCheck %s
+;
+; Verify the compiler produces an error message when trying to emit circular
+; references to unnamed structs which are not supported in CodeView debug
+; information.
+; 
+; -- types-recursive-unnamed.cpp begin -----------------------------------------
+; struct named_struct {
+;   struct {
+;     void method() {}
+;   } unnamed_struct_with_method;
+;   void anchor();
+; };
+; void named_struct::anchor() {}
+; -- types-recursive-unnamed.cpp end -------------------------------------------
+;
+; To rebuild the reproducer:
+;   1. First, compile the source code:
+;      $ clang -S -emit-llvm -g -gcodeview unnamed.cpp
+;   2. Remove all "name" and "identifier" attributes with a value matching
+;      the form: "<unnamed-type-".
+;
+; CHECK: LLVM ERROR: cannot debug circular reference to unnamed type
+
+; ModuleID = 'types-recursive-unnamed.cpp'
+source_filename = "types-recursive-unnamed.cpp"
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.0.24210"
+
+%struct.named_struct = type { %struct.anon }
+%struct.anon = type { i8 }
+
+; Function Attrs: noinline nounwind uwtable
+define void @"\01?anchor at named_struct@@QEAAXXZ"(%struct.named_struct* %this) #0 align 2 !dbg !7 {
+entry:
+  %this.addr = alloca %struct.named_struct*, align 8
+  store %struct.named_struct* %this, %struct.named_struct** %this.addr, align 8
+  call void @llvm.dbg.declare(metadata %struct.named_struct** %this.addr, metadata !21, metadata !23), !dbg !24
+  %this1 = load %struct.named_struct*, %struct.named_struct** %this.addr, align 8
+  ret void, !dbg !25
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "types-recursive-unnamed.cpp", directory: "C:\5Cpath\5Cto\5Cdirectory", checksumkind: CSK_MD5, checksum: "59a90813f3338cfe690d9664215089df")
+!2 = !{}
+!3 = !{i32 2, !"CodeView", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"PIC Level", i32 2}
+!6 = !{!"clang version 5.0.0"}
+!7 = distinct !DISubprogram(name: "anchor", linkageName: "\01?anchor at named_struct@@QEAAXXZ", scope: !8, file: !1, line: 7, type: !18, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !17, retainedNodes: !2)
+!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "named_struct", file: !1, line: 1, size: 8, elements: !9, identifier: ".?AUnamed_struct@@")
+!9 = !{!10, !16, !17}
+!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !8, file: !1, line: 2, size: 8, elements: !11)
+!11 = !{!12}
+!12 = !DISubprogram(name: "method", linkageName: "\01?method@<unnamed-type-unnamed_struct_with_method>@named_struct@@QEAAXXZ", scope: !10, file: !1, line: 3, type: !13, isLocal: false, isDefinition: false, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false)
+!13 = !DISubroutineType(types: !14)
+!14 = !{null, !15}
+!15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!16 = !DIDerivedType(tag: DW_TAG_member, name: "unnamed_struct_with_method", scope: !8, file: !1, line: 4, baseType: !10, size: 8)
+!17 = !DISubprogram(name: "anchor", linkageName: "\01?anchor at named_struct@@QEAAXXZ", scope: !8, file: !1, line: 5, type: !18, isLocal: false, isDefinition: false, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false)
+!18 = !DISubroutineType(types: !19)
+!19 = !{null, !20}
+!20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
+!21 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !22, flags: DIFlagArtificial | DIFlagObjectPointer)
+!22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!23 = !DIExpression()
+!24 = !DILocation(line: 0, scope: !7)
+!25 = !DILocation(line: 7, column: 30, scope: !7)

Added: llvm/trunk/test/DebugInfo/COFF/unnamed.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/unnamed.ll?rev=334382&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/COFF/unnamed.ll (added)
+++ llvm/trunk/test/DebugInfo/COFF/unnamed.ll Sun Jun 10 18:39:34 2018
@@ -0,0 +1,200 @@
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
+;
+; Verify CodeView emission does not emit forward references for unnamed
+; structs/unions.  If a forward reference is emitted for an unnamed composite
+; type then Visual Studio will not be able to display the value.
+;
+;   Previous values displayed by Visual Studio:
+;      local.unnamed_struct    {...}
+;      local.unnamed_union     {...}
+;
+;   New values displayed by Visual Studio:
+;      local.unnamed_struct    {m3=66 'B' }
+;      local.unnamed_union     {m1=65 m2=65 'A' }
+;
+; The reproducer:
+;   $ cat unnamed.c
+;   struct named_struct {
+;     int    id;
+;     union {
+;       int  m1;
+;       char m2;
+;     } unnamed_union;
+;     struct {
+;       char m3;
+;     } unnamed_struct;
+;   };
+;   
+;   int main()
+;   {
+;     struct named_struct local;
+;   
+;     local.id = 1;
+;     local.unnamed_union.m1 = 65;
+;     local.unnamed_struct.m3 = 'B';
+;   
+;     return 0;
+;   }
+;
+; To regenerate the IR below:
+;   $ clang unnamed.c -S -emit-llvm -g -gcodeview
+;
+; CHECK:      FieldList ([[UnnamedUnionFieldList:.*]]) {
+; CHECK-NEXT:   TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK-NEXT:   DataMember {
+; CHECK-NEXT:     TypeLeafKind: LF_MEMBER (0x150D)
+; CHECK-NEXT:     AccessSpecifier: Public (0x3)
+; CHECK-NEXT:     Type: int (0x74)
+; CHECK-NEXT:     FieldOffset: 0x0
+; CHECK-NEXT:     Name: m1
+; CHECK-NEXT:   }
+; CHECK-NEXT:   DataMember {
+; CHECK-NEXT:     TypeLeafKind: LF_MEMBER (0x150D)
+; CHECK-NEXT:     AccessSpecifier: Public (0x3)
+; CHECK-NEXT:     Type: char (0x70)
+; CHECK-NEXT:     FieldOffset: 0x0
+; CHECK-NEXT:     Name: m2
+; CHECK-NEXT:   }
+; CHECK-NEXT: }
+; CHECK:      Union ([[UnnamedUnion:.*]]) {
+; CHECK-NEXT:   TypeLeafKind: LF_UNION (0x1506)
+; CHECK-NEXT:   MemberCount: 2
+; CHECK-NEXT:   Properties [ (0x408)
+; CHECK-NEXT:     Nested (0x8)
+; CHECK-NEXT:     Sealed (0x400)
+; CHECK-NEXT:   ]
+; CHECK-NEXT:   FieldList: <field list> ([[UnnamedUnionFieldList]])
+; CHECK-NEXT:   SizeOf: 4
+; CHECK-NEXT:   Name: named_struct::<unnamed-tag>
+; CHECK-NEXT: }
+; CHECK:      FieldList ([[UnnamedStructFieldList:.*]]) {
+; CHECK-NEXT:   TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK-NEXT:   DataMember {
+; CHECK-NEXT:     TypeLeafKind: LF_MEMBER (0x150D)
+; CHECK-NEXT:     AccessSpecifier: Public (0x3)
+; CHECK-NEXT:     Type: char (0x70)
+; CHECK-NEXT:     FieldOffset: 0x0
+; CHECK-NEXT:     Name: m3
+; CHECK-NEXT:   }
+; CHECK-NEXT: }
+; CHECK:      Struct ([[UnnamedStruct:.*]]) {
+; CHECK-NEXT:   TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK-NEXT:   MemberCount: 1
+; CHECK-NEXT:   Properties [ (0x8)
+; CHECK-NEXT:     Nested (0x8)
+; CHECK-NEXT:   ]
+; CHECK-NEXT:   FieldList: <field list> ([[UnnamedStructFieldList]])
+; CHECK-NEXT:   DerivedFrom: 0x0
+; CHECK-NEXT:   VShape: 0x0
+; CHECK-NEXT:   SizeOf: 1
+; CHECK-NEXT:   Name: named_struct::<unnamed-tag>
+; CHECK-NEXT: }
+; CHECK:      FieldList ([[NamedStructFieldList:.*]]) {
+; CHECK-NEXT:   TypeLeafKind: LF_FIELDLIST (0x1203)
+; CHECK-NEXT:   DataMember {
+; CHECK-NEXT:     TypeLeafKind: LF_MEMBER (0x150D)
+; CHECK-NEXT:     AccessSpecifier: Public (0x3)
+; CHECK-NEXT:     Type: int (0x74)
+; CHECK-NEXT:     FieldOffset: 0x0
+; CHECK-NEXT:     Name: id
+; CHECK-NEXT:   }
+; CHECK-NEXT:   DataMember {
+; CHECK-NEXT:     TypeLeafKind: LF_MEMBER (0x150D)
+; CHECK-NEXT:     AccessSpecifier: Public (0x3)
+; CHECK-NEXT:     Type: named_struct::<unnamed-tag> ([[UnnamedUnion]])
+; CHECK-NEXT:     FieldOffset: 0x4
+; CHECK-NEXT:     Name: unnamed_union
+; CHECK-NEXT:   }
+; CHECK-NEXT:   DataMember {
+; CHECK-NEXT:     TypeLeafKind: LF_MEMBER (0x150D)
+; CHECK-NEXT:     AccessSpecifier: Public (0x3)
+; CHECK-NEXT:     Type: named_struct::<unnamed-tag> ([[UnnamedStruct]])
+; CHECK-NEXT:     FieldOffset: 0x8
+; CHECK-NEXT:     Name: unnamed_struct
+; CHECK-NEXT:   }
+; CHECK-NEXT: }
+; CHECK:      Struct ({{.*}}) {
+; CHECK-NEXT:   TypeLeafKind: LF_STRUCTURE (0x1505)
+; CHECK-NEXT:   MemberCount: 3
+; CHECK-NEXT:   Properties [ (0x0)
+; CHECK-NEXT:   ]
+; CHECK-NEXT:   FieldList: <field list> ([[NamedStructFieldList]])
+; CHECK-NEXT:   DerivedFrom: 0x0
+; CHECK-NEXT:   VShape: 0x0
+; CHECK-NEXT:   SizeOf: 12
+; CHECK-NEXT:   Name: named_struct
+; CHECK-NEXT: }
+
+; ModuleID = 'unnamed.c'
+source_filename = "unnamed.c"
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.0.24210"
+
+%struct.named_struct = type { i32, %union.anon, %struct.anon }
+%union.anon = type { i32 }
+%struct.anon = type { i8 }
+
+; Function Attrs: noinline nounwind uwtable
+define i32 @main() #0 !dbg !7 {
+entry:
+  %retval = alloca i32, align 4
+  %local = alloca %struct.named_struct, align 4
+  store i32 0, i32* %retval, align 4
+  call void @llvm.dbg.declare(metadata %struct.named_struct* %local, metadata !11, metadata !25), !dbg !26
+  %id = getelementptr inbounds %struct.named_struct, %struct.named_struct* %local, i32 0, i32 0, !dbg !27
+  store i32 1, i32* %id, align 4, !dbg !28
+  %unnamed_union = getelementptr inbounds %struct.named_struct, %struct.named_struct* %local, i32 0, i32 1, !dbg !29
+  %m1 = bitcast %union.anon* %unnamed_union to i32*, !dbg !30
+  store i32 65, i32* %m1, align 4, !dbg !31
+  %unnamed_struct = getelementptr inbounds %struct.named_struct, %struct.named_struct* %local, i32 0, i32 2, !dbg !32
+  %m3 = getelementptr inbounds %struct.anon, %struct.anon* %unnamed_struct, i32 0, i32 0, !dbg !33
+  store i8 66, i8* %m3, align 4, !dbg !34
+  ret i32 0, !dbg !35
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.0 (trunk)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "unnamed.c", directory: "C:\5Cpath\5Cto\5Cdirectory", checksumkind: CSK_MD5, checksum: "a1874da39665a126d6949d929fbd4818")
+!2 = !{}
+!3 = !{i32 2, !"CodeView", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"PIC Level", i32 2}
+!6 = !{!"clang version 5.0.0 (trunk)"}
+!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 12, type: !8, isLocal: false, isDefinition: true, scopeLine: 13, isOptimized: false, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DILocalVariable(name: "local", scope: !7, file: !1, line: 14, type: !12)
+!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "named_struct", file: !1, line: 1, size: 96, elements: !13)
+!13 = !{!14, !15, !21}
+!14 = !DIDerivedType(tag: DW_TAG_member, name: "id", scope: !12, file: !1, line: 2, baseType: !10, size: 32)
+!15 = !DIDerivedType(tag: DW_TAG_member, name: "unnamed_union", scope: !12, file: !1, line: 6, baseType: !16, size: 32, offset: 32)
+!16 = distinct !DICompositeType(tag: DW_TAG_union_type, scope: !12, file: !1, line: 3, size: 32, elements: !17)
+!17 = !{!18, !19}
+!18 = !DIDerivedType(tag: DW_TAG_member, name: "m1", scope: !16, file: !1, line: 4, baseType: !10, size: 32)
+!19 = !DIDerivedType(tag: DW_TAG_member, name: "m2", scope: !16, file: !1, line: 5, baseType: !20, size: 8)
+!20 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!21 = !DIDerivedType(tag: DW_TAG_member, name: "unnamed_struct", scope: !12, file: !1, line: 9, baseType: !22, size: 8, offset: 64)
+!22 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !12, file: !1, line: 7, size: 8, elements: !23)
+!23 = !{!24}
+!24 = !DIDerivedType(tag: DW_TAG_member, name: "m3", scope: !22, file: !1, line: 8, baseType: !20, size: 8)
+!25 = !DIExpression()
+!26 = !DILocation(line: 14, column: 23, scope: !7)
+!27 = !DILocation(line: 16, column: 9, scope: !7)
+!28 = !DILocation(line: 16, column: 12, scope: !7)
+!29 = !DILocation(line: 17, column: 9, scope: !7)
+!30 = !DILocation(line: 17, column: 23, scope: !7)
+!31 = !DILocation(line: 17, column: 26, scope: !7)
+!32 = !DILocation(line: 18, column: 9, scope: !7)
+!33 = !DILocation(line: 18, column: 24, scope: !7)
+!34 = !DILocation(line: 18, column: 27, scope: !7)
+!35 = !DILocation(line: 20, column: 3, scope: !7)




More information about the llvm-commits mailing list