forked from OSchip/llvm-project
[clangd] Add a simple fuzzer. It crashes a lot :)
llvm-svn: 316649
This commit is contained in:
parent
d605f414db
commit
09113ae2c5
|
@ -28,4 +28,7 @@ add_clang_library(clangDaemon
|
|||
${LLVM_PTHREAD_LIB}
|
||||
)
|
||||
|
||||
if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE )
|
||||
add_subdirectory(fuzzer)
|
||||
endif()
|
||||
add_subdirectory(tool)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
|
||||
|
||||
set(LLVM_LINK_COMPONENTS support)
|
||||
|
||||
if(LLVM_USE_SANITIZE_COVERAGE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
|
||||
endif()
|
||||
|
||||
add_clang_executable(clangd-fuzzer
|
||||
EXCLUDE_FROM_ALL
|
||||
ClangdFuzzer.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(clangd-fuzzer
|
||||
clangBasic
|
||||
clangDaemon
|
||||
clangFormat
|
||||
clangFrontend
|
||||
clangSema
|
||||
clangTooling
|
||||
clangToolingCore
|
||||
${LLVM_LIB_FUZZING_ENGINE}
|
||||
)
|
|
@ -0,0 +1,34 @@
|
|||
//===-- 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"
|
||||
#include "llvm/Support/Program.h"
|
||||
#include <sstream>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
|
||||
/// Change stdin to binary to not lose \r\n on windows.
|
||||
llvm::sys::ChangeStdinToBinary();
|
||||
|
||||
clang::clangd::JSONOutput Out(llvm::nulls(), llvm::nulls(), nullptr);
|
||||
|
||||
/// Initialize and run ClangdLSPServer.
|
||||
clang::clangd::ClangdLSPServer LSPServer(
|
||||
Out, clang::clangd::getDefaultAsyncThreadsCount(),
|
||||
/*EnableSnippets=*/false, llvm::None, llvm::None);
|
||||
|
||||
std::istringstream In(std::string(reinterpret_cast<char *>(data), size));
|
||||
LSPServer.run(In);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue