Files
TheRock/compiler/amd-llvm/compiler-rt/test/msan/msan_copy_shadow.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

36 lines
1.4 KiB
C++

// Test that __msan_copy_shadow copies shadow, updates origin and does not touch
// the application memory.
// RUN: %clangxx_msan -fsanitize-memory-track-origins=0 -O0 %s -o %t && not %run %t 2>&1
// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O0 %s -o %t && not %run %t 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=CHECK-%short-stack %s
#include <assert.h>
#include <string.h>
#include <sanitizer/msan_interface.h>
int main() {
char *a = new char[4];
char *b = new char[4];
a[1] = 1;
a[3] = 2;
memset(b, 42, 4);
// Test that __msan_copy_shadow does not touch the contents of b[].
__msan_copy_shadow(b, a, 4);
__msan_unpoison(b, 4);
assert(b[0] == 42 && b[1] == 42 && b[2] == 42 && b[3] == 42);
// Test that __msan_copy_shadow correctly updates shadow and origin of b[].
__msan_copy_shadow(b, a, 4);
assert(__msan_test_shadow(b, 4) == 0);
assert(__msan_test_shadow(b + 1, 3) == 1);
assert(__msan_test_shadow(b + 3, 1) == -1);
__msan_check_mem_is_initialized(b, 4);
// CHECK: use-of-uninitialized-value
// CHECK: {{in main.*msan_copy_shadow.cpp:}}[[@LINE-2]]
// CHECK: Uninitialized value was stored to memory at
// CHECK-FULL-STACK: {{in main.*msan_copy_shadow.cpp:}}[[@LINE-8]]
// CHECK-SHORT-STACK: {{in __msan_copy_shadow .*msan_interceptors.cpp:}}
// CHECK: Uninitialized value was created by a heap allocation
// CHECK: {{in main.*msan_copy_shadow.cpp:}}[[@LINE-23]]
}