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

source code of compiler-rt/test/msan/libatomic_load_exceptions.cpp