1 // RUN: %clangxx_msan -fno-sanitize-memory-param-retval -O0 -g %s -o %t && %run %t
2 // RUN: %clangxx_msan -fno-sanitize-memory-param-retval -DPOISON -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
11 #include <sanitizer/msan_interface.h>
13 constexpr size_t kSize1
= 27;
14 constexpr size_t kSize2
= 7;
18 void dummy(long a
, long b
, long c
, long d
, long e
) {}
20 void poison_stack_and_param() {
26 __attribute__((always_inline
)) int cmp(long a
, long b
) {
35 int compar2(const void *a
, const void *b
) {
38 __msan_check_mem_is_initialized(a
, sizeof(long));
39 __msan_check_mem_is_initialized(b
, sizeof(long));
41 poison_stack_and_param();
42 return cmp(*(long *)a
, *(long *)b
);
45 int compar1(const void *a
, const void *b
) {
48 __msan_check_mem_is_initialized(a
, sizeof(long));
49 __msan_check_mem_is_initialized(b
, sizeof(long));
51 long *p
= new long[kSize2
];
53 for (int i
= 0; i
< kSize2
; ++i
)
54 p
[i
] = i
* 2 + (i
% 3 - 1) * 3;
55 qsort(p
, kSize1
, sizeof(long), compar2
);
56 __msan_check_mem_is_initialized(p
, sizeof(long) * kSize2
);
59 poison_stack_and_param();
60 return cmp(*(long *)a
, *(long *)b
);
63 int main(int argc
, char *argv
[]) {
64 long *p
= new long[kSize1
];
66 for (int i
= 0; i
< kSize1
; ++i
)
67 p
[i
] = i
* 2 + (i
% 3 - 1) * 3;
68 poison_stack_and_param();
70 __msan_poison(p
+ 1, sizeof(long));
71 // CHECK: Uninitialized bytes in __msan_check_mem_is_initialized at offset 0 inside [{{.*}}, 8)
73 qsort(p
, kSize1
, sizeof(long), compar1
);
74 __msan_check_mem_is_initialized(p
, sizeof(long) * kSize1
);
79 qsort(p
, 0, sizeof(long), compar1
);
82 qsort(nullptr, 0, sizeof(long), compar1
);