1; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
2; RUN: llc < %s | llvm-mc -filetype=obj --triple=i686-windows | llvm-readobj - --codeview | FileCheck %s
3;
4; Verify lambda routines are emitted properly in CodeView.
5;
6; The original source code:
7; -----------------------------------------------------------------------------
8; int main(int argc, char* argv[], char* arge[]) {
9;   auto Lambda = [argc](int count) -> int { return argc == count ? 1 : 0; };
10;   return Lambda(0);
11; }
12; -----------------------------------------------------------------------------
13;
14; To regenerate the IR below compile the source code:
15;   $ clang lambda.cxx -S -emit-llvm -g -gcodeview
16;
17; CHECK:      FieldList ([[FIELDLIST_ID:0x[0-9A-F]+]]) {
18; CHECK-NEXT:   TypeLeafKind: LF_FIELDLIST ({{.*}})
19; CHECK-NEXT:   DataMember {
20; CHECK-NEXT:     TypeLeafKind: LF_MEMBER ({{.*}})
21; CHECK-NEXT:     AccessSpecifier: Private ({{.*}})
22; CHECK-NEXT:     Type: int ({{.*}})
23; CHECK-NEXT:     FieldOffset: {{.*}}
24; CHECK-NEXT:     Name: argc
25; CHECK-NEXT:   }
26; CHECK-NEXT:   OneMethod {
27; CHECK-NEXT:     TypeLeafKind: LF_ONEMETHOD (0x1511)
28; CHECK-NEXT:     AccessSpecifier: Public (0x3)
29; CHECK-NEXT:     Type: int main::<unnamed-tag>::(int) ({{.*}})
30; CHECK-NEXT:     Name: operator()
31; CHECK-NEXT:   }
32; CHECK-NEXT: }
33; CHECK-NEXT: Class ([[CLASS_ID:0x[0-9A-F]+]]) {
34; CHECK-NEXT:   TypeLeafKind: LF_CLASS ({{.*}})
35; CHECK-NEXT:   MemberCount: {{.*}}
36; CHECK-NEXT:   Properties [ ({{.*}})
37; CHECK-NEXT:     HasUniqueName ({{.*}})
38; CHECK-NEXT:     Scoped ({{.*}})
39; CHECK-NEXT:   ]
40; CHECK-NEXT:   FieldList: <field list> ([[FIELDLIST_ID]])
41; CHECK-NEXT:   DerivedFrom: {{.*}}
42; CHECK-NEXT:   VShape: {{.*}}
43; CHECK-NEXT:   SizeOf: {{.*}}
44; CHECK-NEXT:   Name: main::<unnamed-tag>
45; CHECK-NEXT:   LinkageName: {{.*lambda.*}}
46; CHECK-NEXT: }
47;             LocalSym {
48;               Kind: S_LOCAL ({{.*}})
49; CHECK:        Type: main::<unnamed-tag> ([[CLASS_ID]])
50;               Flags [ (0x0)
51;               ]
52; CHECK:        VarName: Lambda
53;             }
54
55; ModuleID = 'lambda.cxx'
56source_filename = "lambda.cxx"
57target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
58target triple = "i686-pc-windows-msvc19.0.24210"
59
60%class.anon = type { i32 }
61
62; Function Attrs: noinline norecurse optnone
63define dso_local i32 @main(i32 %argc, i8** %argv, i8** %arge) #0 !dbg !8 {
64entry:
65  %retval = alloca i32, align 4
66  %arge.addr = alloca i8**, align 4
67  %argv.addr = alloca i8**, align 4
68  %argc.addr = alloca i32, align 4
69  %Lambda = alloca %class.anon, align 4
70  store i32 0, i32* %retval, align 4
71  store i8** %arge, i8*** %arge.addr, align 4
72  call void @llvm.dbg.declare(metadata i8*** %arge.addr, metadata !15, metadata !DIExpression()), !dbg !16
73  store i8** %argv, i8*** %argv.addr, align 4
74  call void @llvm.dbg.declare(metadata i8*** %argv.addr, metadata !17, metadata !DIExpression()), !dbg !16
75  store i32 %argc, i32* %argc.addr, align 4
76  call void @llvm.dbg.declare(metadata i32* %argc.addr, metadata !18, metadata !DIExpression()), !dbg !16
77  call void @llvm.dbg.declare(metadata %class.anon* %Lambda, metadata !19, metadata !DIExpression()), !dbg !28
78  %0 = getelementptr inbounds %class.anon, %class.anon* %Lambda, i32 0, i32 0, !dbg !28
79  %1 = load i32, i32* %argc.addr, align 4, !dbg !28
80  store i32 %1, i32* %0, align 4, !dbg !28
81  %call = call x86_thiscallcc i32 @"??R<lambda_0>@?0??main@@9@QBE@H@Z"(%class.anon* %Lambda, i32 0), !dbg !29
82  ret i32 %call, !dbg !29
83}
84
85; Function Attrs: nounwind readnone speculatable
86declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
87
88; Function Attrs: noinline nounwind optnone
89define internal x86_thiscallcc i32 @"??R<lambda_0>@?0??main@@9@QBE@H@Z"(%class.anon* %this, i32 %count) #2 align 2 !dbg !30 {
90entry:
91  %count.addr = alloca i32, align 4
92  %this.addr = alloca %class.anon*, align 4
93  store i32 %count, i32* %count.addr, align 4
94  call void @llvm.dbg.declare(metadata i32* %count.addr, metadata !31, metadata !DIExpression()), !dbg !32
95  store %class.anon* %this, %class.anon** %this.addr, align 4
96  call void @llvm.dbg.declare(metadata %class.anon** %this.addr, metadata !33, metadata !DIExpression()), !dbg !35
97  %this1 = load %class.anon*, %class.anon** %this.addr, align 4
98  %0 = getelementptr inbounds %class.anon, %class.anon* %this1, i32 0, i32 0, !dbg !32
99  %1 = load i32, i32* %0, align 4, !dbg !32
100  %2 = load i32, i32* %count.addr, align 4, !dbg !32
101  %cmp = icmp eq i32 %1, %2, !dbg !32
102  %3 = zext i1 %cmp to i64, !dbg !32
103  %cond = select i1 %cmp, i32 1, i32 0, !dbg !32
104  ret i32 %cond, !dbg !32
105}
106
107attributes #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" }
108attributes #1 = { nounwind readnone speculatable }
109attributes #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" }
110
111!llvm.dbg.cu = !{!0}
112!llvm.module.flags = !{!3, !4, !5, !6}
113!llvm.ident = !{!7}
114
115!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)
116!1 = !DIFile(filename: "lambda.cxx", directory: "C:\5Cpath\5Cto", checksumkind: CSK_MD5, checksum: "8d860c432e3763effaf1658460a496c0")
117!2 = !{}
118!3 = !{i32 1, !"NumRegisterParameters", i32 0}
119!4 = !{i32 2, !"CodeView", i32 1}
120!5 = !{i32 2, !"Debug Info Version", i32 3}
121!6 = !{i32 1, !"wchar_size", i32 2}
122!7 = !{!"clang version 7.0.0 (trunk)"}
123!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)
124!9 = !DISubroutineType(types: !10)
125!10 = !{!11, !11, !12, !12}
126!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
127!12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 32)
128!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 32)
129!14 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
130!15 = !DILocalVariable(name: "arge", arg: 3, scope: !8, file: !1, line: 1, type: !12)
131!16 = !DILocation(line: 1, scope: !8)
132!17 = !DILocalVariable(name: "argv", arg: 2, scope: !8, file: !1, line: 1, type: !12)
133!18 = !DILocalVariable(name: "argc", arg: 1, scope: !8, file: !1, line: 1, type: !11)
134!19 = !DILocalVariable(name: "Lambda", scope: !8, file: !1, line: 2, type: !20)
135!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@QBE@H@Z")
136!21 = !{!22, !23}
137!22 = !DIDerivedType(tag: DW_TAG_member, name: "argc", scope: !20, file: !1, line: 2, baseType: !11, size: 32)
138!23 = !DISubprogram(name: "operator()", scope: !20, file: !1, line: 2, type: !24, isLocal: false, isDefinition: false, scopeLine: 2, flags: DIFlagPublic | DIFlagPrototyped, isOptimized: false)
139!24 = !DISubroutineType(cc: DW_CC_BORLAND_thiscall, types: !25)
140!25 = !{!11, !26, !11}
141!26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !27, size: 32, flags: DIFlagArtificial | DIFlagObjectPointer)
142!27 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !20)
143!28 = !DILocation(line: 2, scope: !8)
144!29 = !DILocation(line: 3, scope: !8)
145!30 = distinct !DISubprogram(name: "operator()", linkageName: "??R<lambda_0>@?0??main@@9@QBE@H@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)
146!31 = !DILocalVariable(name: "count", arg: 2, scope: !30, file: !1, line: 2, type: !11)
147!32 = !DILocation(line: 2, scope: !30)
148!33 = !DILocalVariable(name: "this", arg: 1, scope: !30, type: !34, flags: DIFlagArtificial | DIFlagObjectPointer)
149!34 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !27, size: 32)
150!35 = !DILocation(line: 0, scope: !30)
151