/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/clang-fuzzer/handle-cxx/handle_cxx.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //==-- handle_cxx.cpp - Helper function for Clang fuzzers ------------------==// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // Implements HandleCXX for use by the Clang fuzzers. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "handle_cxx.h" |
14 | | |
15 | | #include "clang/CodeGen/CodeGenAction.h" |
16 | | #include "clang/Frontend/CompilerInstance.h" |
17 | | #include "clang/Lex/PreprocessorOptions.h" |
18 | | #include "clang/Tooling/Tooling.h" |
19 | | #include "llvm/Option/Option.h" |
20 | | |
21 | | using namespace clang; |
22 | | |
23 | | void clang_fuzzer::HandleCXX(const std::string &S, |
24 | | const char *FileName, |
25 | 0 | const std::vector<const char *> &ExtraArgs) { |
26 | 0 | llvm::opt::ArgStringList CC1Args; |
27 | 0 | CC1Args.push_back("-cc1"); |
28 | 0 | for (auto &A : ExtraArgs) |
29 | 0 | CC1Args.push_back(A); |
30 | 0 | CC1Args.push_back(FileName); |
31 | |
|
32 | 0 | llvm::IntrusiveRefCntPtr<FileManager> Files( |
33 | 0 | new FileManager(FileSystemOptions())); |
34 | 0 | IgnoringDiagConsumer Diags; |
35 | 0 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); |
36 | 0 | DiagnosticsEngine Diagnostics( |
37 | 0 | IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, |
38 | 0 | &Diags, false); |
39 | 0 | std::unique_ptr<clang::CompilerInvocation> Invocation( |
40 | 0 | tooling::newInvocation(&Diagnostics, CC1Args, /*BinaryName=*/nullptr)); |
41 | 0 | std::unique_ptr<llvm::MemoryBuffer> Input = |
42 | 0 | llvm::MemoryBuffer::getMemBuffer(S); |
43 | 0 | Invocation->getPreprocessorOpts().addRemappedFile(FileName, |
44 | 0 | Input.release()); |
45 | 0 | std::unique_ptr<tooling::ToolAction> action( |
46 | 0 | tooling::newFrontendActionFactory<clang::EmitObjAction>()); |
47 | 0 | std::shared_ptr<PCHContainerOperations> PCHContainerOps = |
48 | 0 | std::make_shared<PCHContainerOperations>(); |
49 | 0 | action->runInvocation(std::move(Invocation), Files.get(), PCHContainerOps, |
50 | 0 | &Diags); |
51 | 0 | } |
52 | | |