1; RUN: %llc_dwarf -O2  -dwarf-version 2 -filetype=obj < %s | llvm-dwarfdump - | FileCheck %s  --check-prefix=DWARF23
2; RUN: %llc_dwarf -O2  -dwarf-version 3 -filetype=obj < %s | llvm-dwarfdump - | FileCheck %s  --check-prefix=DWARF23
3; RUN: %llc_dwarf -O2  -dwarf-version 4 -filetype=obj < %s | llvm-dwarfdump - | FileCheck %s  --check-prefix=DWARF4
4
5; This is a test for PR21176.
6; DW_OP_const <const> doesn't describe a constant value, but a value at a constant address.
7; The proper way to describe a constant value is DW_OP_constu <const>, DW_OP_stack_value.
8; For values < 32 we emit the canonical DW_OP_lit<const>.
9
10; Generated with clang -S -emit-llvm -g -O2 test.cpp
11
12; extern int func();
13;
14; int main()
15; {
16;   volatile int c = 13;
17;   c = func();
18;   return c;
19; }
20
21; CHECK: DW_TAG_variable
22; CHECK: DW_AT_location
23; CHECK-NOT: DW_AT
24; DWARF23: DW_OP_lit13{{$}}
25; DWARF4: DW_OP_lit13, DW_OP_stack_value{{$}}
26
27; Function Attrs: uwtable
28define i32 @main() #0 !dbg !4 {
29entry:
30  %c = alloca i32, align 4
31  tail call void @llvm.dbg.value(metadata i32 13, metadata !10, metadata !16), !dbg !17
32  store volatile i32 13, i32* %c, align 4, !dbg !18
33  %call = tail call i32 @_Z4funcv(), !dbg !19
34  tail call void @llvm.dbg.value(metadata i32 %call, metadata !10, metadata !16), !dbg !17
35  store volatile i32 %call, i32* %c, align 4, !dbg !19
36  tail call void @llvm.dbg.value(metadata i32* %c, metadata !10, metadata !21), !dbg !17
37  %c.0.c.0. = load volatile i32, i32* %c, align 4, !dbg !20
38  ret i32 %c.0.c.0., !dbg !20
39}
40
41declare i32 @_Z4funcv() #1
42
43; Function Attrs: nounwind readnone
44declare void @llvm.dbg.value(metadata, metadata, metadata) #2
45
46attributes #0 = { uwtable "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
47attributes #1 = { "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
48attributes #2 = { nounwind readnone }
49
50!llvm.dbg.cu = !{!0}
51!llvm.module.flags = !{!12, !13}
52!llvm.ident = !{!14}
53
54!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 (trunk 223522)", isOptimized: true, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
55!1 = !DIFile(filename: "test.cpp", directory: "/home/kromanova/ngh/ToT_latest/llvm/test/DebugInfo")
56!2 = !{}
57!4 = distinct !DISubprogram(name: "main", line: 3, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 4, file: !1, scope: !5, type: !6, retainedNodes: !9)
58!5 = !DIFile(filename: "test.cpp", directory: "/home/kromanova/ngh/ToT_latest/llvm/test/DebugInfo")
59!6 = !DISubroutineType(types: !7)
60!7 = !{!8}
61!8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
62!9 = !{!10}
63!10 = !DILocalVariable(name: "c", line: 5, scope: !4, file: !5, type: !11)
64!11 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !8)
65!12 = !{i32 2, !"Dwarf Version", i32 2}
66!13 = !{i32 2, !"Debug Info Version", i32 3}
67!14 = !{!"clang version 3.6.0 (trunk 223522)"}
68!15 = !{i32 13}
69!16 = !DIExpression()
70!17 = !DILocation(line: 5, column: 16, scope: !4)
71!18 = !DILocation(line: 5, column: 3, scope: !4)
72!19 = !DILocation(line: 6, column: 7, scope: !4)
73!20 = !DILocation(line: 7, column: 3, scope: !4)
74!21 = !DIExpression(DW_OP_deref)
75
76