diff options
| -rw-r--r-- | clang/tools/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | clang/tools/clang-fuzzer/CMakeLists.txt | 18 | ||||
| -rw-r--r-- | clang/tools/clang-fuzzer/ClangFuzzer.cpp | 32 |
3 files changed, 51 insertions, 0 deletions
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt index 90b2225a1d2..b2b2f6aa954 100644 --- a/clang/tools/CMakeLists.txt +++ b/clang/tools/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(diagtool) add_subdirectory(driver) add_subdirectory(clang-format) add_subdirectory(clang-format-vs) +add_subdirectory(clang-fuzzer) add_subdirectory(c-index-test) add_subdirectory(libclang) diff --git a/clang/tools/clang-fuzzer/CMakeLists.txt b/clang/tools/clang-fuzzer/CMakeLists.txt new file mode 100644 index 00000000000..87213148776 --- /dev/null +++ b/clang/tools/clang-fuzzer/CMakeLists.txt @@ -0,0 +1,18 @@ +set(LLVM_LINK_COMPONENTS support) + +add_clang_executable(clang-fuzzer + EXCLUDE_FROM_ALL + ClangFuzzer.cpp + ) + +target_link_libraries(clang-fuzzer + ${CLANG_FORMAT_LIB_DEPS} + clangAST + clangBasic + clangDriver + clangFrontend + clangRewriteFrontend + clangStaticAnalyzerFrontend + clangTooling + LLVMFuzzer + ) diff --git a/clang/tools/clang-fuzzer/ClangFuzzer.cpp b/clang/tools/clang-fuzzer/ClangFuzzer.cpp new file mode 100644 index 00000000000..3c50f81303a --- /dev/null +++ b/clang/tools/clang-fuzzer/ClangFuzzer.cpp @@ -0,0 +1,32 @@ +//===-- 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. +/// +//===----------------------------------------------------------------------===// + +#include "clang/Tooling/Tooling.h" +#include "clang/Frontend/FrontendActions.h" +#include "clang/Frontend/CompilerInstance.h" + +using namespace clang; + +extern "C" void TestOneInput(uint8_t *data, size_t size) { + std::string s((const char *)data, size); + llvm::IntrusiveRefCntPtr<FileManager> Files( + new FileManager(FileSystemOptions())); + tooling::ToolInvocation Invocation({"clang", "-c", "test.cc"}, + new clang::SyntaxOnlyAction, Files.get()); + IgnoringDiagConsumer Diags; + Invocation.setDiagnosticConsumer(&Diags); + Invocation.mapVirtualFile("test.cc", s); + Invocation.run(); +} |

