FrontendAction.cpp 40 KB

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