1 ; RUN: llc -O0 -mtriple=x86_64-apple-darwin -filetype=asm %s -o - | FileCheck %s
2 ; RUN: llc -O0 -mtriple=x86_64-apple-darwin -filetype=obj %s -o - | llvm-dwarfdump - --name=a | FileCheck --check-prefix=OBJFILE %s
3 ; REQUIRES: object-emission
5 ; Ensure that we generate an indirect location for the variable length array a.
7 ; CHECK: ##DEBUG_VALUE: vla:a <- [DW_OP_deref] {{\$r[a-z]+}}
8 ; CHECK: DW_OP_breg{{[0-9]}}
10 ; Ensure there's only one level of indirection in the vla location -- it should
11 ; be a memory location. Base register can be any allocatable one; variables are
12 ; filtered by --name arg to llvm-dwarfdump.
14 ; OBJFILE: DW_TAG_variable
15 ; OBJFILE: DW_AT_location
16 ; OBJFILE-NEXT: ): DW_OP_breg{{[0-9]+}} R{{[0-9A-Z]+}}+0)
17 ; OBJFILE: DW_AT_name ("a")
19 ; rdar://problem/13658587
29 ; int main(int argc, char** argv) {
34 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
35 target triple = "x86_64-apple-macosx10.8.0"
37 ; Function Attrs: nounwind ssp uwtable
38 define i32 @vla(i32 %n) nounwind ssp uwtable !dbg !4 {
40 %n.addr = alloca i32, align 4
41 %saved_stack = alloca i8*
42 %cleanup.dest.slot = alloca i32
43 store i32 %n, i32* %n.addr, align 4
44 call void @llvm.dbg.declare(metadata i32* %n.addr, metadata !15, metadata !DIExpression()), !dbg !16
45 %0 = load i32, i32* %n.addr, align 4, !dbg !17
46 %1 = zext i32 %0 to i64, !dbg !17
47 %2 = call i8* @llvm.stacksave(), !dbg !17
48 store i8* %2, i8** %saved_stack, !dbg !17
49 %vla = alloca i32, i64 %1, align 16, !dbg !17
50 call void @llvm.dbg.declare(metadata i32* %vla, metadata !18, metadata !DIExpression()), !dbg !17
51 %arrayidx = getelementptr inbounds i32, i32* %vla, i64 0, !dbg !22
52 store i32 42, i32* %arrayidx, align 4, !dbg !22
53 %3 = load i32, i32* %n.addr, align 4, !dbg !23
54 %sub = sub nsw i32 %3, 1, !dbg !23
55 %idxprom = sext i32 %sub to i64, !dbg !23
56 %arrayidx1 = getelementptr inbounds i32, i32* %vla, i64 %idxprom, !dbg !23
57 %4 = load i32, i32* %arrayidx1, align 4, !dbg !23
58 store i32 1, i32* %cleanup.dest.slot
59 %5 = load i8*, i8** %saved_stack, !dbg !24
60 call void @llvm.stackrestore(i8* %5), !dbg !24
64 ; Function Attrs: nounwind readnone
65 declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
67 ; Function Attrs: nounwind
68 declare i8* @llvm.stacksave() nounwind
70 ; Function Attrs: nounwind
71 declare void @llvm.stackrestore(i8*) nounwind
73 ; Function Attrs: nounwind ssp uwtable
74 define i32 @main(i32 %argc, i8** %argv) nounwind ssp uwtable !dbg !9 {
76 %retval = alloca i32, align 4
77 %argc.addr = alloca i32, align 4
78 %argv.addr = alloca i8**, align 8
79 store i32 0, i32* %retval
80 store i32 %argc, i32* %argc.addr, align 4
81 call void @llvm.dbg.declare(metadata i32* %argc.addr, metadata !25, metadata !DIExpression()), !dbg !26
82 store i8** %argv, i8*** %argv.addr, align 8
83 call void @llvm.dbg.declare(metadata i8*** %argv.addr, metadata !27, metadata !DIExpression()), !dbg !26
84 %0 = load i32, i32* %argc.addr, align 4, !dbg !28
85 %call = call i32 @vla(i32 %0), !dbg !28
86 ret i32 %call, !dbg !28
90 !llvm.module.flags = !{!29}
92 !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.3 ", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
93 !1 = !DIFile(filename: "vla.c", directory: "")
95 !4 = distinct !DISubprogram(name: "vla", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !6, retainedNodes: !2)
96 !5 = !DIFile(filename: "vla.c", directory: "")
97 !6 = !DISubroutineType(types: !7)
99 !8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
100 !9 = distinct !DISubprogram(name: "main", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !5, type: !10, retainedNodes: !2)
101 !10 = !DISubroutineType(types: !11)
103 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !13)
104 !13 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !14)
105 !14 = !DIBasicType(tag: DW_TAG_base_type, name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
106 !15 = !DILocalVariable(name: "n", line: 1, arg: 1, scope: !4, file: !5, type: !8)
107 !16 = !DILocation(line: 1, scope: !4)
108 !17 = !DILocation(line: 2, scope: !4)
109 !18 = !DILocalVariable(name: "a", line: 2, scope: !4, file: !5, type: !19)
110 !19 = !DICompositeType(tag: DW_TAG_array_type, align: 32, baseType: !8, elements: !20)
112 !21 = !DISubrange(count: -1)
113 !22 = !DILocation(line: 3, scope: !4)
114 !23 = !DILocation(line: 4, scope: !4)
115 !24 = !DILocation(line: 5, scope: !4)
116 !25 = !DILocalVariable(name: "argc", line: 7, arg: 1, scope: !9, file: !5, type: !8)
117 !26 = !DILocation(line: 7, scope: !9)
118 !27 = !DILocalVariable(name: "argv", line: 7, arg: 2, scope: !9, file: !5, type: !12)
119 !28 = !DILocation(line: 8, scope: !9)
120 !29 = !{i32 1, !"Debug Info Version", i32 3}