1// RUN: %clang_msan -fsanitize-memory-track-origins=2 %libatomic -DTEST_STORE -O0 %s -o %t && %run %t 2>&1
2// RUN: %clang_msan -fsanitize-memory-track-origins=0 %libatomic -DTEST_LOAD -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3// RUN: %clang_msan -fsanitize-memory-track-origins=2 %libatomic -DTEST_LOAD -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SHADOW
4
5// PPC has no libatomic
6// UNSUPPORTED: powerpc64-target-arch
7// UNSUPPORTED: powerpc64le-target-arch
8
9#include <sanitizer/msan_interface.h>
10#include <stdatomic.h>
11
12typedef struct __attribute((packed)) {
13 uint8_t val[3];
14} i24;
15
16void copy(i24 *dst, i24 *src);
17
18int main() {
19 i24 uninit;
20 i24 init = {0};
21
22 __msan_check_mem_is_initialized(x: &init, size: 3);
23 copy(dst: &init, src: &uninit);
24 __msan_check_mem_is_initialized(x: &init, size: 3);
25}
26
27void copy(i24 *dst, i24 *src) {
28#ifdef TEST_LOAD
29 __atomic_load(src, dst, __ATOMIC_RELAXED);
30
31 // CHECK: MemorySanitizer: use-of-uninitialized-value
32 // CHECK: #0 {{0x[a-f0-9]+}} in main{{.*}}libatomic.c:[[@LINE-8]]
33
34 // CHECK-SHADOW: Uninitialized value was stored to memory at
35 // CHECK-SHADOW: #0 {{0x[a-f0-9]+}} in copy{{.*}}libatomic.c:[[@LINE-6]]
36#endif
37#ifdef TEST_STORE
38 // Store always writes a clean shadow
39 __atomic_store(src, dst, __ATOMIC_RELAXED);
40#endif
41}
42

source code of compiler-rt/test/msan/libatomic.c