1; RUN: opt -S -asan -enable-new-pm=0 %s | FileCheck %s
2; RUN: opt -S -passes=asan-function-pipeline %s | FileCheck %s
3
4; The IR of this testcase is generated from the following C code:
5; void bar (int);
6;
7; void foo() {
8;   __block int x;
9;   bar(x);
10; }
11; by compiling it with 'clang -emit-llvm -g -S' and then by manually
12; adding the sanitize_address attribute to the @foo() function (so
13; that ASAN accepts to instrument the function in the above opt run).
14
15; Check that the location of the ASAN instrumented __block variable is
16; correct.
17; CHECK: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 32, DW_OP_plus_uconst, 8, DW_OP_deref, DW_OP_plus_uconst, 24)
18
19target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
20
21%struct.__block_byref_x = type { i8*, %struct.__block_byref_x*, i32, i32, i32 }
22
23; Function Attrs: nounwind ssp uwtable
24define void @foo() #0 !dbg !4 {
25entry:
26  %x = alloca %struct.__block_byref_x, align 8
27  call void @llvm.dbg.declare(metadata %struct.__block_byref_x* %x, metadata !12, metadata !22), !dbg !23
28  %byref.isa = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 0, !dbg !24
29  store i8* null, i8** %byref.isa, !dbg !24
30  %byref.forwarding = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !24
31  store %struct.__block_byref_x* %x, %struct.__block_byref_x** %byref.forwarding, !dbg !24
32  %byref.flags = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 2, !dbg !24
33  store i32 0, i32* %byref.flags, !dbg !24
34  %byref.size = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 3, !dbg !24
35  store i32 32, i32* %byref.size, !dbg !24
36  %forwarding = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !25
37  %0 = load %struct.__block_byref_x*, %struct.__block_byref_x** %forwarding, !dbg !25
38  %x1 = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %0, i32 0, i32 4, !dbg !25
39  %1 = load i32, i32* %x1, align 4, !dbg !25
40  call void @bar(i32 %1), !dbg !25
41  %2 = bitcast %struct.__block_byref_x* %x to i8*, !dbg !26
42  call void @_Block_object_dispose(i8* %2, i32 8) #3, !dbg !26
43  ret void, !dbg !26
44}
45
46; Function Attrs: nounwind readnone
47declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
48
49declare void @bar(i32) #2
50
51declare void @_Block_object_dispose(i8*, i32)
52
53attributes #0 = { nounwind ssp uwtable sanitize_address "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
54attributes #1 = { nounwind readnone }
55attributes #2 = { "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
56attributes #3 = { nounwind }
57
58!llvm.dbg.cu = !{!0}
59!llvm.module.flags = !{!8, !9, !10}
60!llvm.ident = !{!11}
61
62!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
63!1 = !DIFile(filename: "block.c", directory: "/tmp")
64!2 = !{}
65!4 = distinct !DISubprogram(name: "foo", line: 3, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, retainedNodes: !2)
66!5 = !DIFile(filename: "block.c", directory: "/tmp")
67!6 = !DISubroutineType(types: !7)
68!7 = !{null}
69!8 = !{i32 2, !"Dwarf Version", i32 2}
70!9 = !{i32 2, !"Debug Info Version", i32 3}
71!10 = !{i32 1, !"PIC Level", i32 2}
72!11 = !{!"clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)"}
73!12 = !DILocalVariable(name: "x", line: 4, scope: !4, file: !5, type: !13)
74!13 = !DICompositeType(tag: DW_TAG_structure_type, size: 224, file: !1, scope: !5, elements: !14)
75!14 = !{!15, !17, !18, !20, !21}
76!15 = !DIDerivedType(tag: DW_TAG_member, name: "__isa", size: 64, align: 64, file: !1, scope: !5, baseType: !16)
77!16 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: null)
78!17 = !DIDerivedType(tag: DW_TAG_member, name: "__forwarding", size: 64, align: 64, offset: 64, file: !1, scope: !5, baseType: !16)
79!18 = !DIDerivedType(tag: DW_TAG_member, name: "__flags", size: 32, align: 32, offset: 128, file: !1, scope: !5, baseType: !19)
80!19 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
81!20 = !DIDerivedType(tag: DW_TAG_member, name: "__size", size: 32, align: 32, offset: 160, file: !1, scope: !5, baseType: !19)
82!21 = !DIDerivedType(tag: DW_TAG_member, name: "x", size: 32, align: 32, offset: 192, file: !1, scope: !5, baseType: !19)
83!22 = !DIExpression(DW_OP_plus_uconst, 8, DW_OP_deref, DW_OP_plus_uconst, 24)
84!23 = !DILocation(line: 4, column: 15, scope: !4)
85!24 = !DILocation(line: 4, column: 3, scope: !4)
86!25 = !DILocation(line: 5, column: 3, scope: !4)
87!26 = !DILocation(line: 6, column: 1, scope: !4)
88