diff options
author | Manuel Klimek <klimek@google.com> | 2015-03-28 00:42:36 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2015-03-28 00:42:36 +0000 |
commit | bea7dfbc5e8f464506e18556aed7738a0be7c419 (patch) | |
tree | 66d7c130861aab3cfa603e17353cabebe8a45fc1 /clang/tools/clang-fuzzer/ClangFuzzer.cpp | |
parent | fa3e8979a53217f19c06b7623a70ef58c902e4fb (diff) | |
download | bcm5719-llvm-bea7dfbc5e8f464506e18556aed7738a0be7c419.tar.gz bcm5719-llvm-bea7dfbc5e8f464506e18556aed7738a0be7c419.zip |
Make the clang-fuzzer use the CompilerInstance directly.
Going through the driver is too slow.
llvm-svn: 233459
Diffstat (limited to 'clang/tools/clang-fuzzer/ClangFuzzer.cpp')
-rw-r--r-- | clang/tools/clang-fuzzer/ClangFuzzer.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/clang/tools/clang-fuzzer/ClangFuzzer.cpp b/clang/tools/clang-fuzzer/ClangFuzzer.cpp index 3c50f81303a..b24531976cd 100644 --- a/clang/tools/clang-fuzzer/ClangFuzzer.cpp +++ b/clang/tools/clang-fuzzer/ClangFuzzer.cpp @@ -16,17 +16,28 @@ #include "clang/Tooling/Tooling.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/CompilerInstance.h" +#include "llvm/Option/Option.h" using namespace clang; extern "C" void TestOneInput(uint8_t *data, size_t size) { std::string s((const char *)data, size); + llvm::opt::ArgStringList CC1Args; + CC1Args.push_back("-cc1"); + CC1Args.push_back("test.cc"); 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(); + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + DiagnosticsEngine Diagnostics( + IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, + &Diags, false); + std::unique_ptr<clang::CompilerInvocation> Invocation( + tooling::newInvocation(&Diagnostics, CC1Args)); + std::unique_ptr<llvm::MemoryBuffer> Input = + llvm::MemoryBuffer::getMemBuffer(s); + Invocation->getPreprocessorOpts().addRemappedFile("test.cc", Input.release()); + std::unique_ptr<tooling::ToolAction> action( + tooling::newFrontendActionFactory<clang::SyntaxOnlyAction>()); + action->runInvocation(Invocation.release(), Files.get(), &Diags); } |