llvm-project
41 строка · 1.4 Кб
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
20using namespace clang::clangd;
21
22extern "C" int LLVMFuzzerTestOneInput(uint8_t *Data, size_t Size) {
23if (Size == 0)
24return 0;
25
26// fmemopen isn't portable, but I think we only run the fuzzer on Linux.
27std::FILE *In = fmemopen(Data, Size, "r");
28auto Transport = newJSONTransport(In, llvm::nulls(),
29/*InMirror=*/nullptr, /*Pretty=*/false,
30/*Style=*/JSONStreamStyle::Delimited);
31RealThreadsafeFS FS;
32CodeCompleteOptions CCOpts;
33ClangdLSPServer::Options Opts;
34Opts.CodeComplete.EnableSnippets = false;
35Opts.UseDirBasedCDB = false;
36
37// Initialize and run ClangdLSPServer.
38ClangdLSPServer LSPServer(*Transport, FS, Opts);
39LSPServer.run();
40return 0;
41}
42