1 ; RUN: llc -O0 -mtriple=x86_64-apple-darwin < %s -filetype=obj \
2 ; RUN: | llvm-dwarfdump -v -debug-info - \
3 ; RUN: | FileCheck %s -check-prefix=CHECK -check-prefix=DWARF4
4 ; RUN: llc -O0 -mtriple=x86_64-apple-darwin < %s -filetype=obj -dwarf-version=3 \
5 ; RUN: | llvm-dwarfdump -v -debug-info - \
6 ; RUN: | FileCheck %s -check-prefix=CHECK -check-prefix=DWARF3
8 ; DWARF4: DW_AT_location [DW_FORM_sec_offset] (0x00000000
9 ; DWARF4-NEXT: {{.*}}: DW_OP_breg1 RDX+0{{$}}
10 ; DWARF4-NEXT: {{.*}}: DW_OP_breg6 RBP-{{[0-9]+}}, DW_OP_deref)
12 ; DWARF3: DW_AT_location [DW_FORM_data4] (0x00000000
13 ; DWARF3-NEXT: {{.*}}: DW_OP_breg1 RDX+0{{$}}
14 ; DWARF3-NEXT: {{.*}}: DW_OP_breg6 RBP-{{[0-9]+}}, DW_OP_deref)
17 ; CHECK: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000067] = "vla")
19 ; Check the DEBUG_VALUE comments for good measure.
20 ; RUN: llc -O0 -mtriple=x86_64-apple-darwin %s -o - -filetype=asm | FileCheck %s -check-prefix=ASM-CHECK
21 ; vla should have a register-indirect address at one point.
22 ; ASM-CHECK: DEBUG_VALUE: vla <- [DW_OP_deref] $rdx
23 ; vla ptr is spilt too, it should have a stack location,
24 ; ASM-CHECK: DEBUG_VALUE: vla <- [DW_OP_constu {{[0-9]+}}, DW_OP_minus, DW_OP_deref] [$rbp+0]
25 ; ASM-CHECK: DW_OP_breg1
27 ; RUN: llvm-as %s -o - | llvm-dis - | FileCheck %s --check-prefix=PRETTY-PRINT
28 ; PRETTY-PRINT: DIExpression()
30 define void @testVLAwithSize(i32 %s) nounwind uwtable ssp !dbg !5 {
32 %s.addr = alloca i32, align 4
33 %saved_stack = alloca i8*
34 %i = alloca i32, align 4
35 store i32 %s, i32* %s.addr, align 4
36 call void @llvm.dbg.declare(metadata i32* %s.addr, metadata !10, metadata !DIExpression()), !dbg !11
37 %0 = load i32, i32* %s.addr, align 4, !dbg !12
38 %1 = zext i32 %0 to i64, !dbg !12
39 %2 = call i8* @llvm.stacksave(), !dbg !12
40 store i8* %2, i8** %saved_stack, !dbg !12
41 %vla = alloca i32, i64 %1, align 16, !dbg !12
42 call void @llvm.dbg.declare(metadata i32* %vla, metadata !14, metadata !30), !dbg !18
43 call void @llvm.dbg.declare(metadata i32* %i, metadata !19, metadata !DIExpression()), !dbg !20
44 store i32 0, i32* %i, align 4, !dbg !21
45 br label %for.cond, !dbg !21
47 for.cond: ; preds = %for.inc, %entry
48 %3 = load i32, i32* %i, align 4, !dbg !21
49 %4 = load i32, i32* %s.addr, align 4, !dbg !21
50 %cmp = icmp slt i32 %3, %4, !dbg !21
51 br i1 %cmp, label %for.body, label %for.end, !dbg !21
53 for.body: ; preds = %for.cond
54 %5 = load i32, i32* %i, align 4, !dbg !23
55 %6 = load i32, i32* %i, align 4, !dbg !23
56 %mul = mul nsw i32 %5, %6, !dbg !23
57 %7 = load i32, i32* %i, align 4, !dbg !23
58 %idxprom = sext i32 %7 to i64, !dbg !23
59 %arrayidx = getelementptr inbounds i32, i32* %vla, i64 %idxprom, !dbg !23
60 store i32 %mul, i32* %arrayidx, align 4, !dbg !23
61 br label %for.inc, !dbg !25
63 for.inc: ; preds = %for.body
64 %8 = load i32, i32* %i, align 4, !dbg !26
65 %inc = add nsw i32 %8, 1, !dbg !26
66 store i32 %inc, i32* %i, align 4, !dbg !26
67 br label %for.cond, !dbg !26
69 for.end: ; preds = %for.cond
70 %9 = load i8*, i8** %saved_stack, !dbg !27
71 call void @llvm.stackrestore(i8* %9), !dbg !27
75 declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
77 declare i8* @llvm.stacksave() nounwind
79 declare void @llvm.stackrestore(i8*) nounwind
82 !llvm.module.flags = !{!29}
84 !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.2 (trunk 156005) (llvm/trunk 156000)", isOptimized: false, emissionKind: FullDebug, file: !28, enums: !1, retainedTypes: !1, globals: !1, imports: !1)
86 !5 = distinct !DISubprogram(name: "testVLAwithSize", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 2, file: !28, scope: !6, type: !7, retainedNodes: !1)
87 !6 = !DIFile(filename: "bar.c", directory: "/Users/echristo/tmp")
88 !7 = !DISubroutineType(types: !8)
90 !9 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
91 !10 = !DILocalVariable(name: "s", line: 1, arg: 1, scope: !5, file: !6, type: !9)
92 !11 = !DILocation(line: 1, column: 26, scope: !5)
93 !12 = !DILocation(line: 3, column: 13, scope: !13)
94 !13 = distinct !DILexicalBlock(line: 2, column: 1, file: !28, scope: !5)
95 !14 = !DILocalVariable(name: "vla", line: 3, scope: !13, file: !6, type: !15)
96 !15 = !DICompositeType(tag: DW_TAG_array_type, align: 32, baseType: !9, elements: !16)
98 !17 = !DISubrange(count: -1)
99 !18 = !DILocation(line: 3, column: 7, scope: !13)
100 !19 = !DILocalVariable(name: "i", line: 4, scope: !13, file: !6, type: !9)
101 !20 = !DILocation(line: 4, column: 7, scope: !13)
102 !21 = !DILocation(line: 5, column: 8, scope: !22)
103 !22 = distinct !DILexicalBlock(line: 5, column: 3, file: !28, scope: !13)
104 !23 = !DILocation(line: 6, column: 5, scope: !24)
105 !24 = distinct !DILexicalBlock(line: 5, column: 27, file: !28, scope: !22)
106 !25 = !DILocation(line: 7, column: 3, scope: !24)
107 !26 = !DILocation(line: 5, column: 22, scope: !22)
108 !27 = !DILocation(line: 8, column: 1, scope: !13)
109 !28 = !DIFile(filename: "bar.c", directory: "/Users/echristo/tmp")
110 !29 = !{i32 1, !"Debug Info Version", i32 3}
111 !30 = !DIExpression()