1; RUN: llc -mtriple=x86_64-apple-darwin %s -o - -filetype=obj | llvm-dwarfdump - | FileCheck %s
2; CHECK: 0x00000[[G:.*]]:     DW_TAG_variable
3; CHECK-NEXT:                DW_AT_name	("g")
4; CHECK: DW_TAG_array_type
5; CHECK-NEXT:  DW_AT_type	({{.*}} "int")
6; CHECK-NOT: DW_TAG
7; CHECK:       DW_TAG_subrange_type
8; CHECK-NEXT:     DW_AT_type	({{.*}} "__ARRAY_SIZE_TYPE__")
9; CHECK-NEXT:      DW_AT_count	(0x00000[[G]])
10; Test that a VLA referring to a global variable is handled correctly.
11; Clang doesn't generate this, but the verifier allows it.
12source_filename = "/tmp/test.c"
13target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
14target triple = "x86_64-apple-macosx10.13.0"
15
16@g = common local_unnamed_addr global i32 0, align 4, !dbg !0
17
18define void @f() !dbg !12 {
19entry:
20  %0 = load i32, i32* @g, align 4, !dbg !22
21  %1 = zext i32 %0 to i64, !dbg !22
22  %vla = alloca i32, i64 %1, align 16, !dbg !22
23  call void @llvm.dbg.declare(metadata i32* %vla, metadata !16, metadata !DIExpression()), !dbg !22
24  call void @llvm.dbg.value(metadata i32 2, metadata !21, metadata !DIExpression()), !dbg !22
25  %call = call i32 (i32*, ...) bitcast (i32 (...)* @use to i32 (i32*, ...)*)(i32* nonnull %vla), !dbg !22
26  ret void, !dbg !22
27}
28
29; Function Attrs: nounwind readnone speculatable
30declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
31
32declare i32 @use(...) local_unnamed_addr
33
34; Function Attrs: nounwind readnone speculatable
35declare void @llvm.dbg.value(metadata, metadata, metadata) #0
36
37attributes #0 = { nounwind readnone speculatable }
38
39!llvm.dbg.cu = !{!2}
40!llvm.module.flags = !{!7, !8, !9, !10}
41!llvm.ident = !{!11}
42
43!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
44!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
45!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 324259) (llvm/trunk 324261)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
46!3 = !DIFile(filename: "/tmp/test.c", directory: "/")
47!4 = !{}
48!5 = !{!0}
49!6 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
50!7 = !{i32 2, !"Dwarf Version", i32 4}
51!8 = !{i32 2, !"Debug Info Version", i32 3}
52!9 = !{i32 1, !"wchar_size", i32 4}
53!10 = !{i32 7, !"PIC Level", i32 2}
54!11 = !{!"clang version 7.0.0 (trunk 324259) (llvm/trunk 324261)"}
55!12 = distinct !DISubprogram(name: "f", scope: !3, file: !3, line: 3, type: !13, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !2, retainedNodes: !15)
56!13 = !DISubroutineType(types: !14)
57!14 = !{null}
58!15 = !{!16, !21}
59!16 = !DILocalVariable(name: "array", scope: !12, file: !3, line: 4, type: !17)
60!17 = !DICompositeType(tag: DW_TAG_array_type, baseType: !18, elements: !19)
61!18 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
62!19 = !{!20}
63!20 = !DISubrange(count: !1)
64!21 = !DILocalVariable(name: "count", scope: !12, file: !3, line: 5, type: !18)
65!22 = !DILocation(line: 7, column: 1, scope: !12)
66