Author: d0k Date: Thu Oct 26 03:03:11 2017 New Revision: 316649 URL: http://llvm.org/viewvc/llvm-project?rev=316649&view=rev Log: [clangd] Add a simple fuzzer. It crashes a lot :)
Added: clang-tools-extra/trunk/clangd/fuzzer/ clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=316649&r1=316648&r2=316649&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/CMakeLists.txt (original) +++ clang-tools-extra/trunk/clangd/CMakeLists.txt Thu Oct 26 03:03:11 2017 @@ -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) Added: clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt?rev=316649&view=auto ============================================================================== --- clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt (added) +++ clang-tools-extra/trunk/clangd/fuzzer/CMakeLists.txt Thu Oct 26 03:03:11 2017 @@ -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} + ) Added: clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp?rev=316649&view=auto ============================================================================== --- clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp (added) +++ clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp Thu Oct 26 03:03:11 2017 @@ -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; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits