Module.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. //===- Module.cpp - Describe a module -------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the Module class, which describes a module in the source
  10. // code.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Basic/Module.h"
  14. #include "clang/Basic/CharInfo.h"
  15. #include "clang/Basic/FileManager.h"
  16. #include "clang/Basic/LangOptions.h"
  17. #include "clang/Basic/SourceLocation.h"
  18. #include "clang/Basic/TargetInfo.h"
  19. #include "llvm/ADT/ArrayRef.h"
  20. #include "llvm/ADT/SmallVector.h"
  21. #include "llvm/ADT/StringMap.h"
  22. #include "llvm/ADT/StringRef.h"
  23. #include "llvm/ADT/StringSwitch.h"
  24. #include "llvm/Support/Compiler.h"
  25. #include "llvm/Support/ErrorHandling.h"
  26. #include "llvm/Support/raw_ostream.h"
  27. #include <algorithm>
  28. #include <cassert>
  29. #include <functional>
  30. #include <string>
  31. #include <utility>
  32. #include <vector>
  33. using namespace clang;
  34. Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
  35. bool IsFramework, bool IsExplicit, unsigned VisibilityID)
  36. : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent),
  37. VisibilityID(VisibilityID), IsMissingRequirement(false),
  38. HasIncompatibleModuleFile(false), IsAvailable(true),
  39. IsFromModuleFile(false), IsFramework(IsFramework), IsExplicit(IsExplicit),
  40. IsSystem(false), IsExternC(false), IsInferred(false),
  41. InferSubmodules(false), InferExplicitSubmodules(false),
  42. InferExportWildcard(false), ConfigMacrosExhaustive(false),
  43. NoUndeclaredIncludes(false), ModuleMapIsPrivate(false),
  44. NameVisibility(Hidden) {
  45. if (Parent) {
  46. if (!Parent->isAvailable())
  47. IsAvailable = false;
  48. if (Parent->IsSystem)
  49. IsSystem = true;
  50. if (Parent->IsExternC)
  51. IsExternC = true;
  52. if (Parent->NoUndeclaredIncludes)
  53. NoUndeclaredIncludes = true;
  54. if (Parent->ModuleMapIsPrivate)
  55. ModuleMapIsPrivate = true;
  56. IsMissingRequirement = Parent->IsMissingRequirement;
  57. Parent->SubModuleIndex[Name] = Parent->SubModules.size();
  58. Parent->SubModules.push_back(this);
  59. }
  60. }
  61. Module::~Module() {
  62. for (submodule_iterator I = submodule_begin(), IEnd = submodule_end();
  63. I != IEnd; ++I) {
  64. delete *I;
  65. }
  66. }
  67. static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) {
  68. StringRef Platform = Target.getPlatformName();
  69. StringRef Env = Target.getTriple().getEnvironmentName();
  70. // Attempt to match platform and environment.
  71. if (Platform == Feature || Target.getTriple().getOSName() == Feature ||
  72. Env == Feature)
  73. return true;
  74. auto CmpPlatformEnv = [](StringRef LHS, StringRef RHS) {
  75. auto Pos = LHS.find("-");
  76. if (Pos == StringRef::npos)
  77. return false;
  78. SmallString<128> NewLHS = LHS.slice(0, Pos);
  79. NewLHS += LHS.slice(Pos+1, LHS.size());
  80. return NewLHS == RHS;
  81. };
  82. SmallString<128> PlatformEnv = Target.getTriple().getOSAndEnvironmentName();
  83. // Darwin has different but equivalent variants for simulators, example:
  84. // 1. x86_64-apple-ios-simulator
  85. // 2. x86_64-apple-iossimulator
  86. // where both are valid examples of the same platform+environment but in the
  87. // variant (2) the simulator is hardcoded as part of the platform name. Both
  88. // forms above should match for "iossimulator" requirement.
  89. if (Target.getTriple().isOSDarwin() && PlatformEnv.endswith("simulator"))
  90. return PlatformEnv == Feature || CmpPlatformEnv(PlatformEnv, Feature);
  91. return PlatformEnv == Feature;
  92. }
  93. /// Determine whether a translation unit built using the current
  94. /// language options has the given feature.
  95. static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
  96. const TargetInfo &Target) {
  97. bool HasFeature = llvm::StringSwitch<bool>(Feature)
  98. .Case("altivec", LangOpts.AltiVec)
  99. .Case("blocks", LangOpts.Blocks)
  100. .Case("coroutines", LangOpts.Coroutines)
  101. .Case("cplusplus", LangOpts.CPlusPlus)
  102. .Case("cplusplus11", LangOpts.CPlusPlus11)
  103. .Case("cplusplus14", LangOpts.CPlusPlus14)
  104. .Case("cplusplus17", LangOpts.CPlusPlus17)
  105. .Case("c99", LangOpts.C99)
  106. .Case("c11", LangOpts.C11)
  107. .Case("c17", LangOpts.C17)
  108. .Case("freestanding", LangOpts.Freestanding)
  109. .Case("gnuinlineasm", LangOpts.GNUAsm)
  110. .Case("objc", LangOpts.ObjC)
  111. .Case("objc_arc", LangOpts.ObjCAutoRefCount)
  112. .Case("opencl", LangOpts.OpenCL)
  113. .Case("tls", Target.isTLSSupported())
  114. .Case("zvector", LangOpts.ZVector)
  115. .Default(Target.hasFeature(Feature) ||
  116. isPlatformEnvironment(Target, Feature));
  117. if (!HasFeature)
  118. HasFeature = std::find(LangOpts.ModuleFeatures.begin(),
  119. LangOpts.ModuleFeatures.end(),
  120. Feature) != LangOpts.ModuleFeatures.end();
  121. return HasFeature;
  122. }
  123. bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target,
  124. Requirement &Req,
  125. UnresolvedHeaderDirective &MissingHeader,
  126. Module *&ShadowingModule) const {
  127. if (IsAvailable)
  128. return true;
  129. for (const Module *Current = this; Current; Current = Current->Parent) {
  130. if (Current->ShadowingModule) {
  131. ShadowingModule = Current->ShadowingModule;
  132. return false;
  133. }
  134. for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
  135. if (hasFeature(Current->Requirements[I].first, LangOpts, Target) !=
  136. Current->Requirements[I].second) {
  137. Req = Current->Requirements[I];
  138. return false;
  139. }
  140. }
  141. if (!Current->MissingHeaders.empty()) {
  142. MissingHeader = Current->MissingHeaders.front();
  143. return false;
  144. }
  145. }
  146. llvm_unreachable("could not find a reason why module is unavailable");
  147. }
  148. bool Module::isSubModuleOf(const Module *Other) const {
  149. const Module *This = this;
  150. do {
  151. if (This == Other)
  152. return true;
  153. This = This->Parent;
  154. } while (This);
  155. return false;
  156. }
  157. const Module *Module::getTopLevelModule() const {
  158. const Module *Result = this;
  159. while (Result->Parent)
  160. Result = Result->Parent;
  161. return Result;
  162. }
  163. static StringRef getModuleNameFromComponent(
  164. const std::pair<std::string, SourceLocation> &IdComponent) {
  165. return IdComponent.first;
  166. }
  167. static StringRef getModuleNameFromComponent(StringRef R) { return R; }
  168. template<typename InputIter>
  169. static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End,
  170. bool AllowStringLiterals = true) {
  171. for (InputIter It = Begin; It != End; ++It) {
  172. if (It != Begin)
  173. OS << ".";
  174. StringRef Name = getModuleNameFromComponent(*It);
  175. if (!AllowStringLiterals || isValidIdentifier(Name))
  176. OS << Name;
  177. else {
  178. OS << '"';
  179. OS.write_escaped(Name);
  180. OS << '"';
  181. }
  182. }
  183. }
  184. template<typename Container>
  185. static void printModuleId(raw_ostream &OS, const Container &C) {
  186. return printModuleId(OS, C.begin(), C.end());
  187. }
  188. std::string Module::getFullModuleName(bool AllowStringLiterals) const {
  189. SmallVector<StringRef, 2> Names;
  190. // Build up the set of module names (from innermost to outermost).
  191. for (const Module *M = this; M; M = M->Parent)
  192. Names.push_back(M->Name);
  193. std::string Result;
  194. llvm::raw_string_ostream Out(Result);
  195. printModuleId(Out, Names.rbegin(), Names.rend(), AllowStringLiterals);
  196. Out.flush();
  197. return Result;
  198. }
  199. bool Module::fullModuleNameIs(ArrayRef<StringRef> nameParts) const {
  200. for (const Module *M = this; M; M = M->Parent) {
  201. if (nameParts.empty() || M->Name != nameParts.back())
  202. return false;
  203. nameParts = nameParts.drop_back();
  204. }
  205. return nameParts.empty();
  206. }
  207. Module::DirectoryName Module::getUmbrellaDir() const {
  208. if (Header U = getUmbrellaHeader())
  209. return {"", U.Entry->getDir()};
  210. return {UmbrellaAsWritten, Umbrella.dyn_cast<const DirectoryEntry *>()};
  211. }
  212. ArrayRef<const FileEntry *> Module::getTopHeaders(FileManager &FileMgr) {
  213. if (!TopHeaderNames.empty()) {
  214. for (std::vector<std::string>::iterator
  215. I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; ++I) {
  216. if (const FileEntry *FE = FileMgr.getFile(*I))
  217. TopHeaders.insert(FE);
  218. }
  219. TopHeaderNames.clear();
  220. }
  221. return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
  222. }
  223. bool Module::directlyUses(const Module *Requested) const {
  224. auto *Top = getTopLevelModule();
  225. // A top-level module implicitly uses itself.
  226. if (Requested->isSubModuleOf(Top))
  227. return true;
  228. for (auto *Use : Top->DirectUses)
  229. if (Requested->isSubModuleOf(Use))
  230. return true;
  231. // Anyone is allowed to use our builtin stddef.h and its accompanying module.
  232. if (!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t")
  233. return true;
  234. return false;
  235. }
  236. void Module::addRequirement(StringRef Feature, bool RequiredState,
  237. const LangOptions &LangOpts,
  238. const TargetInfo &Target) {
  239. Requirements.push_back(Requirement(Feature, RequiredState));
  240. // If this feature is currently available, we're done.
  241. if (hasFeature(Feature, LangOpts, Target) == RequiredState)
  242. return;
  243. markUnavailable(/*MissingRequirement*/true);
  244. }
  245. void Module::markUnavailable(bool MissingRequirement) {
  246. auto needUpdate = [MissingRequirement](Module *M) {
  247. return M->IsAvailable || (!M->IsMissingRequirement && MissingRequirement);
  248. };
  249. if (!needUpdate(this))
  250. return;
  251. SmallVector<Module *, 2> Stack;
  252. Stack.push_back(this);
  253. while (!Stack.empty()) {
  254. Module *Current = Stack.back();
  255. Stack.pop_back();
  256. if (!needUpdate(Current))
  257. continue;
  258. Current->IsAvailable = false;
  259. Current->IsMissingRequirement |= MissingRequirement;
  260. for (submodule_iterator Sub = Current->submodule_begin(),
  261. SubEnd = Current->submodule_end();
  262. Sub != SubEnd; ++Sub) {
  263. if (needUpdate(*Sub))
  264. Stack.push_back(*Sub);
  265. }
  266. }
  267. }
  268. Module *Module::findSubmodule(StringRef Name) const {
  269. llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
  270. if (Pos == SubModuleIndex.end())
  271. return nullptr;
  272. return SubModules[Pos->getValue()];
  273. }
  274. void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const {
  275. // All non-explicit submodules are exported.
  276. for (std::vector<Module *>::const_iterator I = SubModules.begin(),
  277. E = SubModules.end();
  278. I != E; ++I) {
  279. Module *Mod = *I;
  280. if (!Mod->IsExplicit)
  281. Exported.push_back(Mod);
  282. }
  283. // Find re-exported modules by filtering the list of imported modules.
  284. bool AnyWildcard = false;
  285. bool UnrestrictedWildcard = false;
  286. SmallVector<Module *, 4> WildcardRestrictions;
  287. for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
  288. Module *Mod = Exports[I].getPointer();
  289. if (!Exports[I].getInt()) {
  290. // Export a named module directly; no wildcards involved.
  291. Exported.push_back(Mod);
  292. continue;
  293. }
  294. // Wildcard export: export all of the imported modules that match
  295. // the given pattern.
  296. AnyWildcard = true;
  297. if (UnrestrictedWildcard)
  298. continue;
  299. if (Module *Restriction = Exports[I].getPointer())
  300. WildcardRestrictions.push_back(Restriction);
  301. else {
  302. WildcardRestrictions.clear();
  303. UnrestrictedWildcard = true;
  304. }
  305. }
  306. // If there were any wildcards, push any imported modules that were
  307. // re-exported by the wildcard restriction.
  308. if (!AnyWildcard)
  309. return;
  310. for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
  311. Module *Mod = Imports[I];
  312. bool Acceptable = UnrestrictedWildcard;
  313. if (!Acceptable) {
  314. // Check whether this module meets one of the restrictions.
  315. for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) {
  316. Module *Restriction = WildcardRestrictions[R];
  317. if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) {
  318. Acceptable = true;
  319. break;
  320. }
  321. }
  322. }
  323. if (!Acceptable)
  324. continue;
  325. Exported.push_back(Mod);
  326. }
  327. }
  328. void Module::buildVisibleModulesCache() const {
  329. assert(VisibleModulesCache.empty() && "cache does not need building");
  330. // This module is visible to itself.
  331. VisibleModulesCache.insert(this);
  332. // Every imported module is visible.
  333. SmallVector<Module *, 16> Stack(Imports.begin(), Imports.end());
  334. while (!Stack.empty()) {
  335. Module *CurrModule = Stack.pop_back_val();
  336. // Every module transitively exported by an imported module is visible.
  337. if (VisibleModulesCache.insert(CurrModule).second)
  338. CurrModule->getExportedModules(Stack);
  339. }
  340. }
  341. void Module::print(raw_ostream &OS, unsigned Indent) const {
  342. OS.indent(Indent);
  343. if (IsFramework)
  344. OS << "framework ";
  345. if (IsExplicit)
  346. OS << "explicit ";
  347. OS << "module ";
  348. printModuleId(OS, &Name, &Name + 1);
  349. if (IsSystem || IsExternC) {
  350. OS.indent(Indent + 2);
  351. if (IsSystem)
  352. OS << " [system]";
  353. if (IsExternC)
  354. OS << " [extern_c]";
  355. }
  356. OS << " {\n";
  357. if (!Requirements.empty()) {
  358. OS.indent(Indent + 2);
  359. OS << "requires ";
  360. for (unsigned I = 0, N = Requirements.size(); I != N; ++I) {
  361. if (I)
  362. OS << ", ";
  363. if (!Requirements[I].second)
  364. OS << "!";
  365. OS << Requirements[I].first;
  366. }
  367. OS << "\n";
  368. }
  369. if (Header H = getUmbrellaHeader()) {
  370. OS.indent(Indent + 2);
  371. OS << "umbrella header \"";
  372. OS.write_escaped(H.NameAsWritten);
  373. OS << "\"\n";
  374. } else if (DirectoryName D = getUmbrellaDir()) {
  375. OS.indent(Indent + 2);
  376. OS << "umbrella \"";
  377. OS.write_escaped(D.NameAsWritten);
  378. OS << "\"\n";
  379. }
  380. if (!ConfigMacros.empty() || ConfigMacrosExhaustive) {
  381. OS.indent(Indent + 2);
  382. OS << "config_macros ";
  383. if (ConfigMacrosExhaustive)
  384. OS << "[exhaustive]";
  385. for (unsigned I = 0, N = ConfigMacros.size(); I != N; ++I) {
  386. if (I)
  387. OS << ", ";
  388. OS << ConfigMacros[I];
  389. }
  390. OS << "\n";
  391. }
  392. struct {
  393. StringRef Prefix;
  394. HeaderKind Kind;
  395. } Kinds[] = {{"", HK_Normal},
  396. {"textual ", HK_Textual},
  397. {"private ", HK_Private},
  398. {"private textual ", HK_PrivateTextual},
  399. {"exclude ", HK_Excluded}};
  400. for (auto &K : Kinds) {
  401. assert(&K == &Kinds[K.Kind] && "kinds in wrong order");
  402. for (auto &H : Headers[K.Kind]) {
  403. OS.indent(Indent + 2);
  404. OS << K.Prefix << "header \"";
  405. OS.write_escaped(H.NameAsWritten);
  406. OS << "\" { size " << H.Entry->getSize()
  407. << " mtime " << H.Entry->getModificationTime() << " }\n";
  408. }
  409. }
  410. for (auto *Unresolved : {&UnresolvedHeaders, &MissingHeaders}) {
  411. for (auto &U : *Unresolved) {
  412. OS.indent(Indent + 2);
  413. OS << Kinds[U.Kind].Prefix << "header \"";
  414. OS.write_escaped(U.FileName);
  415. OS << "\"";
  416. if (U.Size || U.ModTime) {
  417. OS << " {";
  418. if (U.Size)
  419. OS << " size " << *U.Size;
  420. if (U.ModTime)
  421. OS << " mtime " << *U.ModTime;
  422. OS << " }";
  423. }
  424. OS << "\n";
  425. }
  426. }
  427. if (!ExportAsModule.empty()) {
  428. OS.indent(Indent + 2);
  429. OS << "export_as" << ExportAsModule << "\n";
  430. }
  431. for (submodule_const_iterator MI = submodule_begin(), MIEnd = submodule_end();
  432. MI != MIEnd; ++MI)
  433. // Print inferred subframework modules so that we don't need to re-infer
  434. // them (requires expensive directory iteration + stat calls) when we build
  435. // the module. Regular inferred submodules are OK, as we need to look at all
  436. // those header files anyway.
  437. if (!(*MI)->IsInferred || (*MI)->IsFramework)
  438. (*MI)->print(OS, Indent + 2);
  439. for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
  440. OS.indent(Indent + 2);
  441. OS << "export ";
  442. if (Module *Restriction = Exports[I].getPointer()) {
  443. OS << Restriction->getFullModuleName(true);
  444. if (Exports[I].getInt())
  445. OS << ".*";
  446. } else {
  447. OS << "*";
  448. }
  449. OS << "\n";
  450. }
  451. for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) {
  452. OS.indent(Indent + 2);
  453. OS << "export ";
  454. printModuleId(OS, UnresolvedExports[I].Id);
  455. if (UnresolvedExports[I].Wildcard)
  456. OS << (UnresolvedExports[I].Id.empty() ? "*" : ".*");
  457. OS << "\n";
  458. }
  459. for (unsigned I = 0, N = DirectUses.size(); I != N; ++I) {
  460. OS.indent(Indent + 2);
  461. OS << "use ";
  462. OS << DirectUses[I]->getFullModuleName(true);
  463. OS << "\n";
  464. }
  465. for (unsigned I = 0, N = UnresolvedDirectUses.size(); I != N; ++I) {
  466. OS.indent(Indent + 2);
  467. OS << "use ";
  468. printModuleId(OS, UnresolvedDirectUses[I]);
  469. OS << "\n";
  470. }
  471. for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) {
  472. OS.indent(Indent + 2);
  473. OS << "link ";
  474. if (LinkLibraries[I].IsFramework)
  475. OS << "framework ";
  476. OS << "\"";
  477. OS.write_escaped(LinkLibraries[I].Library);
  478. OS << "\"";
  479. }
  480. for (unsigned I = 0, N = UnresolvedConflicts.size(); I != N; ++I) {
  481. OS.indent(Indent + 2);
  482. OS << "conflict ";
  483. printModuleId(OS, UnresolvedConflicts[I].Id);
  484. OS << ", \"";
  485. OS.write_escaped(UnresolvedConflicts[I].Message);
  486. OS << "\"\n";
  487. }
  488. for (unsigned I = 0, N = Conflicts.size(); I != N; ++I) {
  489. OS.indent(Indent + 2);
  490. OS << "conflict ";
  491. OS << Conflicts[I].Other->getFullModuleName(true);
  492. OS << ", \"";
  493. OS.write_escaped(Conflicts[I].Message);
  494. OS << "\"\n";
  495. }
  496. if (InferSubmodules) {
  497. OS.indent(Indent + 2);
  498. if (InferExplicitSubmodules)
  499. OS << "explicit ";
  500. OS << "module * {\n";
  501. if (InferExportWildcard) {
  502. OS.indent(Indent + 4);
  503. OS << "export *\n";
  504. }
  505. OS.indent(Indent + 2);
  506. OS << "}\n";
  507. }
  508. OS.indent(Indent);
  509. OS << "}\n";
  510. }
  511. LLVM_DUMP_METHOD void Module::dump() const {
  512. print(llvm::errs());
  513. }
  514. void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc,
  515. VisibleCallback Vis, ConflictCallback Cb) {
  516. assert(Loc.isValid() && "setVisible expects a valid import location");
  517. if (isVisible(M))
  518. return;
  519. ++Generation;
  520. struct Visiting {
  521. Module *M;
  522. Visiting *ExportedBy;
  523. };
  524. std::function<void(Visiting)> VisitModule = [&](Visiting V) {
  525. // Nothing to do for a module that's already visible.
  526. unsigned ID = V.M->getVisibilityID();
  527. if (ImportLocs.size() <= ID)
  528. ImportLocs.resize(ID + 1);
  529. else if (ImportLocs[ID].isValid())
  530. return;
  531. ImportLocs[ID] = Loc;
  532. Vis(M);
  533. // Make any exported modules visible.
  534. SmallVector<Module *, 16> Exports;
  535. V.M->getExportedModules(Exports);
  536. for (Module *E : Exports) {
  537. // Don't recurse to unavailable submodules.
  538. if (E->isAvailable())
  539. VisitModule({E, &V});
  540. }
  541. for (auto &C : V.M->Conflicts) {
  542. if (isVisible(C.Other)) {
  543. llvm::SmallVector<Module*, 8> Path;
  544. for (Visiting *I = &V; I; I = I->ExportedBy)
  545. Path.push_back(I->M);
  546. Cb(Path, C.Other, C.Message);
  547. }
  548. }
  549. };
  550. VisitModule({M, nullptr});
  551. }