Coverage Report

Created: 2022-05-17 06:19

/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
480
static void emit(const char *Name, const char *Spelling) {
23
480
  static char Hex[] = "0123456789abcdef";
24
25
480
  printf("%s=\"", Name);
26
480
  unsigned char C;
27
4.91k
  while ((C = *Spelling++)) {
28
4.43k
    if (C < 32 || 
C == '"'4.43k
||
C == '\\'4.43k
)
29
10
      printf("\\x%c%c", Hex[C>>4], Hex[C%16]);
30
4.42k
    else
31
4.42k
      printf("%c", C);
32
4.43k
  }
33
480
  printf("\"\n");
34
480
}
35
36
1
int main(int argc, char **argv) {
37
57
#define PUNCTUATOR(Name, Spelling) emit(#Name, Spelling);
38
280
#define KEYWORD(Name, Criteria) emit(#Name, #Name);
39
26
#define PPKEYWORD(Name) emit(#Name, #Name);
40
11
#define CXX_KEYWORD_OPERATOR(Name, Equivalent) emit(#Name, #Name);
41
27
#define OBJC_AT_KEYWORD(Name) emit(#Name, #Name);
42
68
#define ALIAS(Spelling, Equivalent, Criteria) emit(Spelling, Spelling);
43
1
#include "clang/Basic/TokenKinds.def"
44
  // Some other sub-token chunks significant to the lexer.
45
1
  emit("ucn16", "\\u0000");
46
1
  emit("ucn32", "\\U00000000");
47
1
  emit("rawstart", "R\"(");
48
1
  emit("rawend", ")\"");
49
1
  emit("quote", "\"");
50
1
  emit("squote", "'");
51
1
  emit("u8quote", "u8\"");
52
1
  emit("u16quote", "u\"");
53
1
  emit("u32quote", "U\"");
54
1
  emit("esc_nl", "\\\n");
55
1
  emit("hex", "0x");
56
1
}
57