clang-tools 8.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 <cstdio>
20 #include <sstream>
21
22 using namespace clang::clangd;
23
24 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
25 if (size == 0)
26 return 0;
27
28 // fmemopen isn't portable, but I think we only run the fuzzer on Linux.
29 std::FILE *In = fmemopen(data, size, "r");
30 auto Transport = newJSONTransport(In, llvm::nulls(),
31 /*InMirror=*/nullptr, /*Pretty=*/false,
32 /*Style=*/JSONStreamStyle::Standard);
33 CodeCompleteOptions CCOpts;
34 CCOpts.EnableSnippets = false;
35 ClangdServer::Options Opts;
36
37 // Initialize and run ClangdLSPServer.
38 ClangdLSPServer LSPServer(*Transport, CCOpts, llvm::None, false, Opts);
39 LSPServer.run();
40 return 0;
41 }
ClangdServer.h
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
Definition: ClangdFuzzer.cpp:24
clang::clangd::CodeCompleteOptions::EnableSnippets
bool EnableSnippets
When true, completion items will contain expandable code snippets in completion (e.g.
Definition: CodeComplete.h:47
clang::clangd::Transport
Definition: Transport.h:35
clang::clangd::ClangdLSPServer::run
bool run()
Run LSP server loop, communicating with the Transport provided in the constructor.
Definition: ClangdLSPServer.cpp:764
clang::clangd::TextDocumentSyncKind::None
Documents should not be synced at all.
CodeComplete.h
clang::clangd
Definition: AST.cpp:22
clang::clangd::CodeCompleteOptions
Definition: CodeComplete.h:40
clang::clangd::newJSONTransport
std::unique_ptr< Transport > newJSONTransport(std::FILE *In, llvm::raw_ostream &Out, llvm::raw_ostream *InMirror, bool Pretty, JSONStreamStyle Style)
Definition: JSONTransport.cpp:293
clang::clangd::Standard
Definition: Transport.h:68
clang::clangd::ClangdServer::Options
Definition: ClangdServer.h:67
clang::clangd::ClangdLSPServer
This class exposes ClangdServer&#39;s capabilities via Language Server Protocol.
Definition: ClangdLSPServer.h:34
ClangdLSPServer.h