Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / vararg.cpp
blob32f4c5db4ed9d454b516cb2ba0153ab326c5e1cd
1 // RUN: %clangxx_msan -fno-sanitize-memory-param-retval -fsanitize-memory-track-origins=0 -O3 %s -o %t && \
2 // RUN: not %run %t va_arg_tls >%t.out 2>&1
3 // RUN: FileCheck %s --check-prefix=CHECK < %t.out
5 // RUN: %clangxx_msan -fno-sanitize-memory-param-retval -fsanitize-memory-track-origins=0 -O3 %s -o %t && \
6 // RUN: not %run %t overflow >%t.out 2>&1
7 // RUN: FileCheck %s --check-prefix=CHECK < %t.out
9 // RUN: %clangxx_msan -fno-sanitize-memory-param-retval -fsanitize-memory-track-origins=2 -O3 %s -o %t && \
10 // RUN: not %run %t va_arg_tls >%t.out 2>&1
11 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN < %t.out
13 // RUN: %clangxx_msan -fno-sanitize-memory-param-retval -fsanitize-memory-track-origins=2 -O3 %s -o %t && \
14 // RUN: not %run %t overflow >%t.out 2>&1
15 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN < %t.out
17 // Check that shadow and origin are passed through va_args.
19 // Copying origins on AArch64, LoongArch64, MIPS and PowerPC isn't supported yet.
20 // XFAIL: target={{(aarch64|loongarch64|mips|powerpc64).*}}
22 #include <stdarg.h>
23 #include <string.h>
25 __attribute__((noinline))
26 int sum(int n, ...) {
27 va_list args;
28 int i, sum = 0, arg;
29 volatile int temp;
30 va_start(args, n);
31 for (i = 0; i < n; i++) {
32 arg = va_arg(args, int);
33 sum += arg;
35 va_end(args);
36 return sum;
39 int main(int argc, char *argv[]) {
40 volatile int uninit;
41 volatile int a = 1, b = 2;
42 if (argc == 2) {
43 // Shadow/origin will be passed via va_arg_tls/va_arg_origin_tls.
44 if (strcmp(argv[1], "va_arg_tls") == 0) {
45 return sum(3, uninit, a, b);
47 // Shadow/origin of |uninit| will be passed via overflow area.
48 if (strcmp(argv[1], "overflow") == 0) {
49 return sum(7,
50 a, a, a, a, a, a, uninit
54 return 0;
57 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
58 // CHECK-ORIGIN: Uninitialized value was created by an allocation of 'uninit' in the stack frame