blob: 4c938d9c63f849eaa7dc41f45fac64f8dddcf6bd [file] [log] [blame]
Frederic Riss7c78db52014-12-09 17:55:48 +00001; RUN: opt -S -asan %s | FileCheck %s
2
3; The IR of this testcase is generated from the following C code:
4; void bar (int);
5;
6; void foo() {
7; __block int x;
8; bar(x);
9; }
10; by compiling it with 'clang -emit-llvm -g -S' and then by manually
11; adding the sanitize_address attribute to the @foo() function (so
12; that ASAN accepts to instrument the function in the above opt run).
13
14; Check that the location of the ASAN instrumented __block variable is
15; correct.
16; CHECK: [ DW_TAG_expression ] [DW_OP_deref] [DW_OP_plus 8] [DW_OP_deref] [DW_OP_plus 24]
17
18target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
19
20%struct.__block_byref_x = type { i8*, %struct.__block_byref_x*, i32, i32, i32 }
21
22; Function Attrs: nounwind ssp uwtable
23define void @foo() #0 {
24entry:
25 %x = alloca %struct.__block_byref_x, align 8
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000026 call void @llvm.dbg.declare(metadata %struct.__block_byref_x* %x, metadata !12, metadata !22), !dbg !23
David Blaikie79e6c742015-02-27 19:29:02 +000027 %byref.isa = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 0, !dbg !24
Frederic Riss7c78db52014-12-09 17:55:48 +000028 store i8* null, i8** %byref.isa, !dbg !24
David Blaikie79e6c742015-02-27 19:29:02 +000029 %byref.forwarding = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !24
Frederic Riss7c78db52014-12-09 17:55:48 +000030 store %struct.__block_byref_x* %x, %struct.__block_byref_x** %byref.forwarding, !dbg !24
David Blaikie79e6c742015-02-27 19:29:02 +000031 %byref.flags = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 2, !dbg !24
Frederic Riss7c78db52014-12-09 17:55:48 +000032 store i32 0, i32* %byref.flags, !dbg !24
David Blaikie79e6c742015-02-27 19:29:02 +000033 %byref.size = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 3, !dbg !24
Frederic Riss7c78db52014-12-09 17:55:48 +000034 store i32 32, i32* %byref.size, !dbg !24
David Blaikie79e6c742015-02-27 19:29:02 +000035 %forwarding = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !25
David Blaikiea79ac142015-02-27 21:17:42 +000036 %0 = load %struct.__block_byref_x*, %struct.__block_byref_x** %forwarding, !dbg !25
David Blaikie79e6c742015-02-27 19:29:02 +000037 %x1 = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %0, i32 0, i32 4, !dbg !25
David Blaikiea79ac142015-02-27 21:17:42 +000038 %1 = load i32, i32* %x1, align 4, !dbg !25
Frederic Riss7c78db52014-12-09 17:55:48 +000039 call void @bar(i32 %1), !dbg !25
40 %2 = bitcast %struct.__block_byref_x* %x to i8*, !dbg !26
41 call void @_Block_object_dispose(i8* %2, i32 8) #3, !dbg !26
42 ret void, !dbg !26
43}
44
45; Function Attrs: nounwind readnone
46declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
47
48declare void @bar(i32) #2
49
50declare void @_Block_object_dispose(i8*, i32)
51
52attributes #0 = { nounwind ssp uwtable sanitize_address "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
53attributes #1 = { nounwind readnone }
54attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
55attributes #3 = { nounwind }
56
57!llvm.dbg.cu = !{!0}
58!llvm.module.flags = !{!8, !9, !10}
59!llvm.ident = !{!11}
60
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000061!0 = !{!"0x11\0012\00clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)\000\00\000\00\001", !1, !2, !2, !3, !2, !2} ; [ DW_TAG_compile_unit ] [/tmp/block.c] [DW_LANG_C99]
62!1 = !{!"block.c", !"/tmp"}
63!2 = !{}
64!3 = !{!4}
65!4 = !{!"0x2e\00foo\00foo\00\003\000\001\000\000\000\000\003", !1, !5, !6, null, void ()* @foo, null, null, !2} ; [ DW_TAG_subprogram ] [line 3] [def] [foo]
66!5 = !{!"0x29", !1} ; [ DW_TAG_file_type ] [/tmp/block.c]
67!6 = !{!"0x15\00\000\000\000\000\000\000", null, null, null, !7, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
68!7 = !{null}
69!8 = !{i32 2, !"Dwarf Version", i32 2}
70!9 = !{i32 2, !"Debug Info Version", i32 2}
71!10 = !{i32 1, !"PIC Level", i32 2}
72!11 = !{!"clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)"}
73!12 = !{!"0x100\00x\004\000", !4, !5, !13} ; [ DW_TAG_auto_variable ] [x] [line 4]
74!13 = !{!"0x13\00\000\00224\000\000\0016\000", !1, !5, null, !14, null, null, null} ; [ DW_TAG_structure_type ] [line 0, size 224, align 0, offset 0] [def] [from ]
75!14 = !{!15, !17, !18, !20, !21}
76!15 = !{!"0xd\00__isa\000\0064\0064\000\000", !1, !5, !16} ; [ DW_TAG_member ] [__isa] [line 0, size 64, align 64, offset 0] [from ]
77!16 = !{!"0xf\00\000\0064\0064\000\000", null, null, null} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from ]
78!17 = !{!"0xd\00__forwarding\000\0064\0064\0064\000", !1, !5, !16} ; [ DW_TAG_member ] [__forwarding] [line 0, size 64, align 64, offset 64] [from ]
79!18 = !{!"0xd\00__flags\000\0032\0032\00128\000", !1, !5, !19} ; [ DW_TAG_member ] [__flags] [line 0, size 32, align 32, offset 128] [from int]
80!19 = !{!"0x24\00int\000\0032\0032\000\000\005", null, null} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
81!20 = !{!"0xd\00__size\000\0032\0032\00160\000", !1, !5, !19} ; [ DW_TAG_member ] [__size] [line 0, size 32, align 32, offset 160] [from int]
82!21 = !{!"0xd\00x\000\0032\0032\00192\000", !1, !5, !19} ; [ DW_TAG_member ] [x] [line 0, size 32, align 32, offset 192] [from int]
83!22 = !{!"0x102\0034\008\006\0034\0024"} ; [ DW_TAG_expression ] [DW_OP_plus 8] [DW_OP_deref] [DW_OP_plus 24]
Duncan P. N. Exon Smith98854692015-01-14 22:27:36 +000084!23 = !MDLocation(line: 4, column: 15, scope: !4)
85!24 = !MDLocation(line: 4, column: 3, scope: !4)
86!25 = !MDLocation(line: 5, column: 3, scope: !4)
87!26 = !MDLocation(line: 6, column: 1, scope: !4)