1*9880d681SAndroid Build Coastguard Worker; RUN: opt -S -asan %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Worker; The IR of this testcase is generated from the following C code: 4*9880d681SAndroid Build Coastguard Worker; void bar (int); 5*9880d681SAndroid Build Coastguard Worker; 6*9880d681SAndroid Build Coastguard Worker; void foo() { 7*9880d681SAndroid Build Coastguard Worker; __block int x; 8*9880d681SAndroid Build Coastguard Worker; bar(x); 9*9880d681SAndroid Build Coastguard Worker; } 10*9880d681SAndroid Build Coastguard Worker; by compiling it with 'clang -emit-llvm -g -S' and then by manually 11*9880d681SAndroid Build Coastguard Worker; adding the sanitize_address attribute to the @foo() function (so 12*9880d681SAndroid Build Coastguard Worker; that ASAN accepts to instrument the function in the above opt run). 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker; Check that the location of the ASAN instrumented __block variable is 15*9880d681SAndroid Build Coastguard Worker; correct. 16*9880d681SAndroid Build Coastguard Worker; CHECK: !DIExpression(DW_OP_deref, DW_OP_plus, 8, DW_OP_deref, DW_OP_plus, 24) 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker%struct.__block_byref_x = type { i8*, %struct.__block_byref_x*, i32, i32, i32 } 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind ssp uwtable 23*9880d681SAndroid Build Coastguard Workerdefine void @foo() #0 !dbg !4 { 24*9880d681SAndroid Build Coastguard Workerentry: 25*9880d681SAndroid Build Coastguard Worker %x = alloca %struct.__block_byref_x, align 8 26*9880d681SAndroid Build Coastguard Worker call void @llvm.dbg.declare(metadata %struct.__block_byref_x* %x, metadata !12, metadata !22), !dbg !23 27*9880d681SAndroid Build Coastguard Worker %byref.isa = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 0, !dbg !24 28*9880d681SAndroid Build Coastguard Worker store i8* null, i8** %byref.isa, !dbg !24 29*9880d681SAndroid Build Coastguard Worker %byref.forwarding = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !24 30*9880d681SAndroid Build Coastguard Worker store %struct.__block_byref_x* %x, %struct.__block_byref_x** %byref.forwarding, !dbg !24 31*9880d681SAndroid Build Coastguard Worker %byref.flags = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 2, !dbg !24 32*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %byref.flags, !dbg !24 33*9880d681SAndroid Build Coastguard Worker %byref.size = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 3, !dbg !24 34*9880d681SAndroid Build Coastguard Worker store i32 32, i32* %byref.size, !dbg !24 35*9880d681SAndroid Build Coastguard Worker %forwarding = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !25 36*9880d681SAndroid Build Coastguard Worker %0 = load %struct.__block_byref_x*, %struct.__block_byref_x** %forwarding, !dbg !25 37*9880d681SAndroid Build Coastguard Worker %x1 = getelementptr inbounds %struct.__block_byref_x, %struct.__block_byref_x* %0, i32 0, i32 4, !dbg !25 38*9880d681SAndroid Build Coastguard Worker %1 = load i32, i32* %x1, align 4, !dbg !25 39*9880d681SAndroid Build Coastguard Worker call void @bar(i32 %1), !dbg !25 40*9880d681SAndroid Build Coastguard Worker %2 = bitcast %struct.__block_byref_x* %x to i8*, !dbg !26 41*9880d681SAndroid Build Coastguard Worker call void @_Block_object_dispose(i8* %2, i32 8) #3, !dbg !26 42*9880d681SAndroid Build Coastguard Worker ret void, !dbg !26 43*9880d681SAndroid Build Coastguard Worker} 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone 46*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.dbg.declare(metadata, metadata, metadata) #1 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Workerdeclare void @bar(i32) #2 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Workerdeclare void @_Block_object_dispose(i8*, i32) 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Workerattributes #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" } 53*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind readnone } 54*9880d681SAndroid Build Coastguard Workerattributes #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" } 55*9880d681SAndroid Build Coastguard Workerattributes #3 = { nounwind } 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0} 58*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!8, !9, !10} 59*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!11} 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker!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) 62*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "block.c", directory: "/tmp") 63*9880d681SAndroid Build Coastguard Worker!2 = !{} 64*9880d681SAndroid Build Coastguard Worker!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) 65*9880d681SAndroid Build Coastguard Worker!5 = !DIFile(filename: "block.c", directory: "/tmp") 66*9880d681SAndroid Build Coastguard Worker!6 = !DISubroutineType(types: !7) 67*9880d681SAndroid Build Coastguard Worker!7 = !{null} 68*9880d681SAndroid Build Coastguard Worker!8 = !{i32 2, !"Dwarf Version", i32 2} 69*9880d681SAndroid Build Coastguard Worker!9 = !{i32 2, !"Debug Info Version", i32 3} 70*9880d681SAndroid Build Coastguard Worker!10 = !{i32 1, !"PIC Level", i32 2} 71*9880d681SAndroid Build Coastguard Worker!11 = !{!"clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)"} 72*9880d681SAndroid Build Coastguard Worker!12 = !DILocalVariable(name: "x", line: 4, scope: !4, file: !5, type: !13) 73*9880d681SAndroid Build Coastguard Worker!13 = !DICompositeType(tag: DW_TAG_structure_type, size: 224, flags: DIFlagBlockByrefStruct, file: !1, scope: !5, elements: !14) 74*9880d681SAndroid Build Coastguard Worker!14 = !{!15, !17, !18, !20, !21} 75*9880d681SAndroid Build Coastguard Worker!15 = !DIDerivedType(tag: DW_TAG_member, name: "__isa", size: 64, align: 64, file: !1, scope: !5, baseType: !16) 76*9880d681SAndroid Build Coastguard Worker!16 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: null) 77*9880d681SAndroid Build Coastguard Worker!17 = !DIDerivedType(tag: DW_TAG_member, name: "__forwarding", size: 64, align: 64, offset: 64, file: !1, scope: !5, baseType: !16) 78*9880d681SAndroid Build Coastguard Worker!18 = !DIDerivedType(tag: DW_TAG_member, name: "__flags", size: 32, align: 32, offset: 128, file: !1, scope: !5, baseType: !19) 79*9880d681SAndroid Build Coastguard Worker!19 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 80*9880d681SAndroid Build Coastguard Worker!20 = !DIDerivedType(tag: DW_TAG_member, name: "__size", size: 32, align: 32, offset: 160, file: !1, scope: !5, baseType: !19) 81*9880d681SAndroid Build Coastguard Worker!21 = !DIDerivedType(tag: DW_TAG_member, name: "x", size: 32, align: 32, offset: 192, file: !1, scope: !5, baseType: !19) 82*9880d681SAndroid Build Coastguard Worker!22 = !DIExpression(DW_OP_plus, 8, DW_OP_deref, DW_OP_plus, 24) 83*9880d681SAndroid Build Coastguard Worker!23 = !DILocation(line: 4, column: 15, scope: !4) 84*9880d681SAndroid Build Coastguard Worker!24 = !DILocation(line: 4, column: 3, scope: !4) 85*9880d681SAndroid Build Coastguard Worker!25 = !DILocation(line: 5, column: 3, scope: !4) 86*9880d681SAndroid Build Coastguard Worker!26 = !DILocation(line: 6, column: 1, scope: !4) 87