1 // ParamTLS has limited size. Everything that does not fit is considered fully
2 // initialized.
3
4 // RUN: %clangxx_msan -O0 %s -o %t && %run %t
5 // RUN: %clangxx_msan -fsanitize-memory-track-origins -O0 %s -o %t && %run %t
6 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O0 %s -o %t && %run %t
7
8 #include <sanitizer/msan_interface.h>
9 #include <assert.h>
10
11 // This test assumes that ParamTLS size is 800 bytes.
12
13 // This test passes poisoned values through function argument list.
14 // In case of overflow, argument is unpoisoned.
15 #define OVERFLOW(x) assert(__msan_test_shadow(&x, sizeof(x)) == -1)
16 // In case of no overflow, it is still poisoned.
17 #define NO_OVERFLOW(x) assert(__msan_test_shadow(&x, sizeof(x)) == 0)
18
19 template<int N>
20 struct S {
21 char x[N];
22 };
23
f100(S<100> s)24 void f100(S<100> s) {
25 NO_OVERFLOW(s);
26 }
27
f800(S<800> s)28 void f800(S<800> s) {
29 NO_OVERFLOW(s);
30 }
31
f801(S<801> s)32 void f801(S<801> s) {
33 OVERFLOW(s);
34 }
35
f1000(S<1000> s)36 void f1000(S<1000> s) {
37 OVERFLOW(s);
38 }
39
f_many(int a,double b,S<800> s,int c,double d)40 void f_many(int a, double b, S<800> s, int c, double d) {
41 NO_OVERFLOW(a);
42 NO_OVERFLOW(b);
43 OVERFLOW(s);
44 OVERFLOW(c);
45 OVERFLOW(d);
46 }
47
48 // -8 bytes for "int a", aligned by 8
49 // -2 to make "int c" a partial fit
f_many2(int a,S<800-8-2> s,int c,double d)50 void f_many2(int a, S<800 - 8 - 2> s, int c, double d) {
51 NO_OVERFLOW(a);
52 NO_OVERFLOW(s);
53 OVERFLOW(c);
54 OVERFLOW(d);
55 }
56
main(void)57 int main(void) {
58 S<100> s100;
59 S<800> s800;
60 S<801> s801;
61 S<1000> s1000;
62 f100(s100);
63 f800(s800);
64 f801(s801);
65 f1000(s1000);
66
67 int i;
68 double d;
69 f_many(i, d, s800, i, d);
70
71 S<800 - 8 - 2> s788;
72 f_many2(i, s788, i, d);
73 return 0;
74 }
75