FrontendAction.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. //===--- FrontendAction.cpp -----------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "clang/Frontend/FrontendAction.h"
  10. #include "clang/AST/ASTConsumer.h"
  11. #include "clang/AST/ASTContext.h"
  12. #include "clang/AST/DeclGroup.h"
  13. #include "clang/Frontend/ASTUnit.h"
  14. #include "clang/Frontend/CompilerInstance.h"
  15. #include "clang/Frontend/FrontendDiagnostic.h"
  16. #include "clang/Frontend/FrontendPluginRegistry.h"
  17. #include "clang/Frontend/LayoutOverrideSource.h"
  18. #include "clang/Frontend/MultiplexConsumer.h"
  19. #include "clang/Frontend/Utils.h"
  20. #include "clang/Lex/HeaderSearch.h"
  21. #include "clang/Lex/LiteralSupport.h"
  22. #include "clang/Lex/Preprocessor.h"
  23. #include "clang/Lex/PreprocessorOptions.h"
  24. #include "clang/Parse/ParseAST.h"
  25. #include "clang/Serialization/ASTDeserializationListener.h"
  26. #include "clang/Serialization/ASTReader.h"
  27. #include "clang/Serialization/GlobalModuleIndex.h"
  28. #include "llvm/Support/ErrorHandling.h"
  29. #include "llvm/Support/FileSystem.h"
  30. #include "llvm/Support/Path.h"
  31. #include "llvm/Support/Timer.h"
  32. #include "llvm/Support/raw_ostream.h"
  33. #include <system_error>
  34. using namespace clang;
  35. LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
  36. namespace {
  37. class DelegatingDeserializationListener : public ASTDeserializationListener {
  38. ASTDeserializationListener *Previous;
  39. bool DeletePrevious;
  40. public:
  41. explicit DelegatingDeserializationListener(
  42. ASTDeserializationListener *Previous, bool DeletePrevious)
  43. : Previous(Previous), DeletePrevious(DeletePrevious) {}
  44. ~DelegatingDeserializationListener() override {
  45. if (DeletePrevious)
  46. delete Previous;
  47. }
  48. void ReaderInitialized(ASTReader *Reader) override {
  49. if (Previous)
  50. Previous->ReaderInitialized(Reader);
  51. }
  52. void IdentifierRead(serialization::IdentID ID,
  53. IdentifierInfo *II) override {
  54. if (Previous)
  55. Previous->IdentifierRead(ID, II);
  56. }
  57. void TypeRead(serialization::TypeIdx Idx, QualType T) override {
  58. if (Previous)
  59. Previous->TypeRead(Idx, T);
  60. }
  61. void DeclRead(serialization::DeclID ID, const Decl *D) override {
  62. if (Previous)
  63. Previous->DeclRead(ID, D);
  64. }
  65. void SelectorRead(serialization::SelectorID ID, Selector Sel) override {
  66. if (Previous)
  67. Previous->SelectorRead(ID, Sel);
  68. }
  69. void MacroDefinitionRead(serialization::PreprocessedEntityID PPID,
  70. MacroDefinitionRecord *MD) override {
  71. if (Previous)
  72. Previous->MacroDefinitionRead(PPID, MD);
  73. }
  74. };
  75. /// Dumps deserialized declarations.
  76. class DeserializedDeclsDumper : public DelegatingDeserializationListener {
  77. public:
  78. explicit DeserializedDeclsDumper(ASTDeserializationListener *Previous,
  79. bool DeletePrevious)
  80. : DelegatingDeserializationListener(Previous, DeletePrevious) {}
  81. void DeclRead(serialization::DeclID ID, const Decl *D) override {
  82. llvm::outs() << "PCH DECL: " << D->getDeclKindName();
  83. if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) {
  84. llvm::outs() << " - ";
  85. ND->printQualifiedName(llvm::outs());
  86. }
  87. llvm::outs() << "\n";
  88. DelegatingDeserializationListener::DeclRead(ID, D);
  89. }
  90. };
  91. /// Checks deserialized declarations and emits error if a name
  92. /// matches one given in command-line using -error-on-deserialized-decl.
  93. class DeserializedDeclsChecker : public DelegatingDeserializationListener {
  94. ASTContext &Ctx;
  95. std::set<std::string> NamesToCheck;
  96. public:
  97. DeserializedDeclsChecker(ASTContext &Ctx,
  98. const std::set<std::string> &NamesToCheck,
  99. ASTDeserializationListener *Previous,
  100. bool DeletePrevious)
  101. : DelegatingDeserializationListener(Previous, DeletePrevious), Ctx(Ctx),
  102. NamesToCheck(NamesToCheck) {}
  103. void DeclRead(serialization::DeclID ID, const Decl *D) override {
  104. if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
  105. if (NamesToCheck.find(ND->getNameAsString()) != NamesToCheck.end()) {
  106. unsigned DiagID
  107. = Ctx.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error,
  108. "%0 was deserialized");
  109. Ctx.getDiagnostics().Report(Ctx.getFullLoc(D->getLocation()), DiagID)
  110. << ND->getNameAsString();
  111. }
  112. DelegatingDeserializationListener::DeclRead(ID, D);
  113. }
  114. };
  115. } // end anonymous namespace
  116. FrontendAction::FrontendAction() : Instance(nullptr) {}
  117. FrontendAction::~FrontendAction() {}
  118. void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput,
  119. std::unique_ptr<ASTUnit> AST) {
  120. this->CurrentInput = CurrentInput;
  121. CurrentASTUnit = std::move(AST);
  122. }
  123. Module *FrontendAction::getCurrentModule() const {
  124. CompilerInstance &CI = getCompilerInstance();
  125. return CI.getPreprocessor().getHeaderSearchInfo().lookupModule(
  126. CI.getLangOpts().CurrentModule, /*AllowSearch*/false);
  127. }
  128. std::unique_ptr<ASTConsumer>
  129. FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
  130. StringRef InFile) {
  131. std::unique_ptr<ASTConsumer> Consumer = CreateASTConsumer(CI, InFile);
  132. if (!Consumer)
  133. return nullptr;
  134. // If there are no registered plugins we don't need to wrap the consumer
  135. if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
  136. return Consumer;
  137. // If this is a code completion run, avoid invoking the plugin consumers
  138. if (CI.hasCodeCompletionConsumer())
  139. return Consumer;
  140. // Collect the list of plugins that go before the main action (in Consumers)
  141. // or after it (in AfterConsumers)
  142. std::vector<std::unique_ptr<ASTConsumer>> Consumers;
  143. std::vector<std::unique_ptr<ASTConsumer>> AfterConsumers;
  144. for (FrontendPluginRegistry::iterator it = FrontendPluginRegistry::begin(),
  145. ie = FrontendPluginRegistry::end();
  146. it != ie; ++it) {
  147. std::unique_ptr<PluginASTAction> P = it->instantiate();
  148. PluginASTAction::ActionType ActionType = P->getActionType();
  149. if (ActionType == PluginASTAction::Cmdline) {
  150. // This is O(|plugins| * |add_plugins|), but since both numbers are
  151. // way below 50 in practice, that's ok.
  152. for (size_t i = 0, e = CI.getFrontendOpts().AddPluginActions.size();
  153. i != e; ++i) {
  154. if (it->getName() == CI.getFrontendOpts().AddPluginActions[i]) {
  155. ActionType = PluginASTAction::AddAfterMainAction;
  156. break;
  157. }
  158. }
  159. }
  160. if ((ActionType == PluginASTAction::AddBeforeMainAction ||
  161. ActionType == PluginASTAction::AddAfterMainAction) &&
  162. P->ParseArgs(CI, CI.getFrontendOpts().PluginArgs[it->getName()])) {
  163. std::unique_ptr<ASTConsumer> PluginConsumer = P->CreateASTConsumer(CI, InFile);
  164. if (ActionType == PluginASTAction::AddBeforeMainAction) {
  165. Consumers.push_back(std::move(PluginConsumer));
  166. } else {
  167. AfterConsumers.push_back(std::move(PluginConsumer));
  168. }
  169. }
  170. }
  171. // Add to Consumers the main consumer, then all the plugins that go after it
  172. Consumers.push_back(std::move(Consumer));
  173. for (auto &C : AfterConsumers) {
  174. Consumers.push_back(std::move(C));
  175. }
  176. return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
  177. }
  178. /// For preprocessed files, if the first line is the linemarker and specifies
  179. /// the original source file name, use that name as the input file name.
  180. /// Returns the location of the first token after the line marker directive.
  181. ///
  182. /// \param CI The compiler instance.
  183. /// \param InputFile Populated with the filename from the line marker.
  184. /// \param IsModuleMap If \c true, add a line note corresponding to this line
  185. /// directive. (We need to do this because the directive will not be
  186. /// visited by the preprocessor.)
  187. static SourceLocation ReadOriginalFileName(CompilerInstance &CI,
  188. std::string &InputFile,
  189. bool IsModuleMap = false) {
  190. auto &SourceMgr = CI.getSourceManager();
  191. auto MainFileID = SourceMgr.getMainFileID();
  192. bool Invalid = false;
  193. const auto *MainFileBuf = SourceMgr.getBuffer(MainFileID, &Invalid);
  194. if (Invalid)
  195. return SourceLocation();
  196. std::unique_ptr<Lexer> RawLexer(
  197. new Lexer(MainFileID, MainFileBuf, SourceMgr, CI.getLangOpts()));
  198. // If the first line has the syntax of
  199. //
  200. // # NUM "FILENAME"
  201. //
  202. // we use FILENAME as the input file name.
  203. Token T;
  204. if (RawLexer->LexFromRawLexer(T) || T.getKind() != tok::hash)
  205. return SourceLocation();
  206. if (RawLexer->LexFromRawLexer(T) || T.isAtStartOfLine() ||
  207. T.getKind() != tok::numeric_constant)
  208. return SourceLocation();
  209. unsigned LineNo;
  210. SourceLocation LineNoLoc = T.getLocation();
  211. if (IsModuleMap) {
  212. llvm::SmallString<16> Buffer;
  213. if (Lexer::getSpelling(LineNoLoc, Buffer, SourceMgr, CI.getLangOpts())
  214. .getAsInteger(10, LineNo))
  215. return SourceLocation();
  216. }
  217. RawLexer->LexFromRawLexer(T);
  218. if (T.isAtStartOfLine() || T.getKind() != tok::string_literal)
  219. return SourceLocation();
  220. StringLiteralParser Literal(T, CI.getPreprocessor());
  221. if (Literal.hadError)
  222. return SourceLocation();
  223. RawLexer->LexFromRawLexer(T);
  224. if (T.isNot(tok::eof) && !T.isAtStartOfLine())
  225. return SourceLocation();
  226. InputFile = Literal.GetString().str();
  227. if (IsModuleMap)
  228. CI.getSourceManager().AddLineNote(
  229. LineNoLoc, LineNo, SourceMgr.getLineTableFilenameID(InputFile), false,
  230. false, SrcMgr::C_User_ModuleMap);
  231. return T.getLocation();
  232. }
  233. static SmallVectorImpl<char> &
  234. operator+=(SmallVectorImpl<char> &Includes, StringRef RHS) {
  235. Includes.append(RHS.begin(), RHS.end());
  236. return Includes;
  237. }
  238. static void addHeaderInclude(StringRef HeaderName,
  239. SmallVectorImpl<char> &Includes,
  240. const LangOptions &LangOpts,
  241. bool IsExternC) {
  242. if (IsExternC && LangOpts.CPlusPlus)
  243. Includes += "extern \"C\" {\n";
  244. if (LangOpts.ObjC1)
  245. Includes += "#import \"";
  246. else
  247. Includes += "#include \"";
  248. Includes += HeaderName;
  249. Includes += "\"\n";
  250. if (IsExternC && LangOpts.CPlusPlus)
  251. Includes += "}\n";
  252. }
  253. /// Collect the set of header includes needed to construct the given
  254. /// module and update the TopHeaders file set of the module.
  255. ///
  256. /// \param Module The module we're collecting includes from.
  257. ///
  258. /// \param Includes Will be augmented with the set of \#includes or \#imports
  259. /// needed to load all of the named headers.
  260. static std::error_code collectModuleHeaderIncludes(
  261. const LangOptions &LangOpts, FileManager &FileMgr, DiagnosticsEngine &Diag,
  262. ModuleMap &ModMap, clang::Module *Module, SmallVectorImpl<char> &Includes) {
  263. // Don't collect any headers for unavailable modules.
  264. if (!Module->isAvailable())
  265. return std::error_code();
  266. // Resolve all lazy header directives to header files.
  267. ModMap.resolveHeaderDirectives(Module);
  268. // If any headers are missing, we can't build this module. In most cases,
  269. // diagnostics for this should have already been produced; we only get here
  270. // if explicit stat information was provided.
  271. // FIXME: If the name resolves to a file with different stat information,
  272. // produce a better diagnostic.
  273. if (!Module->MissingHeaders.empty()) {
  274. auto &MissingHeader = Module->MissingHeaders.front();
  275. Diag.Report(MissingHeader.FileNameLoc, diag::err_module_header_missing)
  276. << MissingHeader.IsUmbrella << MissingHeader.FileName;
  277. return std::error_code();
  278. }
  279. // Add includes for each of these headers.
  280. for (auto HK : {Module::HK_Normal, Module::HK_Private}) {
  281. for (Module::Header &H : Module->Headers[HK]) {
  282. Module->addTopHeader(H.Entry);
  283. // Use the path as specified in the module map file. We'll look for this
  284. // file relative to the module build directory (the directory containing
  285. // the module map file) so this will find the same file that we found
  286. // while parsing the module map.
  287. addHeaderInclude(H.NameAsWritten, Includes, LangOpts, Module->IsExternC);
  288. }
  289. }
  290. // Note that Module->PrivateHeaders will not be a TopHeader.
  291. if (Module::Header UmbrellaHeader = Module->getUmbrellaHeader()) {
  292. Module->addTopHeader(UmbrellaHeader.Entry);
  293. if (Module->Parent)
  294. // Include the umbrella header for submodules.
  295. addHeaderInclude(UmbrellaHeader.NameAsWritten, Includes, LangOpts,
  296. Module->IsExternC);
  297. } else if (Module::DirectoryName UmbrellaDir = Module->getUmbrellaDir()) {
  298. // Add all of the headers we find in this subdirectory.
  299. std::error_code EC;
  300. SmallString<128> DirNative;
  301. llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative);
  302. llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem();
  303. for (llvm::vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End;
  304. Dir != End && !EC; Dir.increment(EC)) {
  305. // Check whether this entry has an extension typically associated with
  306. // headers.
  307. if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path()))
  308. .Cases(".h", ".H", ".hh", ".hpp", true)
  309. .Default(false))
  310. continue;
  311. const FileEntry *Header = FileMgr.getFile(Dir->path());
  312. // FIXME: This shouldn't happen unless there is a file system race. Is
  313. // that worth diagnosing?
  314. if (!Header)
  315. continue;
  316. // If this header is marked 'unavailable' in this module, don't include
  317. // it.
  318. if (ModMap.isHeaderUnavailableInModule(Header, Module))
  319. continue;
  320. // Compute the relative path from the directory to this file.
  321. SmallVector<StringRef, 16> Components;
  322. auto PathIt = llvm::sys::path::rbegin(Dir->path());
  323. for (int I = 0; I != Dir.level() + 1; ++I, ++PathIt)
  324. Components.push_back(*PathIt);
  325. SmallString<128> RelativeHeader(UmbrellaDir.NameAsWritten);
  326. for (auto It = Components.rbegin(), End = Components.rend(); It != End;
  327. ++It)
  328. llvm::sys::path::append(RelativeHeader, *It);
  329. // Include this header as part of the umbrella directory.
  330. Module->addTopHeader(Header);
  331. addHeaderInclude(RelativeHeader, Includes, LangOpts, Module->IsExternC);
  332. }
  333. if (EC)
  334. return EC;
  335. }
  336. // Recurse into submodules.
  337. for (clang::Module::submodule_iterator Sub = Module->submodule_begin(),
  338. SubEnd = Module->submodule_end();
  339. Sub != SubEnd; ++Sub)
  340. if (std::error_code Err = collectModuleHeaderIncludes(
  341. LangOpts, FileMgr, Diag, ModMap, *Sub, Includes))
  342. return Err;
  343. return std::error_code();
  344. }
  345. static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem,
  346. bool IsPreprocessed,
  347. std::string &PresumedModuleMapFile,
  348. unsigned &Offset) {
  349. auto &SrcMgr = CI.getSourceManager();
  350. HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
  351. // Map the current input to a file.
  352. FileID ModuleMapID = SrcMgr.getMainFileID();
  353. const FileEntry *ModuleMap = SrcMgr.getFileEntryForID(ModuleMapID);
  354. // If the module map is preprocessed, handle the initial line marker;
  355. // line directives are not part of the module map syntax in general.
  356. Offset = 0;
  357. if (IsPreprocessed) {
  358. SourceLocation EndOfLineMarker =
  359. ReadOriginalFileName(CI, PresumedModuleMapFile, /*IsModuleMap*/ true);
  360. if (EndOfLineMarker.isValid())
  361. Offset = CI.getSourceManager().getDecomposedLoc(EndOfLineMarker).second;
  362. }
  363. // Load the module map file.
  364. if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset,
  365. PresumedModuleMapFile))
  366. return true;
  367. if (SrcMgr.getBuffer(ModuleMapID)->getBufferSize() == Offset)
  368. Offset = 0;
  369. return false;
  370. }
  371. static Module *prepareToBuildModule(CompilerInstance &CI,
  372. StringRef ModuleMapFilename) {
  373. if (CI.getLangOpts().CurrentModule.empty()) {
  374. CI.getDiagnostics().Report(diag::err_missing_module_name);
  375. // FIXME: Eventually, we could consider asking whether there was just
  376. // a single module described in the module map, and use that as a
  377. // default. Then it would be fairly trivial to just "compile" a module
  378. // map with a single module (the common case).
  379. return nullptr;
  380. }
  381. // Dig out the module definition.
  382. HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
  383. Module *M = HS.lookupModule(CI.getLangOpts().CurrentModule,
  384. /*AllowSearch=*/false);
  385. if (!M) {
  386. CI.getDiagnostics().Report(diag::err_missing_module)
  387. << CI.getLangOpts().CurrentModule << ModuleMapFilename;
  388. return nullptr;
  389. }
  390. // Check whether we can build this module at all.
  391. if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(),
  392. CI.getDiagnostics(), M))
  393. return nullptr;
  394. // Inform the preprocessor that includes from within the input buffer should
  395. // be resolved relative to the build directory of the module map file.
  396. CI.getPreprocessor().setMainFileDir(M->Directory);
  397. // If the module was inferred from a different module map (via an expanded
  398. // umbrella module definition), track that fact.
  399. // FIXME: It would be preferable to fill this in as part of processing
  400. // the module map, rather than adding it after the fact.
  401. StringRef OriginalModuleMapName = CI.getFrontendOpts().OriginalModuleMap;
  402. if (!OriginalModuleMapName.empty()) {
  403. auto *OriginalModuleMap =
  404. CI.getFileManager().getFile(OriginalModuleMapName,
  405. /*openFile*/ true);
  406. if (!OriginalModuleMap) {
  407. CI.getDiagnostics().Report(diag::err_module_map_not_found)
  408. << OriginalModuleMapName;
  409. return nullptr;
  410. }
  411. if (OriginalModuleMap != CI.getSourceManager().getFileEntryForID(
  412. CI.getSourceManager().getMainFileID())) {
  413. M->IsInferred = true;
  414. CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()
  415. .setInferredModuleAllowedBy(M, OriginalModuleMap);
  416. }
  417. }
  418. // If we're being run from the command-line, the module build stack will not
  419. // have been filled in yet, so complete it now in order to allow us to detect
  420. // module cycles.
  421. SourceManager &SourceMgr = CI.getSourceManager();
  422. if (SourceMgr.getModuleBuildStack().empty())
  423. SourceMgr.pushModuleBuildStack(CI.getLangOpts().CurrentModule,
  424. FullSourceLoc(SourceLocation(), SourceMgr));
  425. return M;
  426. }
  427. /// Compute the input buffer that should be used to build the specified module.
  428. static std::unique_ptr<llvm::MemoryBuffer>
  429. getInputBufferForModule(CompilerInstance &CI, Module *M) {
  430. FileManager &FileMgr = CI.getFileManager();
  431. // Collect the set of #includes we need to build the module.
  432. SmallString<256> HeaderContents;
  433. std::error_code Err = std::error_code();
  434. if (Module::Header UmbrellaHeader = M->getUmbrellaHeader())
  435. addHeaderInclude(UmbrellaHeader.NameAsWritten, HeaderContents,
  436. CI.getLangOpts(), M->IsExternC);
  437. Err = collectModuleHeaderIncludes(
  438. CI.getLangOpts(), FileMgr, CI.getDiagnostics(),
  439. CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(), M,
  440. HeaderContents);
  441. if (Err) {
  442. CI.getDiagnostics().Report(diag::err_module_cannot_create_includes)
  443. << M->getFullModuleName() << Err.message();
  444. return nullptr;
  445. }
  446. return llvm::MemoryBuffer::getMemBufferCopy(
  447. HeaderContents, Module::getModuleInputBufferName());
  448. }
  449. bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
  450. const FrontendInputFile &RealInput) {
  451. FrontendInputFile Input(RealInput);
  452. assert(!Instance && "Already processing a source file!");
  453. assert(!Input.isEmpty() && "Unexpected empty filename!");
  454. setCurrentInput(Input);
  455. setCompilerInstance(&CI);
  456. bool HasBegunSourceFile = false;
  457. bool ReplayASTFile = Input.getKind().getFormat() == InputKind::Precompiled &&
  458. usesPreprocessorOnly();
  459. if (!BeginInvocation(CI))
  460. goto failure;
  461. // If we're replaying the build of an AST file, import it and set up
  462. // the initial state from its build.
  463. if (ReplayASTFile) {
  464. IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());
  465. // The AST unit populates its own diagnostics engine rather than ours.
  466. IntrusiveRefCntPtr<DiagnosticsEngine> ASTDiags(
  467. new DiagnosticsEngine(Diags->getDiagnosticIDs(),
  468. &Diags->getDiagnosticOptions()));
  469. ASTDiags->setClient(Diags->getClient(), /*OwnsClient*/false);
  470. // FIXME: What if the input is a memory buffer?
  471. StringRef InputFile = Input.getFile();
  472. std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
  473. InputFile, CI.getPCHContainerReader(), ASTUnit::LoadPreprocessorOnly,
  474. ASTDiags, CI.getFileSystemOpts(), CI.getCodeGenOpts().DebugTypeExtRefs);
  475. if (!AST)
  476. goto failure;
  477. // Options relating to how we treat the input (but not what we do with it)
  478. // are inherited from the AST unit.
  479. CI.getHeaderSearchOpts() = AST->getHeaderSearchOpts();
  480. CI.getPreprocessorOpts() = AST->getPreprocessorOpts();
  481. CI.getLangOpts() = AST->getLangOpts();
  482. // Set the shared objects, these are reset when we finish processing the
  483. // file, otherwise the CompilerInstance will happily destroy them.
  484. CI.setFileManager(&AST->getFileManager());
  485. CI.createSourceManager(CI.getFileManager());
  486. CI.getSourceManager().initializeForReplay(AST->getSourceManager());
  487. // Preload all the module files loaded transitively by the AST unit. Also
  488. // load all module map files that were parsed as part of building the AST
  489. // unit.
  490. if (auto ASTReader = AST->getASTReader()) {
  491. auto &MM = ASTReader->getModuleManager();
  492. auto &PrimaryModule = MM.getPrimaryModule();
  493. for (ModuleFile &MF : MM)
  494. if (&MF != &PrimaryModule)
  495. CI.getFrontendOpts().ModuleFiles.push_back(MF.FileName);
  496. ASTReader->visitTopLevelModuleMaps(PrimaryModule,
  497. [&](const FileEntry *FE) {
  498. CI.getFrontendOpts().ModuleMapFiles.push_back(FE->getName());
  499. });
  500. }
  501. // Set up the input file for replay purposes.
  502. auto Kind = AST->getInputKind();
  503. if (Kind.getFormat() == InputKind::ModuleMap) {
  504. Module *ASTModule =
  505. AST->getPreprocessor().getHeaderSearchInfo().lookupModule(
  506. AST->getLangOpts().CurrentModule, /*AllowSearch*/ false);
  507. assert(ASTModule && "module file does not define its own module");
  508. Input = FrontendInputFile(ASTModule->PresumedModuleMapFile, Kind);
  509. } else {
  510. auto &OldSM = AST->getSourceManager();
  511. FileID ID = OldSM.getMainFileID();
  512. if (auto *File = OldSM.getFileEntryForID(ID))
  513. Input = FrontendInputFile(File->getName(), Kind);
  514. else
  515. Input = FrontendInputFile(OldSM.getBuffer(ID), Kind);
  516. }
  517. setCurrentInput(Input, std::move(AST));
  518. }
  519. // AST files follow a very different path, since they share objects via the
  520. // AST unit.
  521. if (Input.getKind().getFormat() == InputKind::Precompiled) {
  522. assert(!usesPreprocessorOnly() && "this case was handled above");
  523. assert(hasASTFileSupport() &&
  524. "This action does not have AST file support!");
  525. IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());
  526. // FIXME: What if the input is a memory buffer?
  527. StringRef InputFile = Input.getFile();
  528. std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
  529. InputFile, CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
  530. CI.getFileSystemOpts(), CI.getCodeGenOpts().DebugTypeExtRefs);
  531. if (!AST)
  532. goto failure;
  533. // Inform the diagnostic client we are processing a source file.
  534. CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
  535. HasBegunSourceFile = true;
  536. // Set the shared objects, these are reset when we finish processing the
  537. // file, otherwise the CompilerInstance will happily destroy them.
  538. CI.setFileManager(&AST->getFileManager());
  539. CI.setSourceManager(&AST->getSourceManager());
  540. CI.setPreprocessor(AST->getPreprocessorPtr());
  541. Preprocessor &PP = CI.getPreprocessor();
  542. PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(),
  543. PP.getLangOpts());
  544. CI.setASTContext(&AST->getASTContext());
  545. setCurrentInput(Input, std::move(AST));
  546. // Initialize the action.
  547. if (!BeginSourceFileAction(CI))
  548. goto failure;
  549. // Create the AST consumer.
  550. CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile));
  551. if (!CI.hasASTConsumer())
  552. goto failure;
  553. return true;
  554. }
  555. // Set up the file and source managers, if needed.
  556. if (!CI.hasFileManager()) {
  557. if (!CI.createFileManager()) {
  558. goto failure;
  559. }
  560. }
  561. if (!CI.hasSourceManager())
  562. CI.createSourceManager(CI.getFileManager());
  563. // Set up embedding for any specified files. Do this before we load any
  564. // source files, including the primary module map for the compilation.
  565. for (const auto &F : CI.getFrontendOpts().ModulesEmbedFiles) {
  566. if (const auto *FE = CI.getFileManager().getFile(F, /*openFile*/true))
  567. CI.getSourceManager().setFileIsTransient(FE);
  568. else
  569. CI.getDiagnostics().Report(diag::err_modules_embed_file_not_found) << F;
  570. }
  571. if (CI.getFrontendOpts().ModulesEmbedAllFiles)
  572. CI.getSourceManager().setAllFilesAreTransient(true);
  573. // IR files bypass the rest of initialization.
  574. if (Input.getKind().getLanguage() == InputKind::LLVM_IR) {
  575. assert(hasIRSupport() &&
  576. "This action does not have IR file support!");
  577. // Inform the diagnostic client we are processing a source file.
  578. CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
  579. HasBegunSourceFile = true;
  580. // Initialize the action.
  581. if (!BeginSourceFileAction(CI))
  582. goto failure;
  583. // Initialize the main file entry.
  584. if (!CI.InitializeSourceManager(CurrentInput))
  585. goto failure;
  586. return true;
  587. }
  588. // If the implicit PCH include is actually a directory, rather than
  589. // a single file, search for a suitable PCH file in that directory.
  590. if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
  591. FileManager &FileMgr = CI.getFileManager();
  592. PreprocessorOptions &PPOpts = CI.getPreprocessorOpts();
  593. StringRef PCHInclude = PPOpts.ImplicitPCHInclude;
  594. std::string SpecificModuleCachePath = CI.getSpecificModuleCachePath();
  595. if (const DirectoryEntry *PCHDir = FileMgr.getDirectory(PCHInclude)) {
  596. std::error_code EC;
  597. SmallString<128> DirNative;
  598. llvm::sys::path::native(PCHDir->getName(), DirNative);
  599. bool Found = false;
  600. llvm::vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem();
  601. for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC),
  602. DirEnd;
  603. Dir != DirEnd && !EC; Dir.increment(EC)) {
  604. // Check whether this is an acceptable AST file.
  605. if (ASTReader::isAcceptableASTFile(
  606. Dir->path(), FileMgr, CI.getPCHContainerReader(),
  607. CI.getLangOpts(), CI.getTargetOpts(), CI.getPreprocessorOpts(),
  608. SpecificModuleCachePath)) {
  609. PPOpts.ImplicitPCHInclude = Dir->path();
  610. Found = true;
  611. break;
  612. }
  613. }
  614. if (!Found) {
  615. CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude;
  616. goto failure;
  617. }
  618. }
  619. }
  620. // Set up the preprocessor if needed. When parsing model files the
  621. // preprocessor of the original source is reused.
  622. if (!isModelParsingAction())
  623. CI.createPreprocessor(getTranslationUnitKind());
  624. // Inform the diagnostic client we are processing a source file.
  625. CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(),
  626. &CI.getPreprocessor());
  627. HasBegunSourceFile = true;
  628. // Initialize the main file entry.
  629. if (!CI.InitializeSourceManager(Input))
  630. goto failure;
  631. // For module map files, we first parse the module map and synthesize a
  632. // "<module-includes>" buffer before more conventional processing.
  633. if (Input.getKind().getFormat() == InputKind::ModuleMap) {
  634. CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleMap);
  635. std::string PresumedModuleMapFile;
  636. unsigned OffsetToContents;
  637. if (loadModuleMapForModuleBuild(CI, Input.isSystem(),
  638. Input.isPreprocessed(),
  639. PresumedModuleMapFile, OffsetToContents))
  640. goto failure;
  641. auto *CurrentModule = prepareToBuildModule(CI, Input.getFile());
  642. if (!CurrentModule)
  643. goto failure;
  644. CurrentModule->PresumedModuleMapFile = PresumedModuleMapFile;
  645. if (OffsetToContents)
  646. // If the module contents are in the same file, skip to them.
  647. CI.getPreprocessor().setSkipMainFilePreamble(OffsetToContents, true);
  648. else {
  649. // Otherwise, convert the module description to a suitable input buffer.
  650. auto Buffer = getInputBufferForModule(CI, CurrentModule);
  651. if (!Buffer)
  652. goto failure;
  653. // Reinitialize the main file entry to refer to the new input.
  654. auto Kind = CurrentModule->IsSystem ? SrcMgr::C_System : SrcMgr::C_User;
  655. auto &SourceMgr = CI.getSourceManager();
  656. auto BufferID = SourceMgr.createFileID(std::move(Buffer), Kind);
  657. assert(BufferID.isValid() && "couldn't creaate module buffer ID");
  658. SourceMgr.setMainFileID(BufferID);
  659. }
  660. }
  661. // Initialize the action.
  662. if (!BeginSourceFileAction(CI))
  663. goto failure;
  664. // If we were asked to load any module map files, do so now.
  665. for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
  666. if (auto *File = CI.getFileManager().getFile(Filename))
  667. CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile(
  668. File, /*IsSystem*/false);
  669. else
  670. CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
  671. }
  672. // Add a module declaration scope so that modules from -fmodule-map-file
  673. // arguments may shadow modules found implicitly in search paths.
  674. CI.getPreprocessor()
  675. .getHeaderSearchInfo()
  676. .getModuleMap()
  677. .finishModuleDeclarationScope();
  678. // Create the AST context and consumer unless this is a preprocessor only
  679. // action.
  680. if (!usesPreprocessorOnly()) {
  681. // Parsing a model file should reuse the existing ASTContext.
  682. if (!isModelParsingAction())
  683. CI.createASTContext();
  684. // For preprocessed files, check if the first line specifies the original
  685. // source file name with a linemarker.
  686. std::string PresumedInputFile = getCurrentFileOrBufferName();
  687. if (Input.isPreprocessed())
  688. ReadOriginalFileName(CI, PresumedInputFile);
  689. std::unique_ptr<ASTConsumer> Consumer =
  690. CreateWrappedASTConsumer(CI, PresumedInputFile);
  691. if (!Consumer)
  692. goto failure;
  693. // FIXME: should not overwrite ASTMutationListener when parsing model files?
  694. if (!isModelParsingAction())
  695. CI.getASTContext().setASTMutationListener(Consumer->GetASTMutationListener());
  696. if (!CI.getPreprocessorOpts().ChainedIncludes.empty()) {
  697. // Convert headers to PCH and chain them.
  698. IntrusiveRefCntPtr<ExternalSemaSource> source, FinalReader;
  699. source = createChainedIncludesSource(CI, FinalReader);
  700. if (!source)
  701. goto failure;
  702. CI.setModuleManager(static_cast<ASTReader *>(FinalReader.get()));
  703. CI.getASTContext().setExternalSource(source);
  704. } else if (CI.getLangOpts().Modules ||
  705. !CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
  706. // Use PCM or PCH.
  707. assert(hasPCHSupport() && "This action does not have PCH support!");
  708. ASTDeserializationListener *DeserialListener =
  709. Consumer->GetASTDeserializationListener();
  710. bool DeleteDeserialListener = false;
  711. if (CI.getPreprocessorOpts().DumpDeserializedPCHDecls) {
  712. DeserialListener = new DeserializedDeclsDumper(DeserialListener,
  713. DeleteDeserialListener);
  714. DeleteDeserialListener = true;
  715. }
  716. if (!CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn.empty()) {
  717. DeserialListener = new DeserializedDeclsChecker(
  718. CI.getASTContext(),
  719. CI.getPreprocessorOpts().DeserializedPCHDeclsToErrorOn,
  720. DeserialListener, DeleteDeserialListener);
  721. DeleteDeserialListener = true;
  722. }
  723. if (!CI.getPreprocessorOpts().ImplicitPCHInclude.empty()) {
  724. CI.createPCHExternalASTSource(
  725. CI.getPreprocessorOpts().ImplicitPCHInclude,
  726. CI.getPreprocessorOpts().DisablePCHValidation,
  727. CI.getPreprocessorOpts().AllowPCHWithCompilerErrors, DeserialListener,
  728. DeleteDeserialListener);
  729. if (!CI.getASTContext().getExternalSource())
  730. goto failure;
  731. }
  732. // If modules are enabled, create the module manager before creating
  733. // any builtins, so that all declarations know that they might be
  734. // extended by an external source.
  735. if (CI.getLangOpts().Modules || !CI.hasASTContext() ||
  736. !CI.getASTContext().getExternalSource()) {
  737. CI.createModuleManager();
  738. CI.getModuleManager()->setDeserializationListener(DeserialListener,
  739. DeleteDeserialListener);
  740. }
  741. }
  742. CI.setASTConsumer(std::move(Consumer));
  743. if (!CI.hasASTConsumer())
  744. goto failure;
  745. }
  746. // Initialize built-in info as long as we aren't using an external AST
  747. // source.
  748. if (CI.getLangOpts().Modules || !CI.hasASTContext() ||
  749. !CI.getASTContext().getExternalSource()) {
  750. Preprocessor &PP = CI.getPreprocessor();
  751. PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(),
  752. PP.getLangOpts());
  753. } else {
  754. // FIXME: If this is a problem, recover from it by creating a multiplex
  755. // source.
  756. assert((!CI.getLangOpts().Modules || CI.getModuleManager()) &&
  757. "modules enabled but created an external source that "
  758. "doesn't support modules");
  759. }
  760. // If we were asked to load any module files, do so now.
  761. for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles)
  762. if (!CI.loadModuleFile(ModuleFile))
  763. goto failure;
  764. // If there is a layout overrides file, attach an external AST source that
  765. // provides the layouts from that file.
  766. if (!CI.getFrontendOpts().OverrideRecordLayoutsFile.empty() &&
  767. CI.hasASTContext() && !CI.getASTContext().getExternalSource()) {
  768. IntrusiveRefCntPtr<ExternalASTSource>
  769. Override(new LayoutOverrideSource(
  770. CI.getFrontendOpts().OverrideRecordLayoutsFile));
  771. CI.getASTContext().setExternalSource(Override);
  772. }
  773. return true;
  774. // If we failed, reset state since the client will not end up calling the
  775. // matching EndSourceFile().
  776. failure:
  777. if (HasBegunSourceFile)
  778. CI.getDiagnosticClient().EndSourceFile();
  779. CI.clearOutputFiles(/*EraseFiles=*/true);
  780. CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
  781. setCurrentInput(FrontendInputFile());
  782. setCompilerInstance(nullptr);
  783. return false;
  784. }
  785. bool FrontendAction::Execute() {
  786. CompilerInstance &CI = getCompilerInstance();
  787. if (CI.hasFrontendTimer()) {
  788. llvm::TimeRegion Timer(CI.getFrontendTimer());
  789. ExecuteAction();
  790. }
  791. else ExecuteAction();
  792. // If we are supposed to rebuild the global module index, do so now unless
  793. // there were any module-build failures.
  794. if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() &&
  795. CI.hasPreprocessor()) {
  796. StringRef Cache =
  797. CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath();
  798. if (!Cache.empty())
  799. GlobalModuleIndex::writeIndex(CI.getFileManager(),
  800. CI.getPCHContainerReader(), Cache);
  801. }
  802. return true;
  803. }
  804. void FrontendAction::EndSourceFile() {
  805. CompilerInstance &CI = getCompilerInstance();
  806. // Inform the diagnostic client we are done with this source file.
  807. CI.getDiagnosticClient().EndSourceFile();
  808. // Inform the preprocessor we are done.
  809. if (CI.hasPreprocessor())
  810. CI.getPreprocessor().EndSourceFile();
  811. // Finalize the action.
  812. EndSourceFileAction();
  813. // Sema references the ast consumer, so reset sema first.
  814. //
  815. // FIXME: There is more per-file stuff we could just drop here?
  816. bool DisableFree = CI.getFrontendOpts().DisableFree;
  817. if (DisableFree) {
  818. CI.resetAndLeakSema();
  819. CI.resetAndLeakASTContext();
  820. BuryPointer(CI.takeASTConsumer().get());
  821. } else {
  822. CI.setSema(nullptr);
  823. CI.setASTContext(nullptr);
  824. CI.setASTConsumer(nullptr);
  825. }
  826. if (CI.getFrontendOpts().ShowStats) {
  827. llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFile() << "':\n";
  828. CI.getPreprocessor().PrintStats();
  829. CI.getPreprocessor().getIdentifierTable().PrintStats();
  830. CI.getPreprocessor().getHeaderSearchInfo().PrintStats();
  831. CI.getSourceManager().PrintStats();
  832. llvm::errs() << "\n";
  833. }
  834. // Cleanup the output streams, and erase the output files if instructed by the
  835. // FrontendAction.
  836. CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles());
  837. if (isCurrentFileAST()) {
  838. if (DisableFree) {
  839. CI.resetAndLeakPreprocessor();
  840. CI.resetAndLeakSourceManager();
  841. CI.resetAndLeakFileManager();
  842. BuryPointer(CurrentASTUnit.release());
  843. } else {
  844. CI.setPreprocessor(nullptr);
  845. CI.setSourceManager(nullptr);
  846. CI.setFileManager(nullptr);
  847. }
  848. }
  849. setCompilerInstance(nullptr);
  850. setCurrentInput(FrontendInputFile());
  851. CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
  852. }
  853. bool FrontendAction::shouldEraseOutputFiles() {
  854. return getCompilerInstance().getDiagnostics().hasErrorOccurred();
  855. }
  856. //===----------------------------------------------------------------------===//
  857. // Utility Actions
  858. //===----------------------------------------------------------------------===//
  859. void ASTFrontendAction::ExecuteAction() {
  860. CompilerInstance &CI = getCompilerInstance();
  861. if (!CI.hasPreprocessor())
  862. return;
  863. // FIXME: Move the truncation aspect of this into Sema, we delayed this till
  864. // here so the source manager would be initialized.
  865. if (hasCodeCompletionSupport() &&
  866. !CI.getFrontendOpts().CodeCompletionAt.FileName.empty())
  867. CI.createCodeCompletionConsumer();
  868. // Use a code completion consumer?
  869. CodeCompleteConsumer *CompletionConsumer = nullptr;
  870. if (CI.hasCodeCompletionConsumer())
  871. CompletionConsumer = &CI.getCodeCompletionConsumer();
  872. if (!CI.hasSema())
  873. CI.createSema(getTranslationUnitKind(), CompletionConsumer);
  874. ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats,
  875. CI.getFrontendOpts().SkipFunctionBodies);
  876. }
  877. void PluginASTAction::anchor() { }
  878. std::unique_ptr<ASTConsumer>
  879. PreprocessorFrontendAction::CreateASTConsumer(CompilerInstance &CI,
  880. StringRef InFile) {
  881. llvm_unreachable("Invalid CreateASTConsumer on preprocessor action!");
  882. }
  883. std::unique_ptr<ASTConsumer>
  884. WrapperFrontendAction::CreateASTConsumer(CompilerInstance &CI,
  885. StringRef InFile) {
  886. return WrappedAction->CreateASTConsumer(CI, InFile);
  887. }
  888. bool WrapperFrontendAction::BeginInvocation(CompilerInstance &CI) {
  889. return WrappedAction->BeginInvocation(CI);
  890. }
  891. bool WrapperFrontendAction::BeginSourceFileAction(CompilerInstance &CI) {
  892. WrappedAction->setCurrentInput(getCurrentInput());
  893. WrappedAction->setCompilerInstance(&CI);
  894. auto Ret = WrappedAction->BeginSourceFileAction(CI);
  895. // BeginSourceFileAction may change CurrentInput, e.g. during module builds.
  896. setCurrentInput(WrappedAction->getCurrentInput());
  897. return Ret;
  898. }
  899. void WrapperFrontendAction::ExecuteAction() {
  900. WrappedAction->ExecuteAction();
  901. }
  902. void WrapperFrontendAction::EndSourceFileAction() {
  903. WrappedAction->EndSourceFileAction();
  904. }
  905. bool WrapperFrontendAction::usesPreprocessorOnly() const {
  906. return WrappedAction->usesPreprocessorOnly();
  907. }
  908. TranslationUnitKind WrapperFrontendAction::getTranslationUnitKind() {
  909. return WrappedAction->getTranslationUnitKind();
  910. }
  911. bool WrapperFrontendAction::hasPCHSupport() const {
  912. return WrappedAction->hasPCHSupport();
  913. }
  914. bool WrapperFrontendAction::hasASTFileSupport() const {
  915. return WrappedAction->hasASTFileSupport();
  916. }
  917. bool WrapperFrontendAction::hasIRSupport() const {
  918. return WrappedAction->hasIRSupport();
  919. }
  920. bool WrapperFrontendAction::hasCodeCompletionSupport() const {
  921. return WrappedAction->hasCodeCompletionSupport();
  922. }
  923. WrapperFrontendAction::WrapperFrontendAction(
  924. std::unique_ptr<FrontendAction> WrappedAction)
  925. : WrappedAction(std::move(WrappedAction)) {}