r233455 - Add initial version of a clang-fuzzer.

Manuel Klimek klimek at google.com
Fri Mar 27 17:07:39 PDT 2015


Author: klimek
Date: Fri Mar 27 19:07:39 2015
New Revision: 233455

URL: http://llvm.org/viewvc/llvm-project?rev=233455&view=rev
Log:
Add initial version of a clang-fuzzer.

Added:
    cfe/trunk/tools/clang-fuzzer/
    cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
    cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp
Modified:
    cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/tools/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=233455&r1=233454&r2=233455&view=diff
==============================================================================
--- cfe/trunk/tools/CMakeLists.txt (original)
+++ cfe/trunk/tools/CMakeLists.txt Fri Mar 27 19:07:39 2015
@@ -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)

Added: cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/CMakeLists.txt?rev=233455&view=auto
==============================================================================
--- cfe/trunk/tools/clang-fuzzer/CMakeLists.txt (added)
+++ cfe/trunk/tools/clang-fuzzer/CMakeLists.txt Fri Mar 27 19:07:39 2015
@@ -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
+  )

Added: cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp?rev=233455&view=auto
==============================================================================
--- cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp (added)
+++ cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp Fri Mar 27 19:07:39 2015
@@ -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();
+}





More information about the cfe-commits mailing list