diff options
author | Manuel Klimek <klimek@google.com> | 2015-03-28 00:07:39 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2015-03-28 00:07:39 +0000 |
commit | 89208d11e2848b74d31634be7eeb70f4e9c76ecf (patch) | |
tree | b0289a86349453b02d75707b934551ae5b0b40be /tools/clang-fuzzer | |
parent | 178a7e9255d74a221ba860b9a5da68ab968a30d8 (diff) |
Add initial version of a clang-fuzzer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233455 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-fuzzer')
-rw-r--r-- | tools/clang-fuzzer/CMakeLists.txt | 18 | ||||
-rw-r--r-- | tools/clang-fuzzer/ClangFuzzer.cpp | 32 |
2 files changed, 50 insertions, 0 deletions
diff --git a/tools/clang-fuzzer/CMakeLists.txt b/tools/clang-fuzzer/CMakeLists.txt new file mode 100644 index 0000000000..8721314877 --- /dev/null +++ b/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/tools/clang-fuzzer/ClangFuzzer.cpp b/tools/clang-fuzzer/ClangFuzzer.cpp new file mode 100644 index 0000000000..3c50f81303 --- /dev/null +++ b/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(); +} |