clang-tools  14.0.0git
clangd-fuzzer.cpp
Go to the documentation of this file.
1 //===-- ClangdFuzzer.cpp - Fuzz clangd ------------------------------------===//
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 /// \file
10 /// This file implements a function that runs clangd on a single input.
11 /// This function is then linked into the Fuzzer library.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "ClangdLSPServer.h"
16 #include "ClangdServer.h"
17 #include "support/ThreadsafeFS.h"
18 #include <cstdio>
19 
20 using namespace clang::clangd;
21 
22 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
23  if (size == 0)
24  return 0;
25 
26  // fmemopen isn't portable, but I think we only run the fuzzer on Linux.
27  std::FILE *In = fmemopen(data, size, "r");
28  auto Transport = newJSONTransport(In, llvm::nulls(),
29  /*InMirror=*/nullptr, /*Pretty=*/false,
30  /*Style=*/JSONStreamStyle::Delimited);
32  CodeCompleteOptions CCOpts;
34  Opts.CodeComplete.EnableSnippets = false;
35  Opts.UseDirBasedCDB = false;
36 
37  // Initialize and run ClangdLSPServer.
38  ClangdLSPServer LSPServer(*Transport, FS, Opts);
39  LSPServer.run();
40  return 0;
41 }
clang::clangd::ClangdLSPServer::run
bool run()
Run LSP server loop, communicating with the Transport provided in the constructor.
Definition: ClangdLSPServer.cpp:1508
clang::clangd::RealThreadsafeFS
Definition: ThreadsafeFS.h:49
clang::clangd
Definition: AST.cpp:41
clang::clangd::ClangdLSPServer::Options
Definition: ClangdLSPServer.h:44
ThreadsafeFS.h
clang::clangd::ClangdLSPServer
This class exposes ClangdServer's capabilities via Language Server Protocol.
Definition: ClangdLSPServer.h:41
ClangdLSPServer.h
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
Definition: clangd-fuzzer.cpp:22
clang::clangd::CodeCompleteOptions
Definition: CodeComplete.h:45
clang::clangd::Transport
Definition: Transport.h:35
clang::clangd::CodeCompleteOptions::EnableSnippets
bool EnableSnippets
When true, completion items will contain expandable code snippets in completion (e....
Definition: CodeComplete.h:52
ClangdServer.h
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:323
clang::clangd::Delimited
@ Delimited
Definition: Transport.h:70