Mercurial > hg > CbC > CbC_llvm
annotate projects/compiler-rt/test/fuzzer/SimpleCmpTest.cpp @ 181:df311c476dd5
CreateIdentifierInfo in ParseCbC (not yet worked)
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 31 May 2020 12:30:11 +0900 |
parents | f476a9ba4795 |
children |
rev | line source |
---|---|
131
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
1 // This file is distributed under the University of Illinois Open Source |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
2 // License. See LICENSE.TXT for details. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
3 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
4 // Simple test for a fuzzer. The fuzzer must find several narrow ranges. |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
5 #include <cstdint> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
6 #include <cstdio> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
7 #include <cstdlib> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
8 #include <cstring> |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
9 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
10 extern int AllLines[]; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
11 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
12 bool PrintOnce(int Line) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
13 if (!AllLines[Line]) |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
14 fprintf(stderr, "Seen line %d\n", Line); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
15 AllLines[Line] = 1; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
16 return true; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
17 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
18 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
19 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
20 if (Size != 22) return 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
21 uint64_t x = 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
22 int64_t y = 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
23 int32_t z = 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
24 uint16_t a = 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
25 memcpy(&x, Data, 8); // 8 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
26 memcpy(&y, Data + 8, 8); // 16 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
27 memcpy(&z, Data + 16, sizeof(z)); // 20 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
28 memcpy(&a, Data + 20, sizeof(a)); // 22 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
29 const bool k32bit = sizeof(void*) == 4; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
30 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
31 if ((k32bit || x > 1234567890) && PrintOnce(__LINE__) && |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
32 (k32bit || x < 1234567895) && PrintOnce(__LINE__) && |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
33 a == 0x4242 && PrintOnce(__LINE__) && |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
34 (k32bit || y >= 987654321) && PrintOnce(__LINE__) && |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
35 (k32bit || y <= 987654325) && PrintOnce(__LINE__) && |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
36 z < -10000 && PrintOnce(__LINE__) && |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
37 z >= -10005 && PrintOnce(__LINE__) && |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
38 z != -10003 && PrintOnce(__LINE__) && |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
39 true) { |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
40 fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n", |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
41 Size, x, y, z, a); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
42 exit(1); |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
43 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
44 return 0; |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
45 } |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
46 |
f476a9ba4795
http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
mir3636
parents:
diff
changeset
|
47 int AllLines[__LINE__ + 1]; // Must be the last line. |