191 changes: 86 additions & 105 deletions llvm/test/DebugInfo/COFF/global-constants.ll
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
; RUN: llc < %s | FileCheck %s --check-prefix=ASM
; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s --check-prefix=OBJ

; C++ source to regenerate:
; // C++ source to regenerate:
; namespace Test1 {
; const float TestConst1 = 3.14;
; }
; struct S {
; static const int TestConst2 = -10;
; enum { SEnum = 42 };
; }
; };
; enum TestEnum : int {
; ENUM_A = 2147000000,
; ENUM_B = -2147000000,
; ENUM_A = 2147000000,
; ENUM_B = -2147000000,
; };
; void useConst(int);
; void foo() {
Expand All @@ -20,27 +20,33 @@
; useConst(ENUM_B);
; useConst(S::SEnum);
; }
; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll
;
; $ clang a.cpp -S -emit-llvm -g -gcodeview

; ASM-LABEL: .long 241 # Symbol subsection for globals
; ASM: .short {{.*-.*}} # Record length
; ASM: .short 4359 # Record kind: S_CONSTANT
; ASM-NEXT: .long 4102 # Type
; ASM-NEXT: .byte 0x04, 0x80, 0xc3, 0xf5 # Value
; ASM-NEXT: .byte 0x48, 0x40
; ASM-NEXT: .asciz "Test1::TestConst1" # Name
; ASM: .short {{.*-.*}} # Record length
; ASM: .short 4359 # Record kind: S_CONSTANT
; ASM-NEXT: .long 4103 # Type
; ASM-NEXT: .byte 0x61, 0x00 # Value
; ASM-NEXT: .asciz "S::TestConst2" # Name
; ASM: .short {{.*-.*}} # Record length
; ASM: .short 4359 # Record kind: S_CONSTANT
; ASM-NEXT: .long 4105 # Type
; ASM-NEXT: .byte 0x0a, 0x80, 0x40, 0x61 # Value
; ASM-NEXT: .byte 0x07, 0x80, 0xff, 0xff
; ASM-NEXT: .byte 0xff, 0xff
; ASM-NEXT: .asciz "ENUM_B" # Name

; ASM: .short 4359 # Record kind: S_CONSTANT
; ASM-NEXT: .long 4099 # Type
; ASM-NEXT: .byte 0x04, 0x80, 0xc3, 0xf5 # Value
; ASM-NEXT: .byte 0x48, 0x40
; ASM-NEXT: .asciz "Test1::TestConst1" # Name
; ASM-NEXT: .p2align 2

; ASM: .short 4359 # Record kind: S_CONSTANT
; ASM-NEXT: .long 4101 # Type
; ASM-NEXT: .byte 0x0a, 0x80, 0xf6, 0xff # Value
; ASM-NEXT: .byte 0xff, 0xff, 0xff, 0xff
; ASM-NEXT: .byte 0xff, 0xff
; ASM-NEXT: .asciz "S::TestConst2" # Name
; ASM-NEXT: .p2align 2

; ASM: .short 4359 # Record kind: S_CONSTANT
; ASM-NEXT: .long 4110 # Type
; ASM-NEXT: .byte 0x0a, 0x80, 0x40, 0x61 # Value
; ASM-NEXT: .byte 0x07, 0x80, 0xff, 0xff
; ASM-NEXT: .byte 0xff, 0xff
; ASM-NEXT: .asciz "ENUM_B" # Name
; ASM-NEXT: .p2align 2
; ASM-NOT: .asciz "S::SEnum" # Name

; OBJ: CodeViewDebugInfo [
Expand All @@ -50,110 +56,85 @@
; OBJ: SubSectionType: Symbols (0xF1)
; OBJ: ConstantSym {
; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
; OBJ-NEXT: Type: const float (0x1006)
; OBJ-NEXT: Type: const float (0x1003)
; OBJ-NEXT: Value: 1078523331
; OBJ-NEXT: Name: Test1::TestConst1
; OBJ-NEXT: }
; OBJ-NEXT: ConstantSym {
; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
; OBJ-NEXT: Type: const char (0x1007)
; OBJ-NEXT: Value: 97
; OBJ-NEXT: Type: const int (0x1005)
; OBJ-NEXT: Value: 18446744073709551606
; OBJ-NEXT: Name: S::TestConst2
; OBJ-NEXT: }
; OBJ-NEXT: ConstantSym {
; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
; OBJ-NEXT: Type: TestEnum (0x1009)
; OBJ-NEXT: Type: TestEnum (0x100E)
; OBJ-NEXT: Value: 18446744071562551616
; OBJ-NEXT: Name: ENUM_B
; OBJ-NEXT: }
; OBJ-NOT: Name: S::SEnum

; ModuleID = 't.cpp'
source_filename = "t.cpp"
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.16.27030"

; Function Attrs: noinline nounwind optnone uwtable
define dso_local void @"?useConst@@YAXH@Z"(i32) #0 !dbg !32 {
entry:
%.addr = alloca i32, align 4
store i32 %0, i32* %.addr, align 4
call void @llvm.dbg.declare(metadata i32* %.addr, metadata !36, metadata !DIExpression()), !dbg !37
ret void, !dbg !37
}

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
; ModuleID = 'a.cpp'
source_filename = "a.cpp"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.25.28614"

; Function Attrs: noinline norecurse nounwind optnone uwtable
define dso_local i32 @main() #2 !dbg !38 {
; Function Attrs: noinline optnone uwtable
define dso_local void @"?foo@@YAXXZ"() #0 !dbg !31 {
entry:
%retval = alloca i32, align 4
store i32 0, i32* %retval, align 4
call void @"?useConst@@YAXH@Z"(i32 3), !dbg !41
call void @"?useConst@@YAXH@Z"(i32 97), !dbg !42
call void @"?useConst@@YAXH@Z"(i32 -2147000000), !dbg !43
call void @"?useConst@@YAXH@Z"(i32 42), !dbg !44
call void @llvm.debugtrap(), !dbg !45
ret i32 0, !dbg !46
call void @"?useConst@@YAXH@Z"(i32 3), !dbg !35
call void @"?useConst@@YAXH@Z"(i32 -10), !dbg !36
call void @"?useConst@@YAXH@Z"(i32 -2147000000), !dbg !37
call void @"?useConst@@YAXH@Z"(i32 42), !dbg !38
ret void, !dbg !39
}

; Function Attrs: nounwind
declare void @llvm.debugtrap() #3
declare dso_local void @"?useConst@@YAXH@Z"(i32) #1

attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="none" "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"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readnone speculatable }
attributes #2 = { noinline norecurse nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="none" "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"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #3 = { nounwind }
attributes #0 = { noinline optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "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"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="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"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!27, !28, !29, !30}
!llvm.ident = !{!31}
!llvm.module.flags = !{!26, !27, !28, !29}
!llvm.ident = !{!30}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 9.0.0 (https://github.com/llvm/llvm-project.git f60f863075c7056f26e701b0405fc5752f0db576)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !16, globals: !17, nameTableKind: None)
!1 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Ctesting", checksumkind: CSK_MD5, checksum: "70da26ef1009521e2127bf71f8d532a2")
!2 = !{!3, !12}
!3 = !DICompositeType(tag: DW_TAG_enumeration_type, scope: !4, file: !1, line: 6, baseType: !9, size: 32, elements: !10, identifier: ".?AW4<unnamed-enum-SEnum>@S@@")
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 202f144bffd0be254a829924195e1b8ebabcbb79)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !15, globals: !16, nameTableKind: None)
!1 = !DIFile(filename: "a.cpp", directory: "F:\\llvm-project\\__test", checksumkind: CSK_MD5, checksum: "a1dbf3aabea9e8f9d1be48f60287942f")
!2 = !{!3, !11}
!3 = !DICompositeType(tag: DW_TAG_enumeration_type, scope: !4, file: !1, line: 6, baseType: !8, size: 32, elements: !9, identifier: ".?AW4<unnamed-enum-SEnum>@S@@")
!4 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !5, identifier: ".?AUS@@")
!5 = !{!6, !3}
!6 = !DIDerivedType(tag: DW_TAG_member, name: "TestConst2", scope: !4, file: !1, line: 5, baseType: !7, flags: DIFlagStaticMember, extraData: i8 97)
!6 = !DIDerivedType(tag: DW_TAG_member, name: "TestConst2", scope: !4, file: !1, line: 5, baseType: !7, flags: DIFlagStaticMember, extraData: i32 -10)
!7 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !8)
!8 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !{!11}
!11 = !DIEnumerator(name: "SEnum", value: 42)
!12 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "TestEnum", file: !1, line: 8, baseType: !9, size: 32, elements: !13, identifier: ".?AW4TestEnum@@")
!13 = !{!14, !15}
!14 = !DIEnumerator(name: "ENUM_A", value: 2147000000)
!15 = !DIEnumerator(name: "ENUM_B", value: -2147000000)
!16 = !{!4}
!17 = !{!18, !23, !25}
!18 = !DIGlobalVariableExpression(var: !19, expr: !DIExpression(DW_OP_constu, 1078523331, DW_OP_stack_value))
!19 = distinct !DIGlobalVariable(name: "TestConst1", scope: !20, file: !1, line: 2, type: !21, isLocal: true, isDefinition: true)
!20 = !DINamespace(name: "Test1", scope: null)
!21 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !22)
!22 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
!23 = !DIGlobalVariableExpression(var: !24, expr: !DIExpression(DW_OP_constu, 97, DW_OP_stack_value))
!24 = distinct !DIGlobalVariable(name: "TestConst2", scope: !0, file: !1, line: 5, type: !7, isLocal: true, isDefinition: true, declaration: !6)
!25 = !DIGlobalVariableExpression(var: !26, expr: !DIExpression(DW_OP_constu, 18446744071562551616, DW_OP_stack_value))
!26 = distinct !DIGlobalVariable(name: "ENUM_B", scope: !0, file: !1, line: 10, type: !12, isLocal: true, isDefinition: true)
!27 = !{i32 2, !"CodeView", i32 1}
!28 = !{i32 2, !"Debug Info Version", i32 3}
!29 = !{i32 1, !"wchar_size", i32 2}
!30 = !{i32 7, !"PIC Level", i32 2}
!31 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git f60f863075c7056f26e701b0405fc5752f0db576)"}
!32 = distinct !DISubprogram(name: "useConst", linkageName: "?useConst@@YAXH@Z", scope: !1, file: !1, line: 12, type: !33, scopeLine: 12, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !35)
!33 = !DISubroutineType(types: !34)
!34 = !{null, !9}
!35 = !{}
!36 = !DILocalVariable(arg: 1, scope: !32, file: !1, line: 12, type: !9)
!37 = !DILocation(line: 12, scope: !32)
!38 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 13, type: !39, scopeLine: 13, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !35)
!39 = !DISubroutineType(types: !40)
!40 = !{!9}
!41 = !DILocation(line: 14, scope: !38)
!42 = !DILocation(line: 15, scope: !38)
!43 = !DILocation(line: 16, scope: !38)
!44 = !DILocation(line: 17, scope: !38)
!45 = !DILocation(line: 18, scope: !38)
!46 = !DILocation(line: 19, scope: !38)
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!9 = !{!10}
!10 = !DIEnumerator(name: "SEnum", value: 42)
!11 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "TestEnum", file: !1, line: 8, baseType: !8, size: 32, elements: !12, identifier: ".?AW4TestEnum@@")
!12 = !{!13, !14}
!13 = !DIEnumerator(name: "ENUM_A", value: 2147000000)
!14 = !DIEnumerator(name: "ENUM_B", value: -2147000000)
!15 = !{!4}
!16 = !{!17, !22, !24}
!17 = !DIGlobalVariableExpression(var: !18, expr: !DIExpression(DW_OP_constu, 1078523331, DW_OP_stack_value))
!18 = distinct !DIGlobalVariable(name: "TestConst1", scope: !19, file: !1, line: 2, type: !20, isLocal: true, isDefinition: true)
!19 = !DINamespace(name: "Test1", scope: null)
!20 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !21)
!21 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
!22 = !DIGlobalVariableExpression(var: !23, expr: !DIExpression(DW_OP_constu, 18446744073709551606, DW_OP_stack_value))
!23 = distinct !DIGlobalVariable(name: "TestConst2", scope: !0, file: !1, line: 5, type: !7, isLocal: true, isDefinition: true, declaration: !6)
!24 = !DIGlobalVariableExpression(var: !25, expr: !DIExpression(DW_OP_constu, 18446744071562551616, DW_OP_stack_value))
!25 = distinct !DIGlobalVariable(name: "ENUM_B", scope: !0, file: !1, line: 10, type: !11, isLocal: true, isDefinition: true)
!26 = !{i32 2, !"CodeView", i32 1}
!27 = !{i32 2, !"Debug Info Version", i32 3}
!28 = !{i32 1, !"wchar_size", i32 2}
!29 = !{i32 7, !"PIC Level", i32 2}
!30 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 202f144bffd0be254a829924195e1b8ebabcbb79)"}
!31 = distinct !DISubprogram(name: "foo", linkageName: "?foo@@YAXXZ", scope: !1, file: !1, line: 13, type: !32, scopeLine: 13, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !34)
!32 = !DISubroutineType(types: !33)
!33 = !{null}
!34 = !{}
!35 = !DILocation(line: 14, scope: !31)
!36 = !DILocation(line: 15, scope: !31)
!37 = !DILocation(line: 16, scope: !31)
!38 = !DILocation(line: 17, scope: !31)
!39 = !DILocation(line: 18, scope: !31)
204 changes: 100 additions & 104 deletions llvm/test/DebugInfo/COFF/global_visibility.ll

Large diffs are not rendered by default.

357 changes: 293 additions & 64 deletions llvm/test/DebugInfo/COFF/globals.ll

Large diffs are not rendered by default.

59 changes: 31 additions & 28 deletions llvm/test/DebugInfo/COFF/types-array-unsized.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,22 @@
; We should emit two array types: one used to describe the static data member,
; and the other used by the S_GDATA32 for the definition.

; C++ source:
; // Build with: clang-cl a.cpp /c /Z7 /clang:-S /clang:-emit-llvm
; struct Foo {
; static const char str[];
; };
; const char Foo::str[] = "asdf";
; Foo f; // FIXME: only needed to force emit 'Foo'

; CHECK: CodeViewTypes [
; CHECK: Array ([[ARRAY_COMPLETE:0x.*]]) {
; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
; CHECK-NEXT: ElementType: const char ({{.*}})
; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
; CHECK-NEXT: SizeOf: 5
; CHECK-NEXT: Name:
; CHECK-NEXT: }
; CHECK: Array ([[ARRAY_FWD:0x.*]]) {
; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
; CHECK-NEXT: ElementType: const char ({{.*}})
; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
; CHECK-NEXT: SizeOf: 0
; CHECK-NEXT: Name:
; CHECK-NEXT: }
; CHECK: FieldList (0x1004) {
; CHECK: FieldList (0x1003) {
; CHECK-NEXT: TypeLeafKind: LF_FIELDLIST (0x1203)
; CHECK-NEXT: StaticDataMember {
; CHECK-NEXT: TypeLeafKind: LF_STMEMBER (0x150E)
Expand All @@ -35,39 +28,47 @@
; CHECK-NEXT: Name: str
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK: Array ([[ARRAY_COMPLETE:0x.*]]) {
; CHECK-NEXT: TypeLeafKind: LF_ARRAY (0x1503)
; CHECK-NEXT: ElementType: const char ({{.*}})
; CHECK-NEXT: IndexType: unsigned __int64 (0x23)
; CHECK-NEXT: SizeOf: 5
; CHECK-NEXT: Name:
; CHECK-NEXT: }
; CHECK: ]

; CHECK: GlobalData {
; CHECK-NEXT: Kind: S_GDATA32 (0x110D)
; CHECK-NEXT: DataOffset: ?str@Foo@@2QBDB+0x0
; CHECK-NEXT: Type: [[ARRAY_COMPLETE]]
; CHECK-NEXT: DisplayName: str
; CHECK-NEXT: DisplayName: Foo::str
; CHECK-NEXT: LinkageName: ?str@Foo@@2QBDB
; CHECK-NEXT: }

; ModuleID = 't.cpp'
source_filename = "t.cpp"
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.0.24215"
; ModuleID = 'a.cpp'
source_filename = "a.cpp"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.25.28614"

%struct.Foo = type { i8 }

@"\01?str@Foo@@2QBDB" = constant [5 x i8] c"asdf\00", align 1, !dbg !0
@"\01?f@@3UFoo@@A" = global %struct.Foo zeroinitializer, align 1, !dbg !6
@"?str@Foo@@2QBDB" = dso_local constant [5 x i8] c"asdf\00", align 1, !dbg !0
@"?f@@3UFoo@@A" = dso_local global %struct.Foo zeroinitializer, align 1, !dbg !6

!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!19, !20, !21, !22}
!llvm.ident = !{!23}
!llvm.linker.options = !{!19, !20}
!llvm.module.flags = !{!21, !22, !23, !24}
!llvm.ident = !{!25}

!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "str", linkageName: "\01?str@Foo@@2QBDB", scope: !2, file: !3, line: 4, type: !16, isLocal: false, isDefinition: true, declaration: !10)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 6.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
!3 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "15aa843c5a80301928caf03e71f87a54")
!1 = distinct !DIGlobalVariable(name: "str", linkageName: "?str@Foo@@2QBDB", scope: !2, file: !3, line: 4, type: !16, isLocal: false, isDefinition: true, declaration: !10)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 202f144bffd0be254a829924195e1b8ebabcbb79)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
!3 = !DIFile(filename: "a.cpp", directory: "F:\\llvm-project\\__test", checksumkind: CSK_MD5, checksum: "c2b2d28fd8aaa040c4141cea420d0648")
!4 = !{}
!5 = !{!0, !6}
!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
!7 = distinct !DIGlobalVariable(name: "f", linkageName: "\01?f@@3UFoo@@A", scope: !2, file: !3, line: 5, type: !8, isLocal: false, isDefinition: true)
!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !3, line: 1, size: 8, elements: !9, identifier: ".?AUFoo@@")
!7 = distinct !DIGlobalVariable(name: "f", linkageName: "?f@@3UFoo@@A", scope: !2, file: !3, line: 5, type: !8, isLocal: false, isDefinition: true)
!8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", file: !3, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !9, identifier: ".?AUFoo@@")
!9 = !{!10}
!10 = !DIDerivedType(tag: DW_TAG_member, name: "str", scope: !8, file: !3, line: 2, baseType: !11, flags: DIFlagStaticMember)
!11 = !DICompositeType(tag: DW_TAG_array_type, baseType: !12, elements: !14)
Expand All @@ -78,8 +79,10 @@ target triple = "x86_64-pc-windows-msvc19.0.24215"
!16 = !DICompositeType(tag: DW_TAG_array_type, baseType: !12, size: 40, elements: !17)
!17 = !{!18}
!18 = !DISubrange(count: 5)
!19 = !{i32 2, !"CodeView", i32 1}
!20 = !{i32 2, !"Debug Info Version", i32 3}
!21 = !{i32 1, !"wchar_size", i32 2}
!22 = !{i32 7, !"PIC Level", i32 2}
!23 = !{!"clang version 6.0.0 "}
!19 = !{!"/DEFAULTLIB:libcmt.lib"}
!20 = !{!"/DEFAULTLIB:oldnames.lib"}
!21 = !{i32 2, !"CodeView", i32 1}
!22 = !{i32 2, !"Debug Info Version", i32 3}
!23 = !{i32 1, !"wchar_size", i32 2}
!24 = !{i32 7, !"PIC Level", i32 2}
!25 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 202f144bffd0be254a829924195e1b8ebabcbb79)"}
80 changes: 80 additions & 0 deletions llvm/test/DebugInfo/COFF/udts-fixpoint.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
; RUN: llc %s -o - | FileCheck %s

; This test case caused UDTs to be discovered during UDT emission, which can
; cause iterator invalidation.

; Based on this C++:
; typedef int a;
; struct b;
; class c {
; c();
; a b::*d;
; };
; c::c() = default;

; Previously there was an issue were the "a" typedef would be emitted twice.
; Check that there are only two typedefs, a and c.
; CHECK: .short 4360 # Record kind: S_UDT
; CHECK: .long {{.*}} # Type
; CHECK: .asciz "a"
; CHECK: .p2align 2
; CHECK: .short 4360 # Record kind: S_UDT
; CHECK: .long {{.*}} # Type
; CHECK: .asciz "c"
; CHECK: .p2align 2
; No other S_UDTs.
; CHECK-NOT: S_UDT
; CHECK: .cv_filechecksums


; ModuleID = 't.cpp'
source_filename = "t.cpp"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.16.0"

%class.c = type { { i32, i32, i32 } }

; Function Attrs: noinline nounwind optnone
define dso_local %class.c* @"??0c@@AEAA@XZ"(%class.c* returned %this) unnamed_addr #0 align 2 !dbg !7 {
entry:
%this.addr = alloca %class.c*, align 8
store %class.c* %this, %class.c** %this.addr, align 8
call void @llvm.dbg.declare(metadata %class.c** %this.addr, metadata !20, metadata !DIExpression()), !dbg !22
%this1 = load %class.c*, %class.c** %this.addr, align 8
ret %class.c* %this1, !dbg !23
}

; Function Attrs: nounwind readnone speculatable willreturn
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1

attributes #0 = { noinline nounwind optnone }
attributes #1 = { nounwind readnone speculatable willreturn }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
!1 = !DIFile(filename: "<stdin>", directory: "C:/src/llvm-project/build", checksumkind: CSK_MD5, checksum: "4cbca1b19718cc292886f5df0b72cf37")
!2 = !{}
!3 = !{i32 2, !"CodeView", i32 1}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 2}
!6 = !{!"clang version 11.0.0 "}
!7 = distinct !DISubprogram(name: "c", linkageName: "??0c@@AEAA@XZ", scope: !9, file: !8, line: 7, type: !17, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, declaration: !16, retainedNodes: !2)
!8 = !DIFile(filename: "t.cpp", directory: "C:/src/llvm-project/build", checksumkind: CSK_MD5, checksum: "4cbca1b19718cc292886f5df0b72cf37")
!9 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "c", file: !8, line: 3, size: 96, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !10, identifier: ".?AVc@@")
!10 = !{!11, !16}
!11 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !9, file: !8, line: 5, baseType: !12, size: 96)
!12 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !13, size: 96, extraData: !15)
!13 = !DIDerivedType(tag: DW_TAG_typedef, name: "a", file: !8, line: 1, baseType: !14)
!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!15 = !DICompositeType(tag: DW_TAG_structure_type, name: "b", file: !8, line: 2, flags: DIFlagFwdDecl | DIFlagNonTrivial, identifier: ".?AUb@@")
!16 = !DISubprogram(name: "c", scope: !9, file: !8, line: 4, type: !17, scopeLine: 4, flags: DIFlagPrototyped, spFlags: 0)
!17 = !DISubroutineType(types: !18)
!18 = !{null, !19}
!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!20 = !DILocalVariable(name: "this", arg: 1, scope: !7, type: !21, flags: DIFlagArtificial | DIFlagObjectPointer)
!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
!22 = !DILocation(line: 0, scope: !7)
!23 = !DILocation(line: 7, scope: !7)