clang-tools  7.0.0
ClangdFuzzer.cpp
Go to the documentation of this file.
1 //===-- ClangdFuzzer.cpp - Fuzz clangd ------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file implements a function that runs clangd on a single input.
12 /// This function is then linked into the Fuzzer library.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #include "ClangdLSPServer.h"
17 #include "ClangdServer.h"
18 #include "CodeComplete.h"
19 #include <sstream>
20 #include <stdio.h>
21 
22 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
23  if (size == 0)
24  return 0;
25 
26  clang::clangd::JSONOutput Out(llvm::nulls(), llvm::nulls(),
29  CCOpts.EnableSnippets = false;
31 
32  // Initialize and run ClangdLSPServer.
33  clang::clangd::ClangdLSPServer LSPServer(Out, CCOpts, llvm::None, Opts);
34  // fmemopen isn't portable, but I think we only run the fuzzer on Linux.
35  LSPServer.run(fmemopen(data, size, "r"));
36  return 0;
37 }
Encapsulates output and logs streams and provides thread-safe access to them.
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
bool EnableSnippets
When true, completion items will contain expandable code snippets in completion (e.g.
Definition: CodeComplete.h:40
bool run(std::FILE *In, JSONStreamStyle InputStyle=JSONStreamStyle::Standard)
Run LSP server loop, receiving input for it from In.
This class provides implementation of an LSP server, glueing the JSON dispatch and ClangdServer toget...