1; RUN: opt < %s -asan -asan-module -enable-new-pm=0 -asan-use-after-return=0 -S | FileCheck %s
2; RUN: opt < %s -passes='asan-pipeline' -asan-use-after-return=0 -S | FileCheck %s
3
4; Checks that llvm.dbg.declare instructions are updated
5; accordingly as we merge allocas.
6
7target 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"
8target triple = "x86_64-unknown-linux-gnu"
9
10@G = global [32 x i8] zeroinitializer, align 32, !dbg !0, !type !6
11; CHECK: @G = global { [32 x i8], [32 x i8] } zeroinitializer{{(, comdat)?}}, align 32, !dbg !0, !type [[TYPE:![0-9]+]]
12
13define i32 @_Z3zzzi(i32 %p) nounwind uwtable sanitize_address !dbg !12 {
14entry:
15  %p.addr = alloca i32, align 4
16  %r = alloca i32, align 4
17  store volatile i32 %p, i32* %p.addr, align 4
18  call void @llvm.dbg.declare(metadata i32* %p.addr, metadata !17, metadata !DIExpression()), !dbg !18
19  call void @llvm.dbg.declare(metadata i32* %r, metadata !19, metadata !DIExpression()), !dbg !21
20  %0 = load i32, i32* %p.addr, align 4, !dbg !21
21  %add = add nsw i32 %0, 1, !dbg !21
22  store volatile i32 %add, i32* %r, align 4, !dbg !21
23  %1 = load i32, i32* %r, align 4, !dbg !22
24  ret i32 %1, !dbg !22
25}
26
27;   CHECK: define i32 @_Z3zzzi
28;   CHECK: [[MyAlloca:%.*]] = alloca i8, i64 64
29; Note: these dbg.declares used to contain `ptrtoint` operands. The instruction
30; selector would then decline to put the variable in the MachineFunction side
31; table. Check that the dbg.declares have `alloca` operands.
32;   CHECK: call void @llvm.dbg.declare(metadata i8* [[MyAlloca]], metadata ![[ARG_ID:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 32))
33;   CHECK: call void @llvm.dbg.declare(metadata i8* [[MyAlloca]], metadata ![[VAR_ID:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 48))
34
35declare void @llvm.dbg.declare(metadata, metadata, metadata) nounwind readnone
36
37!llvm.dbg.cu = !{!7}
38!llvm.module.flags = !{!24}
39
40!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
41!1 = distinct !DIGlobalVariable(name: "G", type: !2, isLocal: false, isDefinition: true)
42!2 = !DICompositeType(tag: DW_TAG_array_type, baseType: !3, size: 256, elements: !4)
43!3 = !DIBasicType(name: "unsigned char", size: 8, encoding: DW_ATE_unsigned_char)
44!4 = !{!5}
45!5 = !DISubrange(count: 32)
46!6 = !{i64 0, !"G"}
47; CHECK: [[TYPE]] = !{i64 0, !"G"}
48
49!7 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.3 (trunk 169314)", isOptimized: true, emissionKind: FullDebug, file: !23, enums: !8, retainedTypes: !8, globals: !8)
50!8 = !{}
51!12 = distinct !DISubprogram(name: "zzz", linkageName: "_Z3zzzi", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !7, scopeLine: 1, file: !23, scope: !13, type: !14, retainedNodes: !8)
52!13 = !DIFile(filename: "a.cc", directory: "/usr/local/google/llvm_cmake_clang/tmp/debuginfo")
53!14 = !DISubroutineType(types: !15)
54!15 = !{!16, !16}
55!16 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
56!17 = !DILocalVariable(name: "p", line: 1, arg: 1, scope: !12, file: !13, type: !16)
57!18 = !DILocation(line: 1, scope: !12)
58!19 = !DILocalVariable(name: "r", line: 2, scope: !20, file: !13, type: !16)
59
60; Verify that debug descriptors for argument and local variable will be replaced
61; with descriptors that end with OpDeref (encoded as 2).
62;   CHECK: ![[ARG_ID]] = !DILocalVariable(name: "p", arg: 1,{{.*}} line: 1
63;   CHECK: ![[VAR_ID]] = !DILocalVariable(name: "r",{{.*}} line: 2
64; Verify that there are no more variable descriptors.
65;   CHECK-NOT: !DILocalVariable(tag: DW_TAG_arg_variable
66;   CHECK-NOT: !DILocalVariable(tag: DW_TAG_auto_variable
67
68
69!20 = distinct !DILexicalBlock(line: 1, column: 0, file: !23, scope: !12)
70!21 = !DILocation(line: 2, scope: !20)
71!22 = !DILocation(line: 3, scope: !20)
72!23 = !DIFile(filename: "a.cc", directory: "/usr/local/google/llvm_cmake_clang/tmp/debuginfo")
73!24 = !{i32 1, !"Debug Info Version", i32 3}
74