-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[TySan][Clang] Add clang flag to use tysan outlined instrumentation a… #166170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
95c5ff3
d9dc8be
9ff2fb9
709c218
2edb5d3
384c35f
88ce7ab
61d9c1f
3a9ddee
bb315da
d057155
d8f8818
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // UNSUPPORTED: target={{.*}}-windows-{{.*}} | ||
|
|
||
| // RUN: %clang -S -fsanitize=type -emit-llvm -o - -fsanitize=type %s \ | ||
| // RUN: -fno-sanitize-type-outline-instrumentation \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK-NO-OUTLINE | ||
| // RUN: %clang -S -fsanitize=type -emit-llvm -o - -fsanitize=type %s \ | ||
| // RUN: -fsanitize-type-outline-instrumentation \ | ||
| // RUN: | FileCheck %s --check-prefixes=CHECK-OUTLINE | ||
|
|
||
| // CHECK-LABEL: @alias | ||
| // CHECK: __tysan_app_memory_mask | ||
| // CHECK: __tysan_shadow_memory_address | ||
| // CHECK-NO-OUTLINE-NOT: call{{.*}}@__tysan_instrument_mem_inst | ||
| // CHECK-NO-OUTLINE-NOT: call{{.*}}@__tysan_instrument_with_shadow_update | ||
| // CHECK-OUTLINE: call{{.*}}@__tysan_instrument_mem_inst | ||
| // CHECK-OUTLINE: call{{.*}}@__tysan_instrument_with_shadow_update | ||
|
|
||
| float alias(int *ptr){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use CHECK-LABEL to avoid accidentally passing the test for some reason? |
||
| float *aliasedPtr = (float *)ptr; | ||
| *aliasedPtr *= 2.0f; | ||
| return *aliasedPtr; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 6 | ||
| ; RUN: opt -passes='tysan' -S %s | FileCheck %s | ||
| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | ||
|
||
|
|
||
| ; RUN: opt -passes='tysan' -tysan-outline-instrumentation=false -S %s | FileCheck %s --check-prefix=CHECK-INLINE | ||
| ; RUN: opt -passes='tysan' -S %s | FileCheck %s --check-prefix=CHECK-OUTLINE | ||
|
|
||
| ;. | ||
| ; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @tysan.module_ctor, ptr null }] | ||
| ; CHECK: @__tysan_v1_Simple_20C_2fC_2b_2b_20TBAA = linkonce_odr constant { i64, i64, [18 x i8] } { i64 2, i64 0, [18 x i8] c"Simple C/C++ TBAA\00" }, comdat | ||
| ; CHECK: @__tysan_v1_omnipotent_20char = linkonce_odr constant { i64, i64, ptr, i64, [16 x i8] } { i64 2, i64 1, ptr @__tysan_v1_Simple_20C_2fC_2b_2b_20TBAA, i64 0, [16 x i8] c"omnipotent char\00" }, comdat | ||
|
|
@@ -10,7 +11,6 @@ | |
| ; CHECK: @llvm.used = appending global [5 x ptr] [ptr @tysan.module_ctor, ptr @__tysan_v1_Simple_20C_2fC_2b_2b_20TBAA, ptr @__tysan_v1_omnipotent_20char, ptr @__tysan_v1_any_20pointer, ptr @__tysan_v1_any_20pointer_o_0], section "llvm.metadata" | ||
| ; CHECK: @__tysan_shadow_memory_address = external global i64 | ||
| ; CHECK: @__tysan_app_memory_mask = external global i64 | ||
| ;. | ||
| define ptr @test_load_offset(ptr %argv) { | ||
| ; CHECK-LABEL: define ptr @test_load_offset( | ||
| ; CHECK-SAME: ptr [[ARGV:%.*]]) { | ||
|
|
@@ -52,6 +52,55 @@ define ptr @test_load_offset(ptr %argv) { | |
| ; CHECK-NEXT: [[L:%.*]] = load ptr, ptr null, align 8, !tbaa [[ANYPTR_TBAA1:![0-9]+]] | ||
| ; CHECK-NEXT: ret ptr [[L]] | ||
| ; | ||
| ; CHECK-INLINE-LABEL: define ptr @test_load_offset( | ||
| ; CHECK-INLINE-SAME: ptr [[ARGV:%.*]]) { | ||
| ; CHECK-INLINE-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-INLINE-NEXT: [[APP_MEM_MASK:%.*]] = load i64, ptr @__tysan_app_memory_mask, align 4 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BASE:%.*]] = load i64, ptr @__tysan_shadow_memory_address, align 4 | ||
| ; CHECK-INLINE-NEXT: [[APP_PTR_MASKED:%.*]] = and i64 0, [[APP_MEM_MASK]] | ||
| ; CHECK-INLINE-NEXT: [[APP_PTR_SHIFTED:%.*]] = shl i64 [[APP_PTR_MASKED]], 3 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_PTR_INT:%.*]] = add i64 [[APP_PTR_SHIFTED]], [[SHADOW_BASE]] | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_PTR:%.*]] = inttoptr i64 [[SHADOW_PTR_INT]] to ptr | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_DESC:%.*]] = load ptr, ptr [[SHADOW_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: [[DESC_SET:%.*]] = icmp eq ptr [[SHADOW_DESC]], null | ||
| ; CHECK-INLINE-NEXT: br i1 [[DESC_SET]], label %[[SET_TYPE:.*]], label %[[BB0:.*]], !prof [[PROF0:![0-9]+]] | ||
| ; CHECK-INLINE: [[SET_TYPE]]: | ||
| ; CHECK-INLINE-NEXT: store ptr @__tysan_v1_any_20pointer_o_0, ptr [[SHADOW_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_1_OFFSET:%.*]] = add i64 [[SHADOW_PTR_INT]], 8 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_1_PTR:%.*]] = inttoptr i64 [[SHADOW_BYTE_1_OFFSET]] to ptr | ||
| ; CHECK-INLINE-NEXT: store ptr inttoptr (i64 -1 to ptr), ptr [[SHADOW_BYTE_1_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_2_OFFSET:%.*]] = add i64 [[SHADOW_PTR_INT]], 16 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_2_PTR:%.*]] = inttoptr i64 [[SHADOW_BYTE_2_OFFSET]] to ptr | ||
| ; CHECK-INLINE-NEXT: store ptr inttoptr (i64 -2 to ptr), ptr [[SHADOW_BYTE_2_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_3_OFFSET:%.*]] = add i64 [[SHADOW_PTR_INT]], 24 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_3_PTR:%.*]] = inttoptr i64 [[SHADOW_BYTE_3_OFFSET]] to ptr | ||
| ; CHECK-INLINE-NEXT: store ptr inttoptr (i64 -3 to ptr), ptr [[SHADOW_BYTE_3_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_4_OFFSET:%.*]] = add i64 [[SHADOW_PTR_INT]], 32 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_4_PTR:%.*]] = inttoptr i64 [[SHADOW_BYTE_4_OFFSET]] to ptr | ||
| ; CHECK-INLINE-NEXT: store ptr inttoptr (i64 -4 to ptr), ptr [[SHADOW_BYTE_4_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_5_OFFSET:%.*]] = add i64 [[SHADOW_PTR_INT]], 40 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_5_PTR:%.*]] = inttoptr i64 [[SHADOW_BYTE_5_OFFSET]] to ptr | ||
| ; CHECK-INLINE-NEXT: store ptr inttoptr (i64 -5 to ptr), ptr [[SHADOW_BYTE_5_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_6_OFFSET:%.*]] = add i64 [[SHADOW_PTR_INT]], 48 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_6_PTR:%.*]] = inttoptr i64 [[SHADOW_BYTE_6_OFFSET]] to ptr | ||
| ; CHECK-INLINE-NEXT: store ptr inttoptr (i64 -6 to ptr), ptr [[SHADOW_BYTE_6_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_7_OFFSET:%.*]] = add i64 [[SHADOW_PTR_INT]], 56 | ||
| ; CHECK-INLINE-NEXT: [[SHADOW_BYTE_7_PTR:%.*]] = inttoptr i64 [[SHADOW_BYTE_7_OFFSET]] to ptr | ||
| ; CHECK-INLINE-NEXT: store ptr inttoptr (i64 -7 to ptr), ptr [[SHADOW_BYTE_7_PTR]], align 8 | ||
| ; CHECK-INLINE-NEXT: br label %[[BB0]] | ||
| ; CHECK-INLINE: [[BB0]]: | ||
| ; CHECK-INLINE-NEXT: [[L:%.*]] = load ptr, ptr null, align 8, !tbaa [[ANYPTR_TBAA1:![0-9]+]] | ||
| ; CHECK-INLINE-NEXT: ret ptr [[L]] | ||
| ; | ||
| ; CHECK-OUTLINE-LABEL: define ptr @test_load_offset( | ||
| ; CHECK-OUTLINE-SAME: ptr [[ARGV:%.*]]) { | ||
| ; CHECK-OUTLINE-NEXT: [[ENTRY:.*:]] | ||
| ; CHECK-OUTLINE-NEXT: [[APP_MEM_MASK:%.*]] = load i64, ptr @__tysan_app_memory_mask, align 4 | ||
| ; CHECK-OUTLINE-NEXT: [[SHADOW_BASE:%.*]] = load i64, ptr @__tysan_shadow_memory_address, align 4 | ||
| ; CHECK-OUTLINE-NEXT: call void @__tysan_instrument_with_shadow_update(ptr null, ptr @__tysan_v1_any_20pointer_o_0, i1 false, i64 8, i32 1) | ||
| ; CHECK-OUTLINE-NEXT: [[L:%.*]] = load ptr, ptr null, align 8, !tbaa [[ANYPTR_TBAA0:![0-9]+]] | ||
| ; CHECK-OUTLINE-NEXT: ret ptr [[L]] | ||
| ; | ||
| entry: | ||
| %l = load ptr, ptr null, align 8, !tbaa !0 | ||
| ret ptr %l | ||
|
|
@@ -61,12 +110,21 @@ entry: | |
| !1 = !{!"any pointer", !2, i64 0} | ||
| !2 = !{!"omnipotent char", !3, i64 0} | ||
| !3 = !{!"Simple C/C++ TBAA"} | ||
| ;. | ||
| ; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind } | ||
| ;. | ||
| ; CHECK: [[PROF0]] = !{!"branch_weights", i32 1, i32 100000} | ||
| ; CHECK: [[ANYPTR_TBAA1]] = !{[[META2:![0-9]+]], [[META2]], i64 0} | ||
| ; CHECK: [[META2]] = !{!"any pointer", [[META3:![0-9]+]], i64 0} | ||
| ; CHECK: [[META3]] = !{!"omnipotent char", [[META4:![0-9]+]], i64 0} | ||
| ; CHECK: [[META4]] = !{!"Simple C/C++ TBAA"} | ||
| ;. | ||
| ; CHECK-INLINE: [[PROF0]] = !{!"branch_weights", i32 1, i32 100000} | ||
| ; CHECK-INLINE: [[ANYPTR_TBAA1]] = !{[[META2:![0-9]+]], [[META2]], i64 0} | ||
| ; CHECK-INLINE: [[META2]] = !{!"any pointer", [[META3:![0-9]+]], i64 0} | ||
| ; CHECK-INLINE: [[META3]] = !{!"omnipotent char", [[META4:![0-9]+]], i64 0} | ||
| ; CHECK-INLINE: [[META4]] = !{!"Simple C/C++ TBAA"} | ||
| ;. | ||
| ; CHECK-OUTLINE: [[ANYPTR_TBAA0]] = !{[[META1:![0-9]+]], [[META1]], i64 0} | ||
| ; CHECK-OUTLINE: [[META1]] = !{!"any pointer", [[META2:![0-9]+]], i64 0} | ||
| ; CHECK-OUTLINE: [[META2]] = !{!"omnipotent char", [[META3:![0-9]+]], i64 0} | ||
| ; CHECK-OUTLINE: [[META3]] = !{!"Simple C/C++ TBAA"} | ||
| ;. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing IR test for outline instrumentation (llvm/test/Instrumentation/TypeSanitizer/basic_outlined.ll) checks __tysan_instrument_with_shadow_update.
Why does this test pass? Are there any memintrinsics here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both __tysan_instrument_mem_inst and __tysan_instrument_with_shadow_update are functions which can be inserted when outlining is enabled, so either (perhaps better if both) can be used to check that the outlining of instrumentation is occurring. I made this test mimicking the minimal one ASan has but on second thought maybe I should make it a bit more verbose to properly check for all possible outlined functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Note the ASan tests were written ages ago, so maybe we know better now :-)