llvm.org GIT mirror llvm / b49c13c
[asancov] Fix coverage line info some more. Now it should always point to the opening brace of the function (in -asan-coverage=1 mode). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210266 91177308-0d34-0410-b5e6-96231b3b80d8 Evgeniy Stepanov 5 years ago
2 changed file(s) with 55 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
12531253 break;
12541254 }
12551255
1256 DebugLoc EntryLoc = IP->getDebugLoc().getFnDebugLoc(*C);
12561257 IRBuilder<> IRB(IP);
1258 IRB.SetCurrentDebugLocation(EntryLoc);
12571259 Type *Int8Ty = IRB.getInt8Ty();
12581260 GlobalVariable *Guard = new GlobalVariable(
12591261 *F.getParent(), Int8Ty, false, GlobalValue::PrivateLinkage,
12651267 Instruction *Ins = SplitBlockAndInsertIfThen(
12661268 Cmp, IP, false, MDBuilder(*C).createBranchWeights(1, 100000));
12671269 IRB.SetInsertPoint(Ins);
1270 IRB.SetCurrentDebugLocation(EntryLoc);
12681271 // We pass &F to __sanitizer_cov. We could avoid this and rely on
12691272 // GET_CALLER_PC, but having the PC of the first instruction is just nice.
1270 Instruction *Call = IRB.CreateCall(AsanCovFunction);
1271 Call->setDebugLoc(IP->getDebugLoc());
1273 IRB.CreateCall(AsanCovFunction);
12721274 StoreInst *Store = IRB.CreateStore(ConstantInt::get(Int8Ty, 1), Guard);
12731275 Store->setAtomic(Monotonic);
12741276 Store->setAlignment(1);
11
22 ; RUN: opt < %s -asan -asan-module -asan-coverage=1 -S | FileCheck %s
33
4 ; C++ source:
5 ; 1: struct A {
6 ; 2: int f();
7 ; 3: int x;
8 ; 4: };
9 ; 5:
10 ; 6: int A::f() {
11 ; 7: return x;
12 ; 8: }
13 ; clang++ ../1.cc -O3 -g -S -emit-llvm -fno-strict-aliasing
14 ; and add sanitize_address to @_ZN1A1fEv
15
16 ; Test that __sanitizer_cov call has !dbg pointing to the opening { of A::f().
17 ; CHECK: call void @__sanitizer_cov(), !dbg [[A:!.*]]
18 ; CHECK: [[A]] = metadata !{i32 6, i32 0, metadata !{{.*}}, null}
19
20
421 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
522 target triple = "x86_64-unknown-linux-gnu"
623
7 ; Function Attrs: nounwind readnone uwtable
8 define void @_Z1fv() #0 {
24 %struct.A = type { i32 }
25
26 ; Function Attrs: nounwind readonly uwtable
27 define i32 @_ZN1A1fEv(%struct.A* nocapture readonly %this) #0 align 2 {
928 entry:
10 ret void, !dbg !11
29 tail call void @llvm.dbg.value(metadata !{%struct.A* %this}, i64 0, metadata !15), !dbg !20
30 %x = getelementptr inbounds %struct.A* %this, i64 0, i32 0, !dbg !21
31 %0 = load i32* %x, align 4, !dbg !21
32 ret i32 %0, !dbg !21
1133 }
1234
13 ; CHECK: call void @__sanitizer_cov(), !dbg !
35 ; Function Attrs: nounwind readnone
36 declare void @llvm.dbg.value(metadata, i64, metadata) #1
1437
15 attributes #0 = { sanitize_address nounwind readnone uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
38 attributes #0 = { sanitize_address nounwind readonly uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
39 attributes #1 = { nounwind readnone }
1640
1741 !llvm.dbg.cu = !{!0}
18 !llvm.module.flags = !{!8, !9}
19 !llvm.ident = !{!10}
42 !llvm.module.flags = !{!17, !18}
43 !llvm.ident = !{!19}
2044
21 !0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.5.0 (208682)", i1 true, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/tmp//tmp/1.cc] [DW_LANG_C_plus_plus]
22 !1 = metadata !{metadata !"/tmp/1.cc", metadata !"/tmp"}
45 !0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.5.0 (210251)", i1 true, metadata !"", i32 0, metadata !2, metadata !3, metadata !12, metadata !2, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/code/llvm/build0/../1.cc] [DW_LANG_C_plus_plus]
46 !1 = metadata !{metadata !"../1.cc", metadata !"/code/llvm/build0"}
2347 !2 = metadata !{}
2448 !3 = metadata !{metadata !4}
25 !4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"f", metadata !"f", metadata !"_Z1fv", i32 1, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, void ()* @_Z1fv, null, null, metadata !2, i32 1} ; [ DW_TAG_subprogram ] [line 1] [def] [f]
26 !5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/tmp//tmp/1.cc]
27 !6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
28 !7 = metadata !{null}
29 !8 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}
30 !9 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
31 !10 = metadata !{metadata !"clang version 3.5.0 (208682)"}
32 !11 = metadata !{i32 2, i32 0, metadata !4, null}
49 !4 = metadata !{i32 786451, metadata !1, null, metadata !"A", i32 1, i64 32, i64 32, i32 0, i32 0, null, metadata !5, i32 0, null, null, metadata !"_ZTS1A"} ; [ DW_TAG_structure_type ] [A] [line 1, size 32, align 32, offset 0] [def] [from ]
50 !5 = metadata !{metadata !6, metadata !8}
51 !6 = metadata !{i32 786445, metadata !1, metadata !"_ZTS1A", metadata !"x", i32 3, i64 32, i64 32, i64 0, i32 0, metadata !7} ; [ DW_TAG_member ] [x] [line 3, size 32, align 32, offset 0] [from int]
52 !7 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
53 !8 = metadata !{i32 786478, metadata !1, metadata !"_ZTS1A", metadata !"f", metadata !"f", metadata !"_ZN1A1fEv", i32 2, metadata !9, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 true, null, null, i32 0, null, i32 2} ; [ DW_TAG_subprogram ] [line 2] [f]
54 !9 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !10, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
55 !10 = metadata !{metadata !7, metadata !11}
56 !11 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 1088, metadata !"_ZTS1A"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from _ZTS1A]
57 !12 = metadata !{metadata !13}
58 !13 = metadata !{i32 786478, metadata !1, metadata !"_ZTS1A", metadata !"f", metadata !"f", metadata !"_ZN1A1fEv", i32 6, metadata !9, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, i32 (%struct.A*)* @_ZN1A1fEv, null, metadata !8, metadata !14, i32 6} ; [ DW_TAG_subprogram ] [line 6] [def] [f]
59 !14 = metadata !{metadata !15}
60 !15 = metadata !{i32 786689, metadata !13, metadata !"this", null, i32 16777216, metadata !16, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 0]
61 !16 = metadata !{i32 786447, null, null, metadata !"", i32 0, i64 64, i64 64, i64 0, i32 0, metadata !"_ZTS1A"} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from _ZTS1A]
62 !17 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}
63 !18 = metadata !{i32 2, metadata !"Debug Info Version", i32 1}
64 !19 = metadata !{metadata !"clang version 3.5.0 (210251)"}
65 !20 = metadata !{i32 0, i32 0, metadata !13, null}
66 !21 = metadata !{i32 7, i32 0, metadata !13, null}