<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 27, 2015 at 5:42 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: klimek<br>
Date: Fri Mar 27 19:42:36 2015<br>
New Revision: 233459<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=233459&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=233459&view=rev</a><br>
Log:<br>
Make the clang-fuzzer use the CompilerInstance directly.<br>
<br>
Going through the driver is too slow.<br></blockquote><div><br></div><div>Interesting. How much was the overhead? (clang wasn't forking, was it?)</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    cfe/trunk/include/clang/Tooling/Tooling.h<br>
    cfe/trunk/lib/Tooling/Tooling.cpp<br>
    cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Tooling/Tooling.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=233459&r1=233458&r2=233459&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=233459&r1=233458&r2=233459&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Tooling/Tooling.h (original)<br>
+++ cfe/trunk/include/clang/Tooling/Tooling.h Fri Mar 27 19:42:36 2015<br>
@@ -40,6 +40,7 @@<br>
 #include "clang/Tooling/CompilationDatabase.h"<br>
 #include "llvm/ADT/StringMap.h"<br>
 #include "llvm/ADT/Twine.h"<br>
+#include "llvm/Option/Option.h"<br>
 #include <memory><br>
 #include <string><br>
 #include <vector><br>
@@ -383,6 +384,11 @@ inline std::unique_ptr<FrontendActionFac<br>
 /// \param File Either an absolute or relative path.<br>
 std::string getAbsolutePath(StringRef File);<br>
<br>
+/// \brief Creates a \c CompilerInvocation.<br>
+clang::CompilerInvocation *newInvocation(<br>
+    clang::DiagnosticsEngine *Diagnostics,<br>
+    const llvm::opt::ArgStringList &CC1Args);<br>
+<br>
 } // end namespace tooling<br>
 } // end namespace clang<br>
<br>
<br>
Modified: cfe/trunk/lib/Tooling/Tooling.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=233459&r1=233458&r2=233459&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=233459&r1=233458&r2=233459&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)<br>
+++ cfe/trunk/lib/Tooling/Tooling.cpp Fri Mar 27 19:42:36 2015<br>
@@ -90,7 +90,7 @@ static const llvm::opt::ArgStringList *g<br>
 }<br>
<br>
 /// \brief Returns a clang build invocation initialized from the CC1 flags.<br>
-static clang::CompilerInvocation *newInvocation(<br>
+clang::CompilerInvocation *newInvocation(<br>
     clang::DiagnosticsEngine *Diagnostics,<br>
     const llvm::opt::ArgStringList &CC1Args) {<br>
   assert(!CC1Args.empty() && "Must at least contain the program name!");<br>
<br>
Modified: cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp?rev=233459&r1=233458&r2=233459&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp?rev=233459&r1=233458&r2=233459&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp (original)<br>
+++ cfe/trunk/tools/clang-fuzzer/ClangFuzzer.cpp Fri Mar 27 19:42:36 2015<br>
@@ -16,17 +16,28 @@<br>
 #include "clang/Tooling/Tooling.h"<br>
 #include "clang/Frontend/FrontendActions.h"<br>
 #include "clang/Frontend/CompilerInstance.h"<br>
+#include "llvm/Option/Option.h"<br>
<br>
 using namespace clang;<br>
<br>
 extern "C" void TestOneInput(uint8_t *data, size_t size) {<br>
   std::string s((const char *)data, size);<br>
+  llvm::opt::ArgStringList CC1Args;<br>
+  CC1Args.push_back("-cc1");<br>
+  CC1Args.push_back("test.cc");<br>
   llvm::IntrusiveRefCntPtr<FileManager> Files(<br>
       new FileManager(FileSystemOptions()));<br>
-  tooling::ToolInvocation Invocation({"clang", "-c", "test.cc"},<br>
-                                     new clang::SyntaxOnlyAction, Files.get());<br>
   IgnoringDiagConsumer Diags;<br>
-  Invocation.setDiagnosticConsumer(&Diags);<br>
-  Invocation.mapVirtualFile("test.cc", s);<br>
-  Invocation.run();<br>
+  IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();<br>
+  DiagnosticsEngine Diagnostics(<br>
+      IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,<br>
+      &Diags, false);<br>
+  std::unique_ptr<clang::CompilerInvocation> Invocation(<br>
+      tooling::newInvocation(&Diagnostics, CC1Args));<br>
+  std::unique_ptr<llvm::MemoryBuffer> Input =<br>
+      llvm::MemoryBuffer::getMemBuffer(s);<br>
+  Invocation->getPreprocessorOpts().addRemappedFile("test.cc", Input.release());<br>
+  std::unique_ptr<tooling::ToolAction> action(<br>
+      tooling::newFrontendActionFactory<clang::SyntaxOnlyAction>());<br>
+  action->runInvocation(Invocation.release(), Files.get(), &Diags);<br>
 }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>