21 const clang::Diagnostic &
Info) {
23 llvm::SmallString<64> Message;
24 Info.FormatDiagnostic(Message);
27 if (
Info.hasSourceManager() &&
Info.getLocation().isValid()) {
28 auto &SourceMgr =
Info.getSourceManager();
29 auto Loc = SourceMgr.getFileLoc(
Info.getLocation());
30 llvm::raw_svector_ostream OS(
Location);
31 Loc.print(OS, SourceMgr);
50 CI.getDiagnosticOpts().VerifyDiagnostics =
false;
51 CI.getDiagnosticOpts().ShowColors =
false;
55 CI.getDependencyOutputOpts().ShowIncludesDest = ShowIncludesDestination::None;
56 CI.getDependencyOutputOpts().OutputFile.clear();
57 CI.getDependencyOutputOpts().HeaderIncludeOutputFile.clear();
58 CI.getDependencyOutputOpts().DOTOutputFile.clear();
59 CI.getDependencyOutputOpts().ModuleDependencyOutputDir.clear();
64 CI.getPreprocessorOpts().ImplicitPCHInclude.clear();
65 CI.getPreprocessorOpts().PrecompiledPreambleBytes = {0,
false};
66 CI.getPreprocessorOpts().PCHThroughHeader.clear();
67 CI.getPreprocessorOpts().PCHWithHdrStop =
false;
68 CI.getPreprocessorOpts().PCHWithHdrStopCreate =
false;
71 CI.getPreprocessorOpts().DisablePragmaDebugCrash =
true;
75 CI.getHeaderSearchOpts().ModuleFormat =
76 PCHContainerOperations().getRawReader().getFormats().front().str();
78 CI.getFrontendOpts().Plugins.clear();
79 CI.getFrontendOpts().AddPluginActions.clear();
80 CI.getFrontendOpts().PluginArgs.clear();
81 CI.getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly;
82 CI.getFrontendOpts().ActionName.clear();
87 CI.getLangOpts().NoSanitizeFiles.clear();
88 CI.getLangOpts().XRayAttrListFiles.clear();
89 CI.getLangOpts().ProfileListFiles.clear();
90 CI.getLangOpts().XRayAlwaysInstrumentFiles.clear();
91 CI.getLangOpts().XRayNeverInstrumentFiles.clear();
96 std::vector<std::string> *CC1Args) {
97 llvm::ArrayRef<std::string> Argv = Inputs.
CompileCommand.CommandLine;
100 std::vector<const char *> ArgStrs;
101 ArgStrs.reserve(Argv.size() + 1);
105 ArgStrs = {Argv.front().c_str(),
"-Xclang",
"-no-round-trip-args"};
106 for (
const auto &S : Argv.drop_front())
107 ArgStrs.push_back(S.c_str());
109 CreateInvocationOptions CIOpts;
111 CIOpts.CC1Args = CC1Args;
112 CIOpts.RecoverOnError =
true;
113 DiagnosticOptions DiagOpts;
115 CompilerInstance::createDiagnostics(*CIOpts.VFS, DiagOpts, &D,
false);
116 CIOpts.ProbePrecompiled =
false;
117 std::unique_ptr<CompilerInvocation> CI = createInvocation(ArgStrs, CIOpts);
121 CI->getFrontendOpts().DisableFree =
false;
122 CI->getLangOpts().CommentOpts.ParseAllComments =
true;
123 CI->getLangOpts().RetainCommentsFromSystemHeaders =
true;
131 const PrecompiledPreamble *
Preamble,
132 std::unique_ptr<llvm::MemoryBuffer> Buffer,
133 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
135 assert(VFS &&
"VFS is null");
136 assert(!CI->getPreprocessorOpts().RetainRemappedFileBuffers &&
137 "Setting RetainRemappedFileBuffers to true will cause a memory leak "
138 "of ContentsBuffer");
143 Preamble->OverridePreamble(*CI, VFS, Buffer.get());
145 CI->getPreprocessorOpts().addRemappedFile(
146 CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
149 auto Clang = std::make_unique<CompilerInstance>(std::move(CI));
150 Clang->createVirtualFileSystem(VFS, &DiagsClient);
151 Clang->createDiagnostics(&DiagsClient,
false);
152 Clang->createFileManager();
153 if (!Clang->createTarget())
std::unique_ptr< CompilerInvocation > buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D, std::vector< std::string > *CC1Args)
Builds compiler invocation that could be used to build AST or preamble.
std::unique_ptr< CompilerInstance > prepareCompilerInstance(std::unique_ptr< clang::CompilerInvocation > CI, const PrecompiledPreamble *Preamble, std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, DiagnosticConsumer &DiagsClient)