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