diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
commit | 71d5a2540a98c81f5bcaeb48805e0e2881f530ef (patch) | |
tree | 5343938942df402b49ec7300a1c25a2d4ccd5821 /test/Instrumentation/SanitizerCoverage | |
parent | 31bbf64f3a4974a2d6c8b3b27ad2f519caf74057 (diff) |
Diffstat (limited to 'test/Instrumentation/SanitizerCoverage')
6 files changed, 207 insertions, 4 deletions
diff --git a/test/Instrumentation/SanitizerCoverage/coverage.ll b/test/Instrumentation/SanitizerCoverage/coverage.ll index a2a92a02c718..75a341da021c 100644 --- a/test/Instrumentation/SanitizerCoverage/coverage.ll +++ b/test/Instrumentation/SanitizerCoverage/coverage.ll @@ -1,13 +1,12 @@ ; RUN: opt < %s -sancov -sanitizer-coverage-level=0 -S | FileCheck %s --check-prefix=CHECK0 ; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -S | FileCheck %s --check-prefix=CHECK1 -; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -S | FileCheck %s --check-prefix=CHECK2 +; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK ; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK2 ; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=0 -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK ; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=1 -S | FileCheck %s --check-prefix=CHECK_WITH_CHECK ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-block-threshold=10 -S | FileCheck %s --check-prefix=CHECK3 ; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -S | FileCheck %s --check-prefix=CHECK4 ; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK_TRACE_PC -; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s --check-prefix=CHECK_TRACE_PC ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-8bit-counters=1 -S | FileCheck %s --check-prefix=CHECK-8BIT ; RUN: opt < %s -sancov -sanitizer-coverage-level=2 -sanitizer-coverage-block-threshold=10 \ diff --git a/test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll b/test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll index 37eca1065fdc..fde1904259d5 100644 --- a/test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll +++ b/test/Instrumentation/SanitizerCoverage/coverage2-dbg.ll @@ -17,8 +17,8 @@ target triple = "x86_64-unknown-linux-gnu" ; Check that __sanitizer_cov call has !dgb pointing to the beginning ; of appropriate basic blocks. ; CHECK-LABEL:_Z3fooPi -; CHECK: call void @__sanitizer_cov(i32*{{.*}}), !dbg [[A:!.*]] -; CHECK: call void @__sanitizer_cov(i32*{{.*}}), !dbg [[B:!.*]] +; CHECK: call void @__sanitizer_cov{{.*}}(i32*{{.*}}), !dbg [[A:!.*]] +; CHECK: call void @__sanitizer_cov{{.*}}(i32*{{.*}}), !dbg [[B:!.*]] ; CHECK: ret void ; CHECK: [[A]] = !DILocation(line: 1, scope: !{{.*}}) ; CHECK: [[B]] = !DILocation(line: 3, column: 5, scope: !{{.*}}) diff --git a/test/Instrumentation/SanitizerCoverage/trace-pc-guard-comdat.ll b/test/Instrumentation/SanitizerCoverage/trace-pc-guard-comdat.ll new file mode 100644 index 000000000000..8ab5f4961b1b --- /dev/null +++ b/test/Instrumentation/SanitizerCoverage/trace-pc-guard-comdat.ll @@ -0,0 +1,42 @@ +; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s --check-prefix=CHECK_TRACE_PC_GUARD + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" +target triple = "x86_64-unknown-linux-gnu" +define void @foo(i32* %a) sanitize_address { +entry: + %tobool = icmp eq i32* %a, null + br i1 %tobool, label %if.end, label %if.then + + if.then: ; preds = %entry + store i32 0, i32* %a, align 4 + br label %if.end + + if.end: ; preds = %entry, %if.then + ret void +} + +%struct.StructWithVptr = type { i32 (...)** } + +define void @CallViaVptr(%struct.StructWithVptr* %foo) uwtable sanitize_address { +entry: + %0 = bitcast %struct.StructWithVptr* %foo to void (%struct.StructWithVptr*)*** + %vtable = load void (%struct.StructWithVptr*)**, void (%struct.StructWithVptr*)*** %0, align 8 + %1 = load void (%struct.StructWithVptr*)*, void (%struct.StructWithVptr*)** %vtable, align 8 + tail call void %1(%struct.StructWithVptr* %foo) + tail call void %1(%struct.StructWithVptr* %foo) + tail call void asm sideeffect "", ""() + ret void +} + +; CHECK_TRACE_PC_GUARD-LABEL: define void @foo +; CHECK_TRACE_PC_GUARD: call void @__sanitizer_cov_trace_pc +; CHECK_TRACE_PC_GUARD: call void asm sideeffect "", ""() +; CHECK_TRACE_PC_GUARD: ret void + +; CHECK_TRACE_PC_GUARD-LABEL: define void @CallViaVptr +; CHECK_TRACE_PC_GUARD: call void @__sanitizer_cov_trace_pc_indir +; CHECK_TRACE_PC_GUARD: call void @__sanitizer_cov_trace_pc_indir +; CHECK_TRACE_PC_GUARD: ret void + +; CHECK_TRACE_PC_GUARD-LABEL: define internal void @sancov.module_ctor() comdat + diff --git a/test/Instrumentation/SanitizerCoverage/trace-pc-guard-nocomdat.ll b/test/Instrumentation/SanitizerCoverage/trace-pc-guard-nocomdat.ll new file mode 100644 index 000000000000..392ff8d29327 --- /dev/null +++ b/test/Instrumentation/SanitizerCoverage/trace-pc-guard-nocomdat.ll @@ -0,0 +1,42 @@ +; RUN: opt < %s -sancov -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s --check-prefix=CHECK_TRACE_PC_GUARD + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" +target triple = "x86_64-apple-darwin10.0.0" +define void @foo(i32* %a) sanitize_address { +entry: + %tobool = icmp eq i32* %a, null + br i1 %tobool, label %if.end, label %if.then + + if.then: ; preds = %entry + store i32 0, i32* %a, align 4 + br label %if.end + + if.end: ; preds = %entry, %if.then + ret void +} + +%struct.StructWithVptr = type { i32 (...)** } + +define void @CallViaVptr(%struct.StructWithVptr* %foo) uwtable sanitize_address { +entry: + %0 = bitcast %struct.StructWithVptr* %foo to void (%struct.StructWithVptr*)*** + %vtable = load void (%struct.StructWithVptr*)**, void (%struct.StructWithVptr*)*** %0, align 8 + %1 = load void (%struct.StructWithVptr*)*, void (%struct.StructWithVptr*)** %vtable, align 8 + tail call void %1(%struct.StructWithVptr* %foo) + tail call void %1(%struct.StructWithVptr* %foo) + tail call void asm sideeffect "", ""() + ret void +} + +; CHECK_TRACE_PC_GUARD-LABEL: define void @foo +; CHECK_TRACE_PC_GUARD: call void @__sanitizer_cov_trace_pc +; CHECK_TRACE_PC_GUARD: call void asm sideeffect "", ""() +; CHECK_TRACE_PC_GUARD: ret void + +; CHECK_TRACE_PC_GUARD-LABEL: define void @CallViaVptr +; CHECK_TRACE_PC_GUARD: call void @__sanitizer_cov_trace_pc_indir +; CHECK_TRACE_PC_GUARD: call void @__sanitizer_cov_trace_pc_indir +; CHECK_TRACE_PC_GUARD: ret void + +; CHECK_TRACE_PC_GUARD-LABEL: define internal void @sancov.module_ctor() { + diff --git a/test/Instrumentation/SanitizerCoverage/tracing.ll b/test/Instrumentation/SanitizerCoverage/tracing.ll index 49c2a1a63527..9e153472eaba 100644 --- a/test/Instrumentation/SanitizerCoverage/tracing.ll +++ b/test/Instrumentation/SanitizerCoverage/tracing.ll @@ -3,6 +3,7 @@ ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-experimental-tracing -S | FileCheck %s --check-prefix=CHECK3 ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK_PC ; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S | FileCheck %s --check-prefix=CHECK_PC_GUARD +; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard -S -mtriple=x86_64-apple-macosx | FileCheck %s --check-prefix=CHECK_PC_GUARD_DARWIN target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-unknown-linux-gnu" @@ -47,3 +48,11 @@ entry: ; CHECK_PC_GUARD-NOT: call void @__sanitizer_cov_trace_pc ; CHECK_PC_GUARD: ret void ; CHECK_PC_GUARD: call void @__sanitizer_cov_trace_pc_guard_init(i32* bitcast (i32** @__start___sancov_guards to i32*), i32* bitcast (i32** @__stop___sancov_guards to i32*)) + +; CHECK_PC_GUARD_DARWIN-LABEL: define void @foo +; CHECK_PC_GUARD_DARWIN: call void @__sanitizer_cov_trace_pc_guard +; CHECK_PC_GUARD_DARWIN: call void @__sanitizer_cov_trace_pc_guard +; CHECK_PC_GUARD_DARWIN: call void @__sanitizer_cov_trace_pc_guard +; CHECK_PC_GUARD_DARWIN-NOT: call void @__sanitizer_cov_trace_pc +; CHECK_PC_GUARD_DARWIN: ret void +; CHECK_PC_GUARD_DARWIN: call void @__sanitizer_cov_trace_pc_guard_init(i32* bitcast (i32** @"\01section$start$__DATA$__sancov_guards" to i32*), i32* bitcast (i32** @"\01section$end$__DATA$__sancov_guards" to i32*)) diff --git a/test/Instrumentation/SanitizerCoverage/wineh.ll b/test/Instrumentation/SanitizerCoverage/wineh.ll new file mode 100644 index 000000000000..87b44be5544f --- /dev/null +++ b/test/Instrumentation/SanitizerCoverage/wineh.ll @@ -0,0 +1,111 @@ +; RUN: opt < %s -sancov -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc -S | FileCheck %s --check-prefix=CHECK + +; Generated from this C++ source: +; $ clang -O2 t.cpp -S -emit-llvm +; void g(); +; struct Foo { Foo(); ~Foo(); }; +; int f() { +; Foo v; +; g(); +; try { +; g(); +; } catch (int e) { +; g(); +; } catch (...) { +; g(); +; } +; return 0; +; } + +; FIXME: We need to do more than this. In particular, __sanitizer_cov callbacks +; in funclets need token bundles. + +; CHECK-LABEL: define i32 @"\01?f@@YAHXZ"() +; CHECK: catch.dispatch: +; CHECK-NEXT: catchswitch within none [label %catch3, label %catch] unwind label %ehcleanup + +; ModuleID = 't.cpp' +source_filename = "t.cpp" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.10.24728" + +%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] } +%struct.Foo = type { i8 } + +$"\01??_R0H@8" = comdat any + +@"\01??_7type_info@@6B@" = external constant i8* +@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat + +; Function Attrs: uwtable +define i32 @"\01?f@@YAHXZ"() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) { +entry: + %v = alloca %struct.Foo, align 1 + %e = alloca i32, align 4 + %0 = getelementptr inbounds %struct.Foo, %struct.Foo* %v, i64 0, i32 0 + call void @llvm.lifetime.start(i64 1, i8* nonnull %0) #4 + %call = call %struct.Foo* @"\01??0Foo@@QEAA@XZ"(%struct.Foo* nonnull %v) + invoke void @"\01?g@@YAXXZ"() + to label %invoke.cont unwind label %ehcleanup + +invoke.cont: ; preds = %entry + invoke void @"\01?g@@YAXXZ"() + to label %try.cont unwind label %catch.dispatch + +catch.dispatch: ; preds = %invoke.cont + %1 = catchswitch within none [label %catch3, label %catch] unwind label %ehcleanup + +catch3: ; preds = %catch.dispatch + %2 = catchpad within %1 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %e] + invoke void @"\01?g@@YAXXZ"() [ "funclet"(token %2) ] + to label %invoke.cont4 unwind label %ehcleanup + +invoke.cont4: ; preds = %catch3 + catchret from %2 to label %try.cont + +try.cont: ; preds = %invoke.cont, %invoke.cont2, %invoke.cont4 + call void @"\01??1Foo@@QEAA@XZ"(%struct.Foo* nonnull %v) #4 + call void @llvm.lifetime.end(i64 1, i8* nonnull %0) #4 + ret i32 0 + +catch: ; preds = %catch.dispatch + %3 = catchpad within %1 [i8* null, i32 64, i8* null] + invoke void @"\01?g@@YAXXZ"() [ "funclet"(token %3) ] + to label %invoke.cont2 unwind label %ehcleanup + +invoke.cont2: ; preds = %catch + catchret from %3 to label %try.cont + +ehcleanup: ; preds = %catch3, %catch, %catch.dispatch, %entry + %4 = cleanuppad within none [] + call void @"\01??1Foo@@QEAA@XZ"(%struct.Foo* nonnull %v) #4 [ "funclet"(token %4) ] + call void @llvm.lifetime.end(i64 1, i8* nonnull %0) #4 + cleanupret from %4 unwind to caller +} + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.start(i64, i8* nocapture) #1 + +declare %struct.Foo* @"\01??0Foo@@QEAA@XZ"(%struct.Foo* returned) unnamed_addr #2 + +declare void @"\01?g@@YAXXZ"() local_unnamed_addr #2 + +declare i32 @__CxxFrameHandler3(...) + +; Function Attrs: nounwind +declare void @"\01??1Foo@@QEAA@XZ"(%struct.Foo*) unnamed_addr #3 + +; Function Attrs: argmemonly nounwind +declare void @llvm.lifetime.end(i64, i8* nocapture) #1 + +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" } +attributes #1 = { argmemonly nounwind } +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" } +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" } +attributes #4 = { nounwind } + +!llvm.module.flags = !{!0} +!llvm.ident = !{!1} + +!0 = !{i32 1, !"PIC Level", i32 2} +!1 = !{!"clang version 5.0.0 "} |