Taints the non-acquire RMW's store address with the load part
[oota-llvm.git] / lib / Fuzzer / test / SwitchTest.cpp
1 // Simple test for a fuzzer. The fuzzer must find the interesting switch value.
2 #include <cstdint>
3 #include <cstdlib>
4 #include <cstdio>
5 #include <cstring>
6 #include <cstddef>
7
8 static volatile int Sink;
9
10 template<class T>
11 bool Switch(const uint8_t *Data, size_t Size) {
12   T X;
13   if (Size < sizeof(X)) return false;
14   memcpy(&X, Data, sizeof(X));
15   switch (X) {
16     case 1: Sink = __LINE__; break;
17     case 101: Sink = __LINE__; break;
18     case 1001: Sink = __LINE__; break;
19     case 10001: Sink = __LINE__; break;
20     case 100001: Sink = __LINE__; break;
21     case 1000001: Sink = __LINE__; break;
22     case 10000001: Sink = __LINE__; break;
23     case 100000001: return true;
24   }
25   return false;
26 }
27
28 bool ShortSwitch(const uint8_t *Data, size_t Size) {
29   short X;
30   if (Size < sizeof(short)) return false;
31   memcpy(&X, Data, sizeof(short));
32   switch(X) {
33     case 42: Sink = __LINE__; break;
34     case 402: Sink = __LINE__; break;
35     case 4002: Sink = __LINE__; break;
36     case 5002: Sink = __LINE__; break;
37     case 7002: Sink = __LINE__; break;
38     case 9002: Sink = __LINE__; break;
39     case 14002: Sink = __LINE__; break;
40     case 21402: return true;
41   }
42   return false;
43 }
44
45 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
46   if (Size >= 4  && Switch<int>(Data, Size) &&
47       Size >= 12 && Switch<uint64_t>(Data + 4, Size - 4) &&
48       Size >= 14 && ShortSwitch(Data + 12, 2)
49     ) {
50     fprintf(stderr, "BINGO; Found the target, exiting\n");
51     exit(1);
52   }
53   return 0;
54 }
55