/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/clang-fuzzer/dictionary/dictionary.c
Line | Count | Source |
1 | | //===-- dictionary.c - Generate fuzzing dictionary for clang --------------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This binary emits a fuzzing dictionary describing strings that are |
10 | | // significant to the clang parser: keywords and other tokens. |
11 | | // |
12 | | // The dictionary can be used by a fuzzer to reach interesting parser states |
13 | | // much more quickly. |
14 | | // |
15 | | // The output is a single-file dictionary supported by libFuzzer and AFL: |
16 | | // https://llvm.org/docs/LibFuzzer.html#dictionaries |
17 | | // |
18 | | //===----------------------------------------------------------------------===// |
19 | | |
20 | | #include <stdio.h> |
21 | | |
22 | 517 | static void emit(const char *Name, const char *Spelling) { |
23 | 517 | static char Hex[] = "0123456789abcdef"; |
24 | | |
25 | 517 | printf("%s=\"", Name); |
26 | 517 | unsigned char C; |
27 | 5.57k | while ((C = *Spelling++)) { |
28 | 5.06k | if (C < 32 || C == '"'5.06k || C == '\\'5.05k ) |
29 | 10 | printf("\\x%c%c", Hex[C>>4], Hex[C%16]); |
30 | 5.05k | else |
31 | 5.05k | printf("%c", C); |
32 | 5.06k | } |
33 | 517 | printf("\"\n"); |
34 | 517 | } |
35 | | |
36 | 93 | int main(int argc, char **argv) { |
37 | 5.30k | #define PUNCTUATOR(Name, Spelling) emit(#Name, Spelling); |
38 | 29.4k | #define KEYWORD(Name, Criteria) emit(#Name, #Name); |
39 | 2.41k | #define PPKEYWORD(Name) emit(#Name, #Name); |
40 | 1.02k | #define CXX_KEYWORD_OPERATOR(Name, Equivalent) emit(#Name, #Name); |
41 | 2.51k | #define OBJC_AT_KEYWORD(Name) emit(#Name, #Name); |
42 | 6.32k | #define ALIAS(Spelling, Equivalent, Criteria) emit(Spelling, Spelling); |
43 | 93 | #include "clang/Basic/TokenKinds.def" |
44 | | // Some other sub-token chunks significant to the lexer. |
45 | 93 | emit("ucn16", "\\u0000"); |
46 | 93 | emit("ucn32", "\\U00000000"); |
47 | 93 | emit("rawstart", "R\"("); |
48 | 93 | emit("rawend", ")\""); |
49 | 93 | emit("quote", "\""); |
50 | 93 | emit("squote", "'"); |
51 | 93 | emit("u8quote", "u8\""); |
52 | 93 | emit("u16quote", "u\""); |
53 | 93 | emit("u32quote", "U\""); |
54 | 93 | emit("esc_nl", "\\\n"); |
55 | 93 | emit("hex", "0x"); |
56 | 93 | } |
57 | | |