]> granicus.if.org Git - clang/commitdiff
do more processing in clang-fuzzer (use EmitAssemblyAction)
authorKostya Serebryany <kcc@google.com>
Fri, 14 Jul 2017 18:42:07 +0000 (18:42 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 14 Jul 2017 18:42:07 +0000 (18:42 +0000)
Summary: use EmitAssemblyAction in clang-fuzzer

Reviewers: klimek, rsmith

Reviewed By: klimek

Subscribers: cfe-commits, mgorny

Differential Revision: https://reviews.llvm.org/D34267

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308045 91177308-0d34-0410-b5e6-96231b3b80d8

tools/clang-fuzzer/CMakeLists.txt
tools/clang-fuzzer/ClangFuzzer.cpp

index 87d21c6bf116b68eea5b6f85f68f5f06f993a9e7..a4ea4ca19cdd1c771303c211c72acd8c36293f65 100644 (file)
@@ -1,5 +1,5 @@
 if( LLVM_USE_SANITIZE_COVERAGE )
-  set(LLVM_LINK_COMPONENTS support)
+  set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD})
 
   add_clang_executable(clang-fuzzer
     EXCLUDE_FROM_ALL
@@ -10,6 +10,7 @@ if( LLVM_USE_SANITIZE_COVERAGE )
     ${CLANG_FORMAT_LIB_DEPS}
     clangAST
     clangBasic
+    clangCodeGen
     clangDriver
     clangFrontend
     clangRewriteFrontend
index 1692882c0b5f17fe5ce07499847727e9659c3cdf..9eceb843e581ca99b09ebd3cdf4e473d0a2b3513 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "clang/Tooling/Tooling.h"
-#include "clang/Frontend/FrontendActions.h"
+#include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Support/TargetSelect.h"
 
 using namespace clang;
 
 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
   std::string s((const char *)data, size);
+  llvm::InitializeAllTargets();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllAsmParsers();
+
   llvm::opt::ArgStringList CC1Args;
   CC1Args.push_back("-cc1");
   CC1Args.push_back("./test.cc");
+  CC1Args.push_back("-O2");
   llvm::IntrusiveRefCntPtr<FileManager> Files(
       new FileManager(FileSystemOptions()));
   IgnoringDiagConsumer Diags;
@@ -39,7 +46,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
       llvm::MemoryBuffer::getMemBuffer(s);
   Invocation->getPreprocessorOpts().addRemappedFile("./test.cc", Input.release());
   std::unique_ptr<tooling::ToolAction> action(
-      tooling::newFrontendActionFactory<clang::SyntaxOnlyAction>());
+      tooling::newFrontendActionFactory<clang::EmitObjAction>());
   std::shared_ptr<PCHContainerOperations> PCHContainerOps =
       std::make_shared<PCHContainerOperations>();
   action->runInvocation(std::move(Invocation), Files.get(), PCHContainerOps,