11 #include "clang/Basic/TargetInfo.h"
12 #include "clang/Lex/PreprocessorOptions.h"
13 #include "clang/Serialization/PCHContainerOperations.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Format.h"
16 #include "llvm/Support/FormatVariadic.h"
28 if (
Info.hasSourceManager() &&
Info.getLocation().isValid()) {
44 std::unique_ptr<CompilerInvocation>
46 std::vector<std::string> *CC1Args) {
47 std::vector<const char *> ArgStrs;
49 ArgStrs.push_back(S.c_str());
52 llvm::IntrusiveRefCntPtr<DiagnosticsEngine> CommandLineDiagsEngine =
53 CompilerInstance::createDiagnostics(
new DiagnosticOptions, &D,
false);
54 std::unique_ptr<CompilerInvocation>
CI = createInvocationFromCommandLine(
55 ArgStrs, CommandLineDiagsEngine, std::move(VFS),
60 CI->getFrontendOpts().DisableFree =
false;
61 CI->getLangOpts()->CommentOpts.ParseAllComments =
true;
62 CI->getLangOpts()->RetainCommentsFromSystemHeaders =
true;
66 CI->getDependencyOutputOpts().ShowIncludesDest =
68 CI->getDependencyOutputOpts().OutputFile.clear();
69 CI->getDependencyOutputOpts().HeaderIncludeOutputFile.clear();
70 CI->getDependencyOutputOpts().DOTOutputFile.clear();
71 CI->getDependencyOutputOpts().ModuleDependencyOutputDir.clear();
76 CI->getPreprocessorOpts().ImplicitPCHInclude.clear();
77 CI->getPreprocessorOpts().PrecompiledPreambleBytes = {0,
false};
78 CI->getPreprocessorOpts().PCHThroughHeader.clear();
79 CI->getPreprocessorOpts().PCHWithHdrStop =
false;
80 CI->getPreprocessorOpts().PCHWithHdrStopCreate =
false;
83 if (
CI->getLangOpts()->CPlusPlus) {
90 std::unique_ptr<CompilerInstance>
93 std::unique_ptr<llvm::MemoryBuffer> Buffer,
94 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
96 assert(VFS &&
"VFS is null");
97 assert(!
CI->getPreprocessorOpts().RetainRemappedFileBuffers &&
98 "Setting RetainRemappedFileBuffers to true will cause a memory leak "
104 Preamble->OverridePreamble(*
CI, VFS, Buffer.get());
106 CI->getPreprocessorOpts().addRemappedFile(
107 CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
110 auto Clang = std::make_unique<CompilerInstance>(
111 std::make_shared<PCHContainerOperations>());
112 Clang->setInvocation(std::move(
CI));
113 Clang->createDiagnostics(&DiagsClient,
false);
115 if (
auto VFSWithRemapping = createVFSFromCompilerInvocation(
116 Clang->getInvocation(), Clang->getDiagnostics(), VFS))
117 VFS = VFSWithRemapping;
118 Clang->createFileManager(VFS);
120 Clang->setTarget(TargetInfo::CreateTargetInfo(
121 Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
122 if (!Clang->hasTarget())