Index: tools/CMakeLists.txt =================================================================== --- tools/CMakeLists.txt +++ tools/CMakeLists.txt @@ -15,6 +15,10 @@ add_subdirectory(clang-check) endif() +if( LLVM_USE_SANITIZE_COVERAGE ) + add_subdirectory(fuzzer) +endif() + # We support checking out the clang-tools-extra repository into the 'extra' # subdirectory. It contains tools developed as part of the Clang/LLVM project # on top of the Clang tooling platform. We keep them in a separate repository Index: tools/fuzzer/CMakeLists.txt =================================================================== --- /dev/null +++ tools/fuzzer/CMakeLists.txt @@ -0,0 +1,17 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_executable(clang-fuzzer + ClangFuzzer.cpp + ) + +target_link_libraries(clang-fuzzer + clangAST + clangASTMatchers + clangBasic + clangFrontend + clangLex + clangRewrite + clangTooling + clangToolingCore + LLVMFuzzer + ) Index: tools/fuzzer/ClangFuzzer.cpp =================================================================== --- /dev/null +++ tools/fuzzer/ClangFuzzer.cpp @@ -0,0 +1,34 @@ +//===-- ClangFuzzer.cpp - Fuzz Clang --------------------------------------===// +// +// 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 Clang on a single +/// input. This function is then linked into the Fuzzer library. +/// See llvm/lib/Fuzzer/README.txt for more instructions. +/// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +#include "clang/Tooling/Tooling.h" +#include + +// FIXME: The current implementation is very naive an inefficient: +// - buildASTFromCode does a lot of driver work which slows down things. +// - Errors are reported to stderr slowing things even further. +// +// What we really need here is a function that takes the array of bytes +// and invokes preprocessor and/or parser on it, sending messages to dev/null. + +extern "C" void TestOneInput(uint8_t *data, size_t size) { + std::string S((char*)data, size); + clang::tooling::buildASTFromCode(S); +}