llvm.org GIT mirror llvm / bef4d67
[sancov] Don't instrument blocks with no insertion point This prevents crashes when attempting to instrument functions containing C++ try. Sanitizer coverage will still fail at runtime when an exception is thrown through a sancov instrumented function, but that seems marginally better than what we have now. The full solution is to color the blocks in LLVM IR and only instrument blocks that have an unambiguous color, using the appropriate token. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298662 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 2 years ago
2 changed file(s) with 116 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
442442 // percentage. Also, unreachable instructions frequently have no debug
443443 // locations.
444444 if (isa(BB->getTerminator()))
445 return false;
446
447 // Don't insert coverage into blocks without a valid insertion point
448 // (catchswitch blocks).
449 if (BB->getFirstInsertionPt() == BB->end())
445450 return false;
446451
447452 if (!ClPruneBlocks || &F.getEntryBlock() == BB)
0 ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK
1
2 ; Generated from this C++ source:
3 ; $ clang -O2 t.cpp -S -emit-llvm
4 ; void g();
5 ; struct Foo { Foo(); ~Foo(); };
6 ; int f() {
7 ; Foo v;
8 ; g();
9 ; try {
10 ; g();
11 ; } catch (int e) {
12 ; g();
13 ; } catch (...) {
14 ; g();
15 ; }
16 ; return 0;
17 ; }
18
19 ; FIXME: We need to do more than this. In particular, __sanitizer_cov callbacks
20 ; in funclets need token bundles.
21
22 ; CHECK-LABEL: define i32 @"\01?f@@YAHXZ"()
23 ; CHECK: catch.dispatch:
24 ; CHECK-NEXT: catchswitch within none [label %catch3, label %catch] unwind label %ehcleanup
25
26 ; ModuleID = 't.cpp'
27 source_filename = "t.cpp"
28 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
29 target triple = "x86_64-pc-windows-msvc19.10.24728"
30
31 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
32 %struct.Foo = type { i8 }
33
34 $"\01??_R0H@8" = comdat any
35
36 @"\01??_7type_info@@6B@" = external constant i8*
37 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
38
39 ; Function Attrs: uwtable
40 define i32 @"\01?f@@YAHXZ"() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
41 entry:
42 %v = alloca %struct.Foo, align 1
43 %e = alloca i32, align 4
44 %0 = getelementptr inbounds %struct.Foo, %struct.Foo* %v, i64 0, i32 0
45 call void @llvm.lifetime.start(i64 1, i8* nonnull %0) #4
46 %call = call %struct.Foo* @"\01??0Foo@@QEAA@XZ"(%struct.Foo* nonnull %v)
47 invoke void @"\01?g@@YAXXZ"()
48 to label %invoke.cont unwind label %ehcleanup
49
50 invoke.cont: ; preds = %entry
51 invoke void @"\01?g@@YAXXZ"()
52 to label %try.cont unwind label %catch.dispatch
53
54 catch.dispatch: ; preds = %invoke.cont
55 %1 = catchswitch within none [label %catch3, label %catch] unwind label %ehcleanup
56
57 catch3: ; preds = %catch.dispatch
58 %2 = catchpad within %1 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %e]
59 invoke void @"\01?g@@YAXXZ"() [ "funclet"(token %2) ]
60 to label %invoke.cont4 unwind label %ehcleanup
61
62 invoke.cont4: ; preds = %catch3
63 catchret from %2 to label %try.cont
64
65 try.cont: ; preds = %invoke.cont, %invoke.cont2, %invoke.cont4
66 call void @"\01??1Foo@@QEAA@XZ"(%struct.Foo* nonnull %v) #4
67 call void @llvm.lifetime.end(i64 1, i8* nonnull %0) #4
68 ret i32 0
69
70 catch: ; preds = %catch.dispatch
71 %3 = catchpad within %1 [i8* null, i32 64, i8* null]
72 invoke void @"\01?g@@YAXXZ"() [ "funclet"(token %3) ]
73 to label %invoke.cont2 unwind label %ehcleanup
74
75 invoke.cont2: ; preds = %catch
76 catchret from %3 to label %try.cont
77
78 ehcleanup: ; preds = %catch3, %catch, %catch.dispatch, %entry
79 %4 = cleanuppad within none []
80 call void @"\01??1Foo@@QEAA@XZ"(%struct.Foo* nonnull %v) #4 [ "funclet"(token %4) ]
81 call void @llvm.lifetime.end(i64 1, i8* nonnull %0) #4
82 cleanupret from %4 unwind to caller
83 }
84
85 ; Function Attrs: argmemonly nounwind
86 declare void @llvm.lifetime.start(i64, i8* nocapture) #1
87
88 declare %struct.Foo* @"\01??0Foo@@QEAA@XZ"(%struct.Foo* returned) unnamed_addr #2
89
90 declare void @"\01?g@@YAXXZ"() local_unnamed_addr #2
91
92 declare i32 @__CxxFrameHandler3(...)
93
94 ; Function Attrs: nounwind
95 declare void @"\01??1Foo@@QEAA@XZ"(%struct.Foo*) unnamed_addr #3
96
97 ; Function Attrs: argmemonly nounwind
98 declare void @llvm.lifetime.end(i64, i8* nocapture) #1
99
100 attributes #0 = { uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
101 attributes #1 = { argmemonly nounwind }
102 attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
103 attributes #3 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
104 attributes #4 = { nounwind }
105
106 !llvm.module.flags = !{!0}
107 !llvm.ident = !{!1}
108
109 !0 = !{i32 1, !"PIC Level", i32 2}
110 !1 = !{!"clang version 5.0.0 "}