-
Notifications
You must be signed in to change notification settings - Fork 769
[DeviceMSAN] Check use-of-uninitialized value on private memory #17309
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
177826a
wip
AllanZyne fc73783
add lit test
AllanZyne 74f6ae3
add lit test
AllanZyne fa33675
fix format
AllanZyne 2c6e46c
wip
AllanZyne a3a123d
Merge branch 'sycl' into review/yang/msan_private_mem_2
AllanZyne 1e376ac
wip
AllanZyne b597351
wip
AllanZyne e13305c
add test
AllanZyne b7f2775
add comments
AllanZyne 12850b3
Merge branch 'sycl' into review/yang/msan_private_mem_2
AllanZyne be43892
fix build
AllanZyne 5e26573
fix merge
AllanZyne fd846cc
fix format
AllanZyne 56b4e34
Merge branch 'sycl' into review/yang/msan_private_mem_2
AllanZyne 45f0111
Revert "fix format"
AllanZyne f667cc6
Revert "Revert "fix format""
AllanZyne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
291 changes: 210 additions & 81 deletions
291
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
llvm/test/Instrumentation/MemorySanitizer/SPIRV/check_large_access_size.ll
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
llvm/test/Instrumentation/MemorySanitizer/SPIRV/check_unsupported_access.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
llvm/test/Instrumentation/MemorySanitizer/SPIRV/instrument_private_mem.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
; RUN: opt < %s -passes=msan -msan-instrumentation-with-call-threshold=0 -msan-eager-checks=1 -msan-spir-privates=1 -msan-poison-stack-with-call=1 -S | FileCheck %s | ||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
define spir_kernel void @MyKernel() sanitize_memory { | ||
; CHECK-LABEL: @MyKernel | ||
entry: | ||
%array = alloca [4 x i32], align 4 | ||
; CHECK: call void @__msan_poison_stack(ptr %array, i64 16) | ||
ret void | ||
} | ||
|
||
%"class.sycl::_V1::range" = type { %"class.sycl::_V1::detail::array" } | ||
%"class.sycl::_V1::detail::array" = type { [1 x i64] } | ||
|
||
define spir_func void @ByValFunc(ptr noundef byval(%"class.sycl::_V1::range") align 8 %_arg_array12) sanitize_memory { | ||
; CHECK-LABEL: @ByValFunc | ||
entry: | ||
; CHECK: %0 = ptrtoint ptr %_arg_array12 to i64 | ||
; CHECK: %1 = call i64 @__msan_get_shadow(i64 %0, i32 0, ptr addrspace(2) null) | ||
; CHECK: %2 = inttoptr i64 %1 to ptr addrspace(1) | ||
; CHECK: call void @llvm.memset.p1.i64(ptr addrspace(1) align 8 %2, i8 0, i64 8, i1 false) | ||
%_arg_array12.ascast = addrspacecast ptr %_arg_array12 to ptr addrspace(4) | ||
ret void | ||
} | ||
|
||
define spir_kernel void @ByValKernel(ptr noundef byval(%"class.sycl::_V1::range") align 8 %_arg_array12) sanitize_memory { | ||
; CHECK-LABEL: @ByValKernel | ||
entry: | ||
; CHECK: %_arg_array12.byval = alloca %"class.sycl::_V1::range", align 8 | ||
; CHECK: call void @__msan_unpoison_stack(ptr %_arg_array12.byval, i64 8), !nosanitize | ||
; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %_arg_array12.byval, ptr align 8 %_arg_array12, i64 8, i1 false), !nosanitize | ||
call void @ByValFunc(ptr %_arg_array12) | ||
ret void | ||
} |
2 changes: 1 addition & 1 deletion
2
llvm/test/Instrumentation/MemorySanitizer/SPIRV/instrument_static_local_mem.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// REQUIRES: linux, cpu || (gpu && level_zero) | ||
// RUN: %{build} %device_msan_flags -O0 -g -o %t1.out | ||
// RUN: %{run} not %t1.out 2>&1 | FileCheck %s | ||
// RUN: %{build} %device_msan_flags -O1 -g -o %t2.out | ||
// RUN: %{run} not %t2.out 2>&1 | FileCheck %s | ||
// RUN: %{build} %device_msan_flags -O2 -g -o %t3.out | ||
// RUN: %{run} not %t3.out 2>&1 | FileCheck %s | ||
|
||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
__attribute__((noinline)) int check(int p) { return p; } | ||
__attribute__((noinline)) int foo(int *p) { return check(*p); } | ||
// CHECK-NOT: [kernel] | ||
// CHECK: DeviceSanitizer: use-of-uninitialized-value | ||
// CHECK: #0 {{foo.*}} {{.*single_private.cpp}}:[[@LINE-3]] | ||
|
||
int main() { | ||
sycl::queue Q; | ||
auto *array = sycl::malloc_device<int>(1, Q); | ||
|
||
Q.submit([&](sycl::handler &h) { | ||
h.single_task<class MyKernel>([=]() { | ||
int p[4]; | ||
*array += foo(p); | ||
}); | ||
}); | ||
Q.wait(); | ||
|
||
sycl::free(array, Q); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.