1 //===-- dictionary.c - Generate fuzzing dictionary for clang --------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This binary emits a fuzzing dictionary describing strings that are
10 // significant to the clang parser: keywords and other tokens.
12 // The dictionary can be used by a fuzzer to reach interesting parser states
15 // The output is a single-file dictionary supported by libFuzzer and AFL:
16 // https://llvm.org/docs/LibFuzzer.html#dictionaries
18 //===----------------------------------------------------------------------===//
22 static void emit(const char *Name
, const char *Spelling
) {
23 static char Hex
[] = "0123456789abcdef";
25 printf("%s=\"", Name
);
27 while ((C
= *Spelling
++)) {
28 if (C
< 32 || C
== '"' || C
== '\\')
29 printf("\\x%c%c", Hex
[C
>>4], Hex
[C
%16]);
36 int main(int argc
, char **argv
) {
37 #define PUNCTUATOR(Name, Spelling) emit(#Name, Spelling);
38 #define KEYWORD(Name, Criteria) emit(#Name, #Name);
39 #define PPKEYWORD(Name) emit(#Name, #Name);
40 #define CXX_KEYWORD_OPERATOR(Name, Equivalent) emit(#Name, #Name);
41 #define OBJC_AT_KEYWORD(Name) emit(#Name, #Name);
42 #define ALIAS(Spelling, Equivalent, Criteria) emit(Spelling, Spelling);
43 #include "clang/Basic/TokenKinds.def"
44 // Some other sub-token chunks significant to the lexer.
45 emit("ucn16", "\\u0000");
46 emit("ucn32", "\\U00000000");
47 emit("rawstart", "R\"(");
48 emit("rawend", ")\"");
51 emit("u8quote", "u8\"");
52 emit("u16quote", "u\"");
53 emit("u32quote", "U\"");
54 emit("esc_nl", "\\\n");