summaryrefslogtreecommitdiffstats
path: root/clang/tools/clang-fuzzer/ClangFuzzer.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2015-03-28 00:07:39 +0000
committerManuel Klimek <klimek@google.com>2015-03-28 00:07:39 +0000
commit667c152bce2ac481959975a8075870a5a05d90f6 (patch)
treebf1cbbbea8a87c8c69eefee43b4eda45658728f7 /clang/tools/clang-fuzzer/ClangFuzzer.cpp
parent6fab3c73b842d91d6dbfbff6f902b53a8eb688cb (diff)
downloadbcm5719-llvm-667c152bce2ac481959975a8075870a5a05d90f6.tar.gz
bcm5719-llvm-667c152bce2ac481959975a8075870a5a05d90f6.zip
Add initial version of a clang-fuzzer.
llvm-svn: 233455
Diffstat (limited to 'clang/tools/clang-fuzzer/ClangFuzzer.cpp')
-rw-r--r--clang/tools/clang-fuzzer/ClangFuzzer.cpp32
1 files changed, 32 insertions, 0 deletions
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();
+}
OpenPOWER on IntegriCloud