• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc %s -o %t.s
2; RUN: llvm-mc %t.s -filetype=obj -triple=x86_64-windows-msvc -o %t.o
3; RUN: FileCheck %s < %t.s --check-prefix=ASM
4; RUN: llvm-dwarfdump %t.o | FileCheck %s --check-prefix=DWARF
5
6; In this example, the variable lives mostly in memory, but at the point of the
7; assignment to global, it lives nowhere, and is described as the constant
8; value 1.
9
10; C source:
11;
12; void escape(int *);
13; extern int global;
14; void f(int x) {
15;   escape(&x);
16;   x = 1; // DSE should delete and insert dbg.value(i32 1)
17;   global = x;
18;   x = 2; // DSE should insert dbg.addr
19;   escape(&x);
20; }
21
22; ModuleID = 'dse.c'
23source_filename = "dse.c"
24target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
25target triple = "x86_64-pc-windows-msvc19.0.24215"
26
27declare void @llvm.dbg.addr(metadata, metadata, metadata) #2
28declare void @llvm.dbg.value(metadata, metadata, metadata) #2
29declare void @escape(i32*)
30
31@global = external global i32, align 4
32
33; Function Attrs: nounwind uwtable
34define void @f(i32 %x) #0 !dbg !8 {
35entry:
36  %x.addr = alloca i32, align 4
37  store i32 %x, i32* %x.addr, align 4
38  call void @llvm.dbg.addr(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !18
39  call void @escape(i32* %x.addr), !dbg !19
40  call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression()), !dbg !20
41  store i32 1, i32* @global, align 4, !dbg !22
42  call void @llvm.dbg.addr(metadata i32* %x.addr, metadata !13, metadata !DIExpression()), !dbg !23
43  store i32 2, i32* %x.addr, align 4, !dbg !23
44  call void @escape(i32* %x.addr), !dbg !24
45  ret void, !dbg !25
46}
47
48; ASM-LABEL: f: # @f
49; ASM: movl    %ecx, [[OFF_X:[0-9]+]](%rsp)
50; ASM: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[OFF_X]]] [$rsp+0]
51; ASM: callq   escape
52; ASM: #DEBUG_VALUE: f:x <- 1
53; ASM: movl    $1, global(%rip)
54; FIXME: Needs a fix to LiveDebugVariables
55; ASMX: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[OFF_X]]] [$rsp+0]
56; ASM: movl    $2, [[OFF_X]](%rsp)
57; ASM: callq   escape
58; ASM: retq
59
60; DWARF:      DW_TAG_formal_parameter
61; DWARF-NEXT:   DW_AT_location        (0x00000000
62; DWARF-NEXT:      {{[^:]*}}: DW_OP_breg7 RSP+{{[0-9]+}}
63; DWARF-NEXT:      {{[^:]*}}: DW_OP_consts +1, DW_OP_stack_value
64; DWARF-NEXT:      {{[^:]*}}: DW_OP_breg7 RSP+{{[0-9]+}})
65; DWARF-NEXT:   DW_AT_name    ("x")
66
67attributes #0 = { nounwind uwtable }
68attributes #2 = { nounwind readnone speculatable }
69
70!llvm.dbg.cu = !{!0}
71!llvm.module.flags = !{!3, !4, !5, !6}
72!llvm.ident = !{!7}
73
74!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
75!1 = !DIFile(filename: "dse.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
76!2 = !{}
77!3 = !{i32 2, !"Dwarf Version", i32 4}
78!4 = !{i32 2, !"Debug Info Version", i32 3}
79!5 = !{i32 1, !"wchar_size", i32 2}
80!6 = !{i32 7, !"PIC Level", i32 2}
81!7 = !{!"clang version 6.0.0 "}
82!8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3, type: !9, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
83!9 = !DISubroutineType(types: !10)
84!10 = !{null, !11}
85!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
86!12 = !{!13}
87!13 = !DILocalVariable(name: "x", arg: 1, scope: !8, file: !1, line: 3, type: !11)
88!14 = !{!15, !15, i64 0}
89!15 = !{!"int", !16, i64 0}
90!16 = !{!"omnipotent char", !17, i64 0}
91!17 = !{!"Simple C/C++ TBAA"}
92!18 = !DILocation(line: 3, column: 12, scope: !8)
93!19 = !DILocation(line: 4, column: 3, scope: !8)
94!20 = !DILocation(line: 5, column: 5, scope: !8)
95!21 = !DILocation(line: 6, column: 12, scope: !8)
96!22 = !DILocation(line: 6, column: 10, scope: !8)
97!23 = !DILocation(line: 7, column: 5, scope: !8)
98!24 = !DILocation(line: 8, column: 3, scope: !8)
99!25 = !DILocation(line: 9, column: 1, scope: !8)
100