2017-10-26 18:03:11 +08:00
|
|
|
//===-- ClangdFuzzer.cpp - Fuzz clangd ------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file implements a function that runs clangd on a single input.
|
|
|
|
/// This function is then linked into the Fuzzer library.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangdLSPServer.h"
|
2018-03-10 07:02:22 +08:00
|
|
|
#include "ClangdServer.h"
|
2017-12-12 20:56:46 +08:00
|
|
|
#include "CodeComplete.h"
|
2017-10-26 18:03:11 +08:00
|
|
|
#include <sstream>
|
2018-06-09 04:25:05 +08:00
|
|
|
#include <stdio.h>
|
2017-10-26 18:03:11 +08:00
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
|
2018-07-25 05:50:06 +08:00
|
|
|
if (size == 0)
|
|
|
|
return 0;
|
|
|
|
|
2018-07-22 23:55:57 +08:00
|
|
|
clang::clangd::JSONOutput Out(llvm::nulls(), llvm::nulls(),
|
|
|
|
clang::clangd::Logger::Error, nullptr);
|
2017-12-08 03:04:27 +08:00
|
|
|
clang::clangd::CodeCompleteOptions CCOpts;
|
|
|
|
CCOpts.EnableSnippets = false;
|
2018-03-10 07:02:22 +08:00
|
|
|
clang::clangd::ClangdServer::Options Opts;
|
2017-10-26 18:03:11 +08:00
|
|
|
|
2017-10-26 18:07:04 +08:00
|
|
|
// Initialize and run ClangdLSPServer.
|
2018-08-04 09:51:10 +08:00
|
|
|
clang::clangd::ClangdLSPServer LSPServer(Out, CCOpts, llvm::None, false,
|
|
|
|
Opts);
|
2018-06-09 04:25:05 +08:00
|
|
|
// fmemopen isn't portable, but I think we only run the fuzzer on Linux.
|
|
|
|
LSPServer.run(fmemopen(data, size, "r"));
|
2017-10-26 18:03:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|