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