blob: f1f8b35df27c9d467866bbda3e8de352d1af5dc4 [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.
Adrian Prantl6825fb62017-04-18 01:21:53 +000016; CHECK: !DIExpression(DW_OP_plus, 8, DW_OP_deref, DW_OP_plus, 24)
Frederic Riss7c78db52014-12-09 17:55:48 +000017
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
Peter Collingbourned4bff302015-11-05 22:03:56 +000023define void @foo() #0 !dbg !4 {
Frederic Riss7c78db52014-12-09 17:55:48 +000024entry:
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
Adrian Prantl75819ae2016-04-15 15:57:41 +000061!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)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000062!1 = !DIFile(filename: "block.c", directory: "/tmp")
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000063!2 = !{}
Adrian Prantl75819ae2016-04-15 15:57:41 +000064!4 = distinct !DISubprogram(name: "foo", line: 3, isLocal: false, isDefinition: true, isOptimized: false, unit: !0, scopeLine: 3, file: !1, scope: !5, type: !6, variables: !2)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000065!5 = !DIFile(filename: "block.c", directory: "/tmp")
66!6 = !DISubroutineType(types: !7)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000067!7 = !{null}
68!8 = !{i32 2, !"Dwarf Version", i32 2}
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +000069!9 = !{i32 2, !"Debug Info Version", i32 3}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000070!10 = !{i32 1, !"PIC Level", i32 2}
71!11 = !{!"clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)"}
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +000072!12 = !DILocalVariable(name: "x", line: 4, scope: !4, file: !5, type: !13)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000073!13 = !DICompositeType(tag: DW_TAG_structure_type, size: 224, flags: DIFlagBlockByrefStruct, file: !1, scope: !5, elements: !14)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000074!14 = !{!15, !17, !18, !20, !21}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000075!15 = !DIDerivedType(tag: DW_TAG_member, name: "__isa", size: 64, align: 64, file: !1, scope: !5, baseType: !16)
76!16 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: null)
77!17 = !DIDerivedType(tag: DW_TAG_member, name: "__forwarding", size: 64, align: 64, offset: 64, file: !1, scope: !5, baseType: !16)
78!18 = !DIDerivedType(tag: DW_TAG_member, name: "__flags", size: 32, align: 32, offset: 128, file: !1, scope: !5, baseType: !19)
79!19 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
80!20 = !DIDerivedType(tag: DW_TAG_member, name: "__size", size: 32, align: 32, offset: 160, file: !1, scope: !5, baseType: !19)
81!21 = !DIDerivedType(tag: DW_TAG_member, name: "x", size: 32, align: 32, offset: 192, file: !1, scope: !5, baseType: !19)
82!22 = !DIExpression(DW_OP_plus, 8, DW_OP_deref, DW_OP_plus, 24)
83!23 = !DILocation(line: 4, column: 15, scope: !4)
84!24 = !DILocation(line: 4, column: 3, scope: !4)
85!25 = !DILocation(line: 5, column: 3, scope: !4)
86!26 = !DILocation(line: 6, column: 1, scope: !4)