blob: 1c504da4282548a684985bc01ba7657d020d348e [file] [log] [blame]
Stephen Hines6d186232014-11-26 17:56:19 -08001// ParamTLS has limited size. Everything that does not fit is considered fully
2// initialized.
3
Pirama Arumuga Nainar7c915052015-04-08 08:58:29 -07004// 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
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08007//
8// AArch64 fails with:
9// void f801(S<801>): Assertion `__msan_test_shadow(&s, sizeof(s)) == -1' failed
10// XFAIL: aarch64
Stephen Hines6d186232014-11-26 17:56:19 -080011
12#include <sanitizer/msan_interface.h>
13#include <assert.h>
14
15// This test assumes that ParamTLS size is 800 bytes.
16
17// This test passes poisoned values through function argument list.
18// In case of overflow, argument is unpoisoned.
19#define OVERFLOW(x) assert(__msan_test_shadow(&x, sizeof(x)) == -1)
20// In case of no overflow, it is still poisoned.
21#define NO_OVERFLOW(x) assert(__msan_test_shadow(&x, sizeof(x)) == 0)
22
23template<int N>
24struct S {
25 char x[N];
26};
27
28void f100(S<100> s) {
29 NO_OVERFLOW(s);
30}
31
32void f800(S<800> s) {
33 NO_OVERFLOW(s);
34}
35
36void f801(S<801> s) {
37 OVERFLOW(s);
38}
39
40void f1000(S<1000> s) {
41 OVERFLOW(s);
42}
43
44void f_many(int a, double b, S<800> s, int c, double d) {
45 NO_OVERFLOW(a);
46 NO_OVERFLOW(b);
47 OVERFLOW(s);
48 OVERFLOW(c);
49 OVERFLOW(d);
50}
51
52// -8 bytes for "int a", aligned by 8
53// -2 to make "int c" a partial fit
54void f_many2(int a, S<800 - 8 - 2> s, int c, double d) {
55 NO_OVERFLOW(a);
56 NO_OVERFLOW(s);
57 OVERFLOW(c);
58 OVERFLOW(d);
59}
60
61int main(void) {
62 S<100> s100;
63 S<800> s800;
64 S<801> s801;
65 S<1000> s1000;
66 f100(s100);
67 f800(s800);
68 f801(s801);
69 f1000(s1000);
70
71 int i;
72 double d;
73 f_many(i, d, s800, i, d);
74
75 S<800 - 8 - 2> s788;
76 f_many2(i, s788, i, d);
77 return 0;
78}