Skip to content

Commit ce5bfa8

Browse files
authored
[DeviceMSAN] Fix no "noundef" attribute in parameters and return value (#17626)
- Simplify "instrument_global_address_space.ll" test - Handle no "noundef" attribute in arguments and return value
1 parent 55416ca commit ce5bfa8

File tree

3 files changed

+26
-131
lines changed

3 files changed

+26
-131
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5849,7 +5849,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
58495849
if (isa<CallInst>(CB) && cast<CallInst>(CB).isMustTailCall())
58505850
return;
58515851

5852-
if (MayCheckCall && CB.hasRetAttr(Attribute::NoUndef)) {
5852+
// Since Spirv always does eager checking, the shadow of retval must be
5853+
// zeros
5854+
if (SpirOrSpirv || (MayCheckCall && CB.hasRetAttr(Attribute::NoUndef))) {
58535855
setShadow(&CB, getCleanShadow(&CB));
58545856
setOrigin(&CB, getCleanOrigin());
58555857
return;
@@ -5924,7 +5926,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
59245926

59255927
// The caller may still expect information passed over TLS if we pass our
59265928
// check
5927-
if (StoreShadow) {
5929+
if (StoreShadow && !SpirOrSpirv) {
59285930
IRB.CreateAlignedStore(Shadow, ShadowPtr, kShadowTLSAlignment);
59295931
if (MS.TrackOrigins && StoreOrigin)
59305932
IRB.CreateStore(getOrigin(RetVal), getOriginPtrForRetval());
Lines changed: 20 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,36 @@
1-
; RUN: opt < %s -passes=msan -msan-instrumentation-with-call-threshold=0 -msan-eager-checks=1 -S | FileCheck %s
1+
; RUN: opt < %s -passes=msan -msan-instrumentation-with-call-threshold=0 -msan-eager-checks=1 -msan-spir-privates=0 -S | FileCheck %s
22

3-
; ModuleID = 'check_call.cpp'
4-
source_filename = "check_call.cpp"
53
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"
64
target triple = "spir64-unknown-unknown"
75

8-
$_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_E8MyKernel = comdat any
9-
106
; CHECK: @__MsanKernelMetadata = appending dso_local local_unnamed_addr addrspace(1) global
117
; CHECK-SAME: [[ATTR0:#[0-9]+]]
128

13-
; Function Attrs: mustprogress norecurse nounwind sanitize_memory uwtable
14-
define weak_odr dso_local spir_kernel void @_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_E8MyKernel(ptr addrspace(1) noundef align 4 %_arg_array) local_unnamed_addr #0 comdat !srcloc !85 !kernel_arg_buffer_location !86 !sycl_fixed_targets !87 {
15-
; CHECK-LABEL: @_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_E8MyKernel
9+
; CHECK-NOT: _tls
10+
11+
define spir_kernel void @MyKernel(ptr addrspace(1) noundef align 4 %_arg_array) sanitize_memory {
12+
; CHECK-LABEL: define spir_kernel void @MyKernel
1613
entry:
17-
; CHECK-NOT: @__msan_param_tls
18-
%0 = load i32, ptr addrspace(1) %_arg_array, align 4, !tbaa !88
19-
%arrayidx3.i = getelementptr inbounds i8, ptr addrspace(1) %_arg_array, i64 4
20-
; CHECK: @__msan_get_shadow
21-
%1 = load i32, ptr addrspace(1) %arrayidx3.i, align 4, !tbaa !88
22-
%conv.i = sext i32 %1 to i64
23-
%call.i = tail call spir_func noundef i64 @_Z3fooix(i32 noundef %0, i64 noundef %conv.i) #2
24-
%conv4.i = trunc i64 %call.i to i32
25-
store i32 %conv4.i, ptr addrspace(1) %_arg_array, align 4, !tbaa !88
14+
%0 = load i32, ptr addrspace(1) %_arg_array, align 4
15+
; CHECK: %1 = ptrtoint ptr addrspace(1) %_arg_array to i64
16+
; CHECK-NEXT: %2 = call i64 @__msan_get_shadow(i64 %1, i32 1, ptr addrspace(2) null)
17+
; CHECK-NEXT: %3 = inttoptr i64 %2 to ptr addrspace(1)
18+
; CHECK-NEXT: %_msld = load i32, ptr addrspace(1) %3, align 4
19+
; CHECK-NEXT: call void @__msan_maybe_warning_4(i32 zeroext %_msld, i64 zeroext 0, ptr addrspace(2) null, i32 0, ptr addrspace(2) @__msan_kernel)
20+
%call = call spir_func i32 @foo(i32 %0)
21+
; CHECK: %4 = ptrtoint ptr addrspace(1) %_arg_array to i64
22+
; CHECK-NEXT: %5 = call i64 @__msan_get_shadow(i64 %4, i32 1, ptr addrspace(2) null)
23+
; CHECK-NEXT: %6 = inttoptr i64 %5 to ptr addrspace(1)
24+
; CHECK-NEXT: store i32 0, ptr addrspace(1) %6, align 4
25+
store i32 %call, ptr addrspace(1) %_arg_array, align 4
2626
ret void
2727
}
2828

29-
; Function Attrs: mustprogress noinline norecurse nounwind sanitize_memory uwtable
30-
define linkonce_odr dso_local spir_func noundef i64 @_Z3fooix(i32 noundef %data1, i64 noundef %data2) local_unnamed_addr #1 !srcloc !92 {
31-
; CHECK-LABEL: @_Z3fooix
29+
define spir_func i32 @foo(i32 %data) sanitize_memory {
30+
; CHECK-LABEL: define spir_func i32 @foo
3231
entry:
33-
%conv = sext i32 %data1 to i64
34-
%add = add nsw i64 %data2, %conv
35-
ret i64 %add
32+
ret i32 %data
3633
}
3734

3835
; CHECK: attributes [[ATTR0]]
3936
; CHECK-SAME: "sycl-device-global-size"="32" "sycl-device-image-scope" "sycl-host-access"="0" "sycl-unique-id"="_Z20__MsanKernelMetadata"
40-
41-
attributes #0 = { mustprogress norecurse nounwind sanitize_memory uwtable "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="check_call.cpp" "sycl-single-task" "uniform-work-group-size"="true" }
42-
attributes #1 = { mustprogress noinline norecurse nounwind sanitize_memory uwtable "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
43-
attributes #2 = { nounwind }
44-
45-
!llvm.module.flags = !{!0, !1, !2, !3}
46-
!opencl.spir.version = !{!4}
47-
!spirv.Source = !{!5}
48-
!sycl_aspects = !{!6, !7, !8, !9, !10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37, !38, !39, !40, !41, !42, !43, !44, !45, !46, !47, !48, !49, !50, !51, !52, !53, !54, !55, !56, !57, !58, !59, !60, !61, !62, !63, !64, !65, !66, !67, !68, !69, !70, !71, !72, !73, !74, !75, !76, !77, !78, !79, !80, !81, !82, !83}
49-
!llvm.ident = !{!84}
50-
51-
!0 = !{i32 1, !"wchar_size", i32 4}
52-
!1 = !{i32 1, !"sycl-device", i32 1}
53-
!2 = !{i32 7, !"uwtable", i32 2}
54-
!3 = !{i32 7, !"frame-pointer", i32 2}
55-
!4 = !{i32 1, i32 2}
56-
!5 = !{i32 4, i32 100000}
57-
!6 = !{!"cpu", i32 1}
58-
!7 = !{!"gpu", i32 2}
59-
!8 = !{!"accelerator", i32 3}
60-
!9 = !{!"custom", i32 4}
61-
!10 = !{!"fp16", i32 5}
62-
!11 = !{!"fp64", i32 6}
63-
!12 = !{!"image", i32 9}
64-
!13 = !{!"online_compiler", i32 10}
65-
!14 = !{!"online_linker", i32 11}
66-
!15 = !{!"queue_profiling", i32 12}
67-
!16 = !{!"usm_device_allocations", i32 13}
68-
!17 = !{!"usm_host_allocations", i32 14}
69-
!18 = !{!"usm_shared_allocations", i32 15}
70-
!19 = !{!"usm_system_allocations", i32 17}
71-
!20 = !{!"ext_intel_pci_address", i32 18}
72-
!21 = !{!"ext_intel_gpu_eu_count", i32 19}
73-
!22 = !{!"ext_intel_gpu_eu_simd_width", i32 20}
74-
!23 = !{!"ext_intel_gpu_slices", i32 21}
75-
!24 = !{!"ext_intel_gpu_subslices_per_slice", i32 22}
76-
!25 = !{!"ext_intel_gpu_eu_count_per_subslice", i32 23}
77-
!26 = !{!"ext_intel_max_mem_bandwidth", i32 24}
78-
!27 = !{!"ext_intel_mem_channel", i32 25}
79-
!28 = !{!"usm_atomic_host_allocations", i32 26}
80-
!29 = !{!"usm_atomic_shared_allocations", i32 27}
81-
!30 = !{!"atomic64", i32 28}
82-
!31 = !{!"ext_intel_device_info_uuid", i32 29}
83-
!32 = !{!"ext_oneapi_srgb", i32 30}
84-
!33 = !{!"ext_oneapi_native_assert", i32 31}
85-
!34 = !{!"host_debuggable", i32 32}
86-
!35 = !{!"ext_intel_gpu_hw_threads_per_eu", i32 33}
87-
!36 = !{!"ext_oneapi_cuda_async_barrier", i32 34}
88-
!37 = !{!"ext_intel_free_memory", i32 36}
89-
!38 = !{!"ext_intel_device_id", i32 37}
90-
!39 = !{!"ext_intel_memory_clock_rate", i32 38}
91-
!40 = !{!"ext_intel_memory_bus_width", i32 39}
92-
!41 = !{!"emulated", i32 40}
93-
!42 = !{!"ext_intel_legacy_image", i32 41}
94-
!43 = !{!"ext_oneapi_bindless_images", i32 42}
95-
!44 = !{!"ext_oneapi_bindless_images_shared_usm", i32 43}
96-
!45 = !{!"ext_oneapi_bindless_images_1d_usm", i32 44}
97-
!46 = !{!"ext_oneapi_bindless_images_2d_usm", i32 45}
98-
!47 = !{!"ext_oneapi_external_memory_import", i32 46}
99-
!48 = !{!"ext_oneapi_external_semaphore_import", i32 48}
100-
!49 = !{!"ext_oneapi_mipmap", i32 50}
101-
!50 = !{!"ext_oneapi_mipmap_anisotropy", i32 51}
102-
!51 = !{!"ext_oneapi_mipmap_level_reference", i32 52}
103-
!52 = !{!"ext_intel_esimd", i32 53}
104-
!53 = !{!"ext_oneapi_ballot_group", i32 54}
105-
!54 = !{!"ext_oneapi_fixed_size_group", i32 55}
106-
!55 = !{!"ext_oneapi_opportunistic_group", i32 56}
107-
!56 = !{!"ext_oneapi_tangle_group", i32 57}
108-
!57 = !{!"ext_intel_matrix", i32 58}
109-
!58 = !{!"ext_oneapi_is_composite", i32 59}
110-
!59 = !{!"ext_oneapi_is_component", i32 60}
111-
!60 = !{!"ext_oneapi_graph", i32 61}
112-
!61 = !{!"ext_intel_fpga_task_sequence", i32 62}
113-
!62 = !{!"ext_oneapi_limited_graph", i32 63}
114-
!63 = !{!"ext_oneapi_private_alloca", i32 64}
115-
!64 = !{!"ext_oneapi_cubemap", i32 65}
116-
!65 = !{!"ext_oneapi_cubemap_seamless_filtering", i32 66}
117-
!66 = !{!"ext_oneapi_bindless_sampled_image_fetch_1d_usm", i32 67}
118-
!67 = !{!"ext_oneapi_bindless_sampled_image_fetch_1d", i32 68}
119-
!68 = !{!"ext_oneapi_bindless_sampled_image_fetch_2d_usm", i32 69}
120-
!69 = !{!"ext_oneapi_bindless_sampled_image_fetch_2d", i32 70}
121-
!70 = !{!"ext_oneapi_bindless_sampled_image_fetch_3d", i32 72}
122-
!71 = !{!"ext_oneapi_queue_profiling_tag", i32 73}
123-
!72 = !{!"ext_oneapi_virtual_mem", i32 74}
124-
!73 = !{!"ext_oneapi_cuda_cluster_group", i32 75}
125-
!74 = !{!"ext_oneapi_image_array", i32 76}
126-
!75 = !{!"ext_oneapi_unique_addressing_per_dim", i32 77}
127-
!76 = !{!"ext_oneapi_bindless_images_sample_1d_usm", i32 78}
128-
!77 = !{!"ext_oneapi_bindless_images_sample_2d_usm", i32 79}
129-
!78 = !{!"ext_oneapi_atomic16", i32 80}
130-
!79 = !{!"ext_oneapi_virtual_functions", i32 81}
131-
!80 = !{!"host", i32 0}
132-
!81 = !{!"int64_base_atomics", i32 7}
133-
!82 = !{!"int64_extended_atomics", i32 8}
134-
!83 = !{!"usm_restricted_shared_allocations", i32 16}
135-
!84 = !{!"clang version 20.0.0git (https://github.com/intel/llvm.git 7384106e6410c6f038b2a9d6367a32b55278c638)"}
136-
!85 = !{i32 563}
137-
!86 = !{i32 -1}
138-
!87 = !{}
139-
!88 = !{!89, !89, i64 0}
140-
!89 = !{!"int", !90, i64 0}
141-
!90 = !{!"omnipotent char", !91, i64 0}
142-
!91 = !{!"Simple C++ TBAA"}
143-
!92 = !{i32 345}

unified-runtime/source/loader/layers/sanitizer/msan/msan_ddi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ ur_result_t UR_APICALL urEnqueueUSMMemcpy(
14961496
/// must not refer to an element of the phEventWaitList array.
14971497
ur_event_handle_t *phEvent) {
14981498
auto pfnUSMMemcpy = getContext()->urDdiTable.Enqueue.pfnUSMMemcpy;
1499-
getContext()->logger.debug("==== pfnUSMMemcpy");
1499+
getContext()->logger.debug("==== urEnqueueUSMMemcpy");
15001500

15011501
std::vector<ur_event_handle_t> Events;
15021502
ur_event_handle_t Event{};
@@ -1637,7 +1637,7 @@ ur_result_t UR_APICALL urEnqueueUSMMemcpy2D(
16371637
/// phEvent must not refer to an element of the phEventWaitList array.
16381638
ur_event_handle_t *phEvent) {
16391639
auto pfnUSMMemcpy2D = getContext()->urDdiTable.Enqueue.pfnUSMMemcpy2D;
1640-
getContext()->logger.debug("==== pfnUSMMemcpy2D");
1640+
getContext()->logger.debug("==== urEnqueueUSMMemcpy2D");
16411641

16421642
std::vector<ur_event_handle_t> Events;
16431643
ur_event_handle_t Event{};

0 commit comments

Comments
 (0)