1 //===--- CompilerInstance.cpp ---------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/Frontend/CompilerInstance.h"
11 #include "clang/AST/ASTConsumer.h"
12 #include "clang/AST/ASTContext.h"
13 #include "clang/AST/Decl.h"
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Basic/FileManager.h"
16 #include "clang/Basic/SourceManager.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Basic/Version.h"
19 #include "clang/Frontend/ChainedDiagnosticConsumer.h"
20 #include "clang/Frontend/FrontendAction.h"
21 #include "clang/Frontend/FrontendActions.h"
22 #include "clang/Frontend/FrontendDiagnostic.h"
23 #include "clang/Frontend/LogDiagnosticPrinter.h"
24 #include "clang/Frontend/SerializedDiagnosticPrinter.h"
25 #include "clang/Frontend/TextDiagnosticPrinter.h"
26 #include "clang/Frontend/Utils.h"
27 #include "clang/Frontend/VerifyDiagnosticConsumer.h"
28 #include "clang/Lex/HeaderSearch.h"
29 #include "clang/Lex/PTHManager.h"
30 #include "clang/Lex/Preprocessor.h"
31 #include "clang/Sema/CodeCompleteConsumer.h"
32 #include "clang/Sema/Sema.h"
33 #include "clang/Serialization/ASTReader.h"
34 #include "llvm/ADT/Statistic.h"
35 #include "llvm/Config/config.h"
36 #include "llvm/Support/CrashRecoveryContext.h"
37 #include "llvm/Support/FileSystem.h"
38 #include "llvm/Support/Host.h"
39 #include "llvm/Support/LockFileManager.h"
40 #include "llvm/Support/MemoryBuffer.h"
41 #include "llvm/Support/Path.h"
42 #include "llvm/Support/Program.h"
43 #include "llvm/Support/Signals.h"
44 #include "llvm/Support/Timer.h"
45 #include "llvm/Support/raw_ostream.h"
46 #include "llvm/Support/system_error.h"
50 using namespace clang;
52 CompilerInstance::CompilerInstance()
53 : Invocation(new CompilerInvocation()), ModuleManager(0),
54 BuildGlobalModuleIndex(false), ModuleBuildFailed(false) {
57 CompilerInstance::~CompilerInstance() {
58 assert(OutputFiles.empty() && "Still output files in flight?");
61 void CompilerInstance::setInvocation(CompilerInvocation *Value) {
65 bool CompilerInstance::shouldBuildGlobalModuleIndex() const {
66 return (BuildGlobalModuleIndex ||
67 (ModuleManager && ModuleManager->isGlobalIndexUnavailable() &&
68 getFrontendOpts().GenerateGlobalModuleIndex)) &&
72 void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) {
76 void CompilerInstance::setTarget(TargetInfo *Value) {
80 void CompilerInstance::setFileManager(FileManager *Value) {
84 void CompilerInstance::setSourceManager(SourceManager *Value) {
88 void CompilerInstance::setPreprocessor(Preprocessor *Value) { PP = Value; }
90 void CompilerInstance::setASTContext(ASTContext *Value) { Context = Value; }
92 void CompilerInstance::setSema(Sema *S) {
96 void CompilerInstance::setASTConsumer(ASTConsumer *Value) {
97 Consumer.reset(Value);
100 void CompilerInstance::setCodeCompletionConsumer(CodeCompleteConsumer *Value) {
101 CompletionConsumer.reset(Value);
105 static void SetUpDiagnosticLog(DiagnosticOptions *DiagOpts,
106 const CodeGenOptions *CodeGenOpts,
107 DiagnosticsEngine &Diags) {
108 std::string ErrorInfo;
109 bool OwnsStream = false;
110 raw_ostream *OS = &llvm::errs();
111 if (DiagOpts->DiagnosticLogFile != "-") {
112 // Create the output stream.
113 llvm::raw_fd_ostream *FileOS(
114 new llvm::raw_fd_ostream(DiagOpts->DiagnosticLogFile.c_str(),
115 ErrorInfo, llvm::raw_fd_ostream::F_Append));
116 if (!ErrorInfo.empty()) {
117 Diags.Report(diag::warn_fe_cc_log_diagnostics_failure)
118 << DiagOpts->DiagnosticLogFile << ErrorInfo;
120 FileOS->SetUnbuffered();
121 FileOS->SetUseAtomicWrites(true);
127 // Chain in the diagnostic client which will log the diagnostics.
128 LogDiagnosticPrinter *Logger = new LogDiagnosticPrinter(*OS, DiagOpts,
131 Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags);
132 Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(), Logger));
135 static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts,
136 DiagnosticsEngine &Diags,
137 StringRef OutputFile) {
138 std::string ErrorInfo;
139 OwningPtr<llvm::raw_fd_ostream> OS;
140 OS.reset(new llvm::raw_fd_ostream(OutputFile.str().c_str(), ErrorInfo,
141 llvm::raw_fd_ostream::F_Binary));
143 if (!ErrorInfo.empty()) {
144 Diags.Report(diag::warn_fe_serialized_diag_failure)
145 << OutputFile << ErrorInfo;
149 DiagnosticConsumer *SerializedConsumer =
150 clang::serialized_diags::create(OS.take(), DiagOpts);
153 Diags.setClient(new ChainedDiagnosticConsumer(Diags.takeClient(),
154 SerializedConsumer));
157 void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client,
158 bool ShouldOwnClient) {
159 Diagnostics = createDiagnostics(&getDiagnosticOpts(), Client,
160 ShouldOwnClient, &getCodeGenOpts());
163 IntrusiveRefCntPtr<DiagnosticsEngine>
164 CompilerInstance::createDiagnostics(DiagnosticOptions *Opts,
165 DiagnosticConsumer *Client,
166 bool ShouldOwnClient,
167 const CodeGenOptions *CodeGenOpts) {
168 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
169 IntrusiveRefCntPtr<DiagnosticsEngine>
170 Diags(new DiagnosticsEngine(DiagID, Opts));
172 // Create the diagnostic client for reporting errors or for
173 // implementing -verify.
175 Diags->setClient(Client, ShouldOwnClient);
177 Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts));
179 // Chain in -verify checker, if requested.
180 if (Opts->VerifyDiagnostics)
181 Diags->setClient(new VerifyDiagnosticConsumer(*Diags));
183 // Chain in -diagnostic-log-file dumper, if requested.
184 if (!Opts->DiagnosticLogFile.empty())
185 SetUpDiagnosticLog(Opts, CodeGenOpts, *Diags);
187 if (!Opts->DiagnosticSerializationFile.empty())
188 SetupSerializedDiagnostics(Opts, *Diags,
189 Opts->DiagnosticSerializationFile);
191 // Configure our handling of diagnostics.
192 ProcessWarningOptions(*Diags, *Opts);
199 void CompilerInstance::createFileManager() {
200 FileMgr = new FileManager(getFileSystemOpts());
205 void CompilerInstance::createSourceManager(FileManager &FileMgr) {
206 SourceMgr = new SourceManager(getDiagnostics(), FileMgr);
211 void CompilerInstance::createPreprocessor() {
212 const PreprocessorOptions &PPOpts = getPreprocessorOpts();
214 // Create a PTH manager if we are using some form of a token cache.
215 PTHManager *PTHMgr = 0;
216 if (!PPOpts.TokenCache.empty())
217 PTHMgr = PTHManager::Create(PPOpts.TokenCache, getDiagnostics());
219 // Create the Preprocessor.
220 HeaderSearch *HeaderInfo = new HeaderSearch(&getHeaderSearchOpts(),
225 PP = new Preprocessor(&getPreprocessorOpts(),
226 getDiagnostics(), getLangOpts(), &getTarget(),
227 getSourceManager(), *HeaderInfo, *this, PTHMgr,
228 /*OwnsHeaderSearch=*/true);
230 // Note that this is different then passing PTHMgr to Preprocessor's ctor.
231 // That argument is used as the IdentifierInfoLookup argument to
232 // IdentifierTable's ctor.
234 PTHMgr->setPreprocessor(&*PP);
235 PP->setPTHManager(PTHMgr);
238 if (PPOpts.DetailedRecord)
239 PP->createPreprocessingRecord();
241 InitializePreprocessor(*PP, PPOpts, getHeaderSearchOpts(), getFrontendOpts());
243 PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP);
245 // Set up the module path, including the hash for the
246 // module-creation options.
247 SmallString<256> SpecificModuleCache(
248 getHeaderSearchOpts().ModuleCachePath);
249 if (!getHeaderSearchOpts().DisableModuleHash)
250 llvm::sys::path::append(SpecificModuleCache,
251 getInvocation().getModuleHash());
252 PP->getHeaderSearchInfo().setModuleCachePath(SpecificModuleCache);
254 // Handle generating dependencies, if requested.
255 const DependencyOutputOptions &DepOpts = getDependencyOutputOpts();
256 if (!DepOpts.OutputFile.empty())
257 AttachDependencyFileGen(*PP, DepOpts);
258 if (!DepOpts.DOTOutputFile.empty())
259 AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile,
260 getHeaderSearchOpts().Sysroot);
263 // Handle generating header include information, if requested.
264 if (DepOpts.ShowHeaderIncludes)
265 AttachHeaderIncludeGen(*PP);
266 if (!DepOpts.HeaderIncludeOutputFile.empty()) {
267 StringRef OutputPath = DepOpts.HeaderIncludeOutputFile;
268 if (OutputPath == "-")
270 AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/true, OutputPath,
271 /*ShowDepth=*/false);
277 void CompilerInstance::createASTContext() {
278 Preprocessor &PP = getPreprocessor();
279 Context = new ASTContext(getLangOpts(), PP.getSourceManager(),
280 &getTarget(), PP.getIdentifierTable(),
281 PP.getSelectorTable(), PP.getBuiltinInfo(),
282 /*size_reserve=*/ 0);
287 void CompilerInstance::createPCHExternalASTSource(StringRef Path,
288 bool DisablePCHValidation,
289 bool AllowPCHWithCompilerErrors,
290 void *DeserializationListener){
291 OwningPtr<ExternalASTSource> Source;
292 bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
293 Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
294 DisablePCHValidation,
295 AllowPCHWithCompilerErrors,
296 getPreprocessor(), getASTContext(),
297 DeserializationListener,
299 getFrontendOpts().UseGlobalModuleIndex));
300 ModuleManager = static_cast<ASTReader*>(Source.get());
301 getASTContext().setExternalSource(Source);
305 CompilerInstance::createPCHExternalASTSource(StringRef Path,
306 const std::string &Sysroot,
307 bool DisablePCHValidation,
308 bool AllowPCHWithCompilerErrors,
311 void *DeserializationListener,
313 bool UseGlobalModuleIndex) {
314 OwningPtr<ASTReader> Reader;
315 Reader.reset(new ASTReader(PP, Context,
316 Sysroot.empty() ? "" : Sysroot.c_str(),
317 DisablePCHValidation,
318 AllowPCHWithCompilerErrors,
319 UseGlobalModuleIndex));
321 Reader->setDeserializationListener(
322 static_cast<ASTDeserializationListener *>(DeserializationListener));
323 switch (Reader->ReadAST(Path,
324 Preamble ? serialization::MK_Preamble
325 : serialization::MK_PCH,
327 ASTReader::ARR_None)) {
328 case ASTReader::Success:
329 // Set the predefines buffer as suggested by the PCH reader. Typically, the
330 // predefines buffer will be empty.
331 PP.setPredefines(Reader->getSuggestedPredefines());
332 return Reader.take();
334 case ASTReader::Failure:
335 // Unrecoverable failure: don't even try to process the input file.
338 case ASTReader::Missing:
339 case ASTReader::OutOfDate:
340 case ASTReader::VersionMismatch:
341 case ASTReader::ConfigurationMismatch:
342 case ASTReader::HadErrors:
343 // No suitable PCH file could be found. Return an error.
352 static bool EnableCodeCompletion(Preprocessor &PP,
353 const std::string &Filename,
356 // Tell the source manager to chop off the given file at a specific
358 const FileEntry *Entry = PP.getFileManager().getFile(Filename);
360 PP.getDiagnostics().Report(diag::err_fe_invalid_code_complete_file)
365 // Truncate the named file at the given line/column.
366 PP.SetCodeCompletionPoint(Entry, Line, Column);
370 void CompilerInstance::createCodeCompletionConsumer() {
371 const ParsedSourceLocation &Loc = getFrontendOpts().CodeCompletionAt;
372 if (!CompletionConsumer) {
373 setCodeCompletionConsumer(
374 createCodeCompletionConsumer(getPreprocessor(),
375 Loc.FileName, Loc.Line, Loc.Column,
376 getFrontendOpts().CodeCompleteOpts,
378 if (!CompletionConsumer)
380 } else if (EnableCodeCompletion(getPreprocessor(), Loc.FileName,
381 Loc.Line, Loc.Column)) {
382 setCodeCompletionConsumer(0);
386 if (CompletionConsumer->isOutputBinary() &&
387 llvm::sys::Program::ChangeStdoutToBinary()) {
388 getPreprocessor().getDiagnostics().Report(diag::err_fe_stdout_binary);
389 setCodeCompletionConsumer(0);
393 void CompilerInstance::createFrontendTimer() {
394 FrontendTimer.reset(new llvm::Timer("Clang front-end timer"));
397 CodeCompleteConsumer *
398 CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
399 const std::string &Filename,
402 const CodeCompleteOptions &Opts,
404 if (EnableCodeCompletion(PP, Filename, Line, Column))
407 // Set up the creation routine for code-completion.
408 return new PrintingCodeCompleteConsumer(Opts, OS);
411 void CompilerInstance::createSema(TranslationUnitKind TUKind,
412 CodeCompleteConsumer *CompletionConsumer) {
413 TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(),
414 TUKind, CompletionConsumer));
419 void CompilerInstance::addOutputFile(const OutputFile &OutFile) {
420 assert(OutFile.OS && "Attempt to add empty stream to output list!");
421 OutputFiles.push_back(OutFile);
424 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
425 for (std::list<OutputFile>::iterator
426 it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) {
428 if (!it->TempFilename.empty()) {
431 llvm::sys::fs::remove(it->TempFilename, existed);
433 SmallString<128> NewOutFile(it->Filename);
435 // If '-working-directory' was passed, the output filename should be
437 FileMgr->FixupRelativePath(NewOutFile);
438 if (llvm::error_code ec = llvm::sys::fs::rename(it->TempFilename,
440 getDiagnostics().Report(diag::err_unable_to_rename_temp)
441 << it->TempFilename << it->Filename << ec.message();
444 llvm::sys::fs::remove(it->TempFilename, existed);
447 } else if (!it->Filename.empty() && EraseFiles)
448 llvm::sys::Path(it->Filename).eraseFromDisk();
454 llvm::raw_fd_ostream *
455 CompilerInstance::createDefaultOutputFile(bool Binary,
457 StringRef Extension) {
458 return createOutputFile(getFrontendOpts().OutputFile, Binary,
459 /*RemoveFileOnSignal=*/true, InFile, Extension,
460 /*UseTemporary=*/true);
463 llvm::raw_fd_ostream *
464 CompilerInstance::createOutputFile(StringRef OutputPath,
465 bool Binary, bool RemoveFileOnSignal,
469 bool CreateMissingDirectories) {
470 std::string Error, OutputPathName, TempPathName;
471 llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary,
475 CreateMissingDirectories,
479 getDiagnostics().Report(diag::err_fe_unable_to_open_output)
480 << OutputPath << Error;
484 // Add the output file -- but don't try to remove "-", since this means we are
486 addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "",
492 llvm::raw_fd_ostream *
493 CompilerInstance::createOutputFile(StringRef OutputPath,
496 bool RemoveFileOnSignal,
500 bool CreateMissingDirectories,
501 std::string *ResultPathName,
502 std::string *TempPathName) {
503 assert((!CreateMissingDirectories || UseTemporary) &&
504 "CreateMissingDirectories is only allowed when using temporary files");
506 std::string OutFile, TempFile;
507 if (!OutputPath.empty()) {
508 OutFile = OutputPath;
509 } else if (InFile == "-") {
511 } else if (!Extension.empty()) {
512 llvm::sys::Path Path(InFile);
514 Path.appendSuffix(Extension);
515 OutFile = Path.str();
520 OwningPtr<llvm::raw_fd_ostream> OS;
523 if (UseTemporary && OutFile != "-") {
524 // Only create the temporary if the parent directory exists (or create
525 // missing directories is true) and we can actually write to OutPath,
526 // otherwise we want to fail early.
527 SmallString<256> AbsPath(OutputPath);
528 llvm::sys::fs::make_absolute(AbsPath);
529 llvm::sys::Path OutPath(AbsPath);
530 bool ParentExists = false;
531 if (llvm::sys::fs::exists(llvm::sys::path::parent_path(AbsPath.str()),
533 ParentExists = false;
535 if ((CreateMissingDirectories || ParentExists) &&
536 ((llvm::sys::fs::exists(AbsPath.str(), Exists) || !Exists) ||
537 (OutPath.isRegularFile() && OutPath.canWrite()))) {
538 // Create a temporary file.
539 SmallString<128> TempPath;
541 TempPath += "-%%%%%%%%";
543 if (llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath,
544 /*makeAbsolute=*/false, 0664)
545 == llvm::errc::success) {
546 OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));
547 OSFile = TempFile = TempPath.str();
555 new llvm::raw_fd_ostream(OSFile.c_str(), Error,
556 (Binary ? llvm::raw_fd_ostream::F_Binary : 0)));
561 // Make sure the out stream file gets removed if we crash.
562 if (RemoveFileOnSignal)
563 llvm::sys::RemoveFileOnSignal(llvm::sys::Path(OSFile));
566 *ResultPathName = OutFile;
568 *TempPathName = TempFile;
573 // Initialization Utilities
575 bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input){
576 return InitializeSourceManager(Input, getDiagnostics(),
577 getFileManager(), getSourceManager(),
581 bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
582 DiagnosticsEngine &Diags,
583 FileManager &FileMgr,
584 SourceManager &SourceMgr,
585 const FrontendOptions &Opts) {
586 SrcMgr::CharacteristicKind
587 Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
589 if (Input.isBuffer()) {
590 SourceMgr.createMainFileIDForMemBuffer(Input.getBuffer(), Kind);
591 assert(!SourceMgr.getMainFileID().isInvalid() &&
592 "Couldn't establish MainFileID!");
596 StringRef InputFile = Input.getFile();
598 // Figure out where to get and map in the main file.
599 if (InputFile != "-") {
600 const FileEntry *File = FileMgr.getFile(InputFile);
602 Diags.Report(diag::err_fe_error_reading) << InputFile;
606 // The natural SourceManager infrastructure can't currently handle named
607 // pipes, but we would at least like to accept them for the main
608 // file. Detect them here, read them with the more generic MemoryBuffer
609 // function, and simply override their contents as we do for STDIN.
610 if (File->isNamedPipe()) {
611 OwningPtr<llvm::MemoryBuffer> MB;
612 if (llvm::error_code ec = llvm::MemoryBuffer::getFile(InputFile, MB)) {
613 Diags.Report(diag::err_cannot_open_file) << InputFile << ec.message();
617 // Create a new virtual file that will have the correct size.
618 File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0);
619 SourceMgr.overrideFileContents(File, MB.take());
622 SourceMgr.createMainFileID(File, Kind);
624 OwningPtr<llvm::MemoryBuffer> SB;
625 if (llvm::MemoryBuffer::getSTDIN(SB)) {
626 // FIXME: Give ec.message() in this diag.
627 Diags.Report(diag::err_fe_error_reading_stdin);
630 const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
631 SB->getBufferSize(), 0);
632 SourceMgr.createMainFileID(File, Kind);
633 SourceMgr.overrideFileContents(File, SB.take());
636 assert(!SourceMgr.getMainFileID().isInvalid() &&
637 "Couldn't establish MainFileID!");
641 // High-Level Operations
643 bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
644 assert(hasDiagnostics() && "Diagnostics engine is not initialized!");
645 assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!");
646 assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!");
648 // FIXME: Take this as an argument, once all the APIs we used have moved to
649 // taking it as an input instead of hard-coding llvm::errs.
650 raw_ostream &OS = llvm::errs();
652 // Create the target instance.
653 setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), &getTargetOpts()));
657 // Inform the target of the language options.
659 // FIXME: We shouldn't need to do this, the target should be immutable once
660 // created. This complexity should be lifted elsewhere.
661 getTarget().setForcedLangOptions(getLangOpts());
663 // rewriter project will change target built-in bool type from its default.
664 if (getFrontendOpts().ProgramAction == frontend::RewriteObjC)
665 getTarget().noSignedCharForObjCBool();
667 // Validate/process some options.
668 if (getHeaderSearchOpts().Verbose)
669 OS << "clang -cc1 version " CLANG_VERSION_STRING
670 << " based upon " << PACKAGE_STRING
671 << " default target " << llvm::sys::getDefaultTargetTriple() << "\n";
673 if (getFrontendOpts().ShowTimers)
674 createFrontendTimer();
676 if (getFrontendOpts().ShowStats)
677 llvm::EnableStatistics();
679 for (unsigned i = 0, e = getFrontendOpts().Inputs.size(); i != e; ++i) {
680 // Reset the ID tables if we are reusing the SourceManager.
681 if (hasSourceManager())
682 getSourceManager().clearIDTables();
684 if (Act.BeginSourceFile(*this, getFrontendOpts().Inputs[i])) {
690 // Notify the diagnostic client that all files were processed.
691 getDiagnostics().getClient()->finish();
693 if (getDiagnosticOpts().ShowCarets) {
694 // We can have multiple diagnostics sharing one diagnostic client.
695 // Get the total number of warnings/errors from the client.
696 unsigned NumWarnings = getDiagnostics().getClient()->getNumWarnings();
697 unsigned NumErrors = getDiagnostics().getClient()->getNumErrors();
700 OS << NumWarnings << " warning" << (NumWarnings == 1 ? "" : "s");
701 if (NumWarnings && NumErrors)
704 OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s");
705 if (NumWarnings || NumErrors)
706 OS << " generated.\n";
709 if (getFrontendOpts().ShowStats && hasFileManager()) {
710 getFileManager().PrintStats();
714 return !getDiagnostics().getClient()->getNumErrors();
717 /// \brief Determine the appropriate source input kind based on language
719 static InputKind getSourceInputKindFromOptions(const LangOptions &LangOpts) {
725 return LangOpts.CPlusPlus? IK_ObjCXX : IK_ObjC;
726 return LangOpts.CPlusPlus? IK_CXX : IK_C;
730 struct CompileModuleMapData {
731 CompilerInstance &Instance;
732 GenerateModuleAction &CreateModuleAction;
736 /// \brief Helper function that executes the module-generating action under
737 /// a crash recovery context.
738 static void doCompileMapModule(void *UserData) {
739 CompileModuleMapData &Data
740 = *reinterpret_cast<CompileModuleMapData *>(UserData);
741 Data.Instance.ExecuteAction(Data.CreateModuleAction);
745 /// \brief Function object that checks with the given macro definition should
746 /// be removed, because it is one of the ignored macros.
747 class RemoveIgnoredMacro {
748 const HeaderSearchOptions &HSOpts;
751 explicit RemoveIgnoredMacro(const HeaderSearchOptions &HSOpts)
754 bool operator()(const std::pair<std::string, bool> &def) const {
755 StringRef MacroDef = def.first;
756 return HSOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first) > 0;
761 /// \brief Compile a module file for the given module, using the options
762 /// provided by the importing compiler instance.
763 static void compileModule(CompilerInstance &ImportingInstance,
764 SourceLocation ImportLoc,
766 StringRef ModuleFileName) {
767 llvm::LockFileManager Locked(ModuleFileName);
769 case llvm::LockFileManager::LFS_Error:
772 case llvm::LockFileManager::LFS_Owned:
773 // We're responsible for building the module ourselves. Do so below.
776 case llvm::LockFileManager::LFS_Shared:
777 // Someone else is responsible for building the module. Wait for them to
779 Locked.waitForUnlock();
784 = ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
786 // Construct a compiler invocation for creating this module.
787 IntrusiveRefCntPtr<CompilerInvocation> Invocation
788 (new CompilerInvocation(ImportingInstance.getInvocation()));
790 PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts();
792 // For any options that aren't intended to affect how a module is built,
793 // reset them to their default values.
794 Invocation->getLangOpts()->resetNonModularOptions();
795 PPOpts.resetNonModularOptions();
797 // Remove any macro definitions that are explicitly ignored by the module.
798 // They aren't supposed to affect how the module is built anyway.
799 const HeaderSearchOptions &HSOpts = Invocation->getHeaderSearchOpts();
800 PPOpts.Macros.erase(std::remove_if(PPOpts.Macros.begin(), PPOpts.Macros.end(),
801 RemoveIgnoredMacro(HSOpts)),
802 PPOpts.Macros.end());
805 // Note the name of the module we're building.
806 Invocation->getLangOpts()->CurrentModule = Module->getTopLevelModuleName();
808 // Make sure that the failed-module structure has been allocated in
809 // the importing instance, and propagate the pointer to the newly-created
811 PreprocessorOptions &ImportingPPOpts
812 = ImportingInstance.getInvocation().getPreprocessorOpts();
813 if (!ImportingPPOpts.FailedModules)
814 ImportingPPOpts.FailedModules = new PreprocessorOptions::FailedModulesSet;
815 PPOpts.FailedModules = ImportingPPOpts.FailedModules;
817 // If there is a module map file, build the module using the module map.
818 // Set up the inputs/outputs so that we build the module from its umbrella
820 FrontendOptions &FrontendOpts = Invocation->getFrontendOpts();
821 FrontendOpts.OutputFile = ModuleFileName.str();
822 FrontendOpts.DisableFree = false;
823 FrontendOpts.GenerateGlobalModuleIndex = false;
824 FrontendOpts.Inputs.clear();
825 InputKind IK = getSourceInputKindFromOptions(*Invocation->getLangOpts());
827 // Get or create the module map that we'll use to build this module.
828 SmallString<128> TempModuleMapFileName;
829 if (const FileEntry *ModuleMapFile
830 = ModMap.getContainingModuleMapFile(Module)) {
831 // Use the module map where this module resides.
832 FrontendOpts.Inputs.push_back(FrontendInputFile(ModuleMapFile->getName(),
835 // Create a temporary module map file.
836 TempModuleMapFileName = Module->Name;
837 TempModuleMapFileName += "-%%%%%%%%.map";
839 if (llvm::sys::fs::unique_file(TempModuleMapFileName.str(), FD,
840 TempModuleMapFileName,
841 /*makeAbsolute=*/true)
842 != llvm::errc::success) {
843 ImportingInstance.getDiagnostics().Report(diag::err_module_map_temp_file)
844 << TempModuleMapFileName;
847 // Print the module map to this file.
848 llvm::raw_fd_ostream OS(FD, /*shouldClose=*/true);
850 FrontendOpts.Inputs.push_back(
851 FrontendInputFile(TempModuleMapFileName.str().str(), IK));
854 // Don't free the remapped file buffers; they are owned by our caller.
855 PPOpts.RetainRemappedFileBuffers = true;
857 Invocation->getDiagnosticOpts().VerifyDiagnostics = 0;
858 assert(ImportingInstance.getInvocation().getModuleHash() ==
859 Invocation->getModuleHash() && "Module hash mismatch!");
861 // Construct a compiler instance that will be used to actually create the
863 CompilerInstance Instance;
864 Instance.setInvocation(&*Invocation);
866 Instance.createDiagnostics(new ForwardingDiagnosticConsumer(
867 ImportingInstance.getDiagnosticClient()),
868 /*ShouldOwnClient=*/true);
870 // Note that this module is part of the module build stack, so that we
871 // can detect cycles in the module graph.
872 Instance.createFileManager(); // FIXME: Adopt file manager from importer?
873 Instance.createSourceManager(Instance.getFileManager());
874 SourceManager &SourceMgr = Instance.getSourceManager();
875 SourceMgr.setModuleBuildStack(
876 ImportingInstance.getSourceManager().getModuleBuildStack());
877 SourceMgr.pushModuleBuildStack(Module->getTopLevelModuleName(),
878 FullSourceLoc(ImportLoc, ImportingInstance.getSourceManager()));
881 // Construct a module-generating action.
882 GenerateModuleAction CreateModuleAction;
884 // Execute the action to actually build the module in-place. Use a separate
885 // thread so that we get a stack large enough.
886 const unsigned ThreadStackSize = 8 << 20;
887 llvm::CrashRecoveryContext CRC;
888 CompileModuleMapData Data = { Instance, CreateModuleAction };
889 CRC.RunSafelyOnThread(&doCompileMapModule, &Data, ThreadStackSize);
892 // Delete the temporary module map file.
893 // FIXME: Even though we're executing under crash protection, it would still
894 // be nice to do this with RemoveFileOnSignal when we can. However, that
895 // doesn't make sense for all clients, so clean this up manually.
896 Instance.clearOutputFiles(/*EraseFiles=*/true);
897 if (!TempModuleMapFileName.empty())
898 llvm::sys::Path(TempModuleMapFileName).eraseFromDisk();
900 // We've rebuilt a module. If we're allowed to generate or update the global
901 // module index, record that fact in the importing compiler instance.
902 if (ImportingInstance.getFrontendOpts().GenerateGlobalModuleIndex) {
903 ImportingInstance.setBuildGlobalModuleIndex(true);
907 /// \brief Diagnose differences between the current definition of the given
908 /// configuration macro and the definition provided on the command line.
909 static void checkConfigMacro(Preprocessor &PP, StringRef ConfigMacro,
910 Module *Mod, SourceLocation ImportLoc) {
911 IdentifierInfo *Id = PP.getIdentifierInfo(ConfigMacro);
912 SourceManager &SourceMgr = PP.getSourceManager();
914 // If this identifier has never had a macro definition, then it could
916 if (!Id->hadMacroDefinition())
919 // If this identifier does not currently have a macro definition,
920 // check whether it had one on the command line.
921 if (!Id->hasMacroDefinition()) {
922 MacroDirective::DefInfo LatestDef =
923 PP.getMacroDirectiveHistory(Id)->getDefinition();
924 for (MacroDirective::DefInfo Def = LatestDef; Def;
925 Def = Def.getPreviousDefinition()) {
926 FileID FID = SourceMgr.getFileID(Def.getLocation());
930 // We only care about the predefines buffer.
931 if (FID != PP.getPredefinesFileID())
934 // This macro was defined on the command line, then #undef'd later.
936 PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)
937 << true << ConfigMacro << Mod->getFullModuleName();
938 if (LatestDef.isUndefined())
939 PP.Diag(LatestDef.getUndefLocation(), diag::note_module_def_undef_here)
944 // Okay: no definition in the predefines buffer.
948 // This identifier has a macro definition. Check whether we had a definition
949 // on the command line.
950 MacroDirective::DefInfo LatestDef =
951 PP.getMacroDirectiveHistory(Id)->getDefinition();
952 MacroDirective::DefInfo PredefinedDef;
953 for (MacroDirective::DefInfo Def = LatestDef; Def;
954 Def = Def.getPreviousDefinition()) {
955 FileID FID = SourceMgr.getFileID(Def.getLocation());
959 // We only care about the predefines buffer.
960 if (FID != PP.getPredefinesFileID())
967 // If there was no definition for this macro in the predefines buffer,
969 if (!PredefinedDef ||
970 (!PredefinedDef.getLocation().isValid() &&
971 PredefinedDef.getUndefLocation().isValid())) {
972 PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)
973 << false << ConfigMacro << Mod->getFullModuleName();
974 PP.Diag(LatestDef.getLocation(), diag::note_module_def_undef_here)
979 // If the current macro definition is the same as the predefined macro
980 // definition, it's okay.
981 if (LatestDef.getMacroInfo() == PredefinedDef.getMacroInfo() ||
982 LatestDef.getMacroInfo()->isIdenticalTo(*PredefinedDef.getMacroInfo(),PP,
983 /*Syntactically=*/true))
986 // The macro definitions differ.
987 PP.Diag(ImportLoc, diag::warn_module_config_macro_undef)
988 << false << ConfigMacro << Mod->getFullModuleName();
989 PP.Diag(LatestDef.getLocation(), diag::note_module_def_undef_here)
993 /// \brief Write a new timestamp file with the given path.
994 static void writeTimestampFile(StringRef TimestampFile) {
995 std::string ErrorInfo;
996 llvm::raw_fd_ostream Out(TimestampFile.str().c_str(), ErrorInfo,
997 llvm::raw_fd_ostream::F_Binary);
1000 /// \brief Prune the module cache of modules that haven't been accessed in
1002 static void pruneModuleCache(const HeaderSearchOptions &HSOpts) {
1003 struct stat StatBuf;
1004 llvm::SmallString<128> TimestampFile;
1005 TimestampFile = HSOpts.ModuleCachePath;
1006 llvm::sys::path::append(TimestampFile, "modules.timestamp");
1008 // Try to stat() the timestamp file.
1009 if (::stat(TimestampFile.c_str(), &StatBuf)) {
1010 // If the timestamp file wasn't there, create one now.
1011 if (errno == ENOENT) {
1012 writeTimestampFile(TimestampFile);
1017 // Check whether the time stamp is older than our pruning interval.
1018 // If not, do nothing.
1019 time_t TimeStampModTime = StatBuf.st_mtime;
1020 time_t CurrentTime = time(0);
1021 if (CurrentTime - TimeStampModTime <= time_t(HSOpts.ModuleCachePruneInterval))
1024 // Write a new timestamp file so that nobody else attempts to prune.
1025 // There is a benign race condition here, if two Clang instances happen to
1026 // notice at the same time that the timestamp is out-of-date.
1027 writeTimestampFile(TimestampFile);
1029 // Walk the entire module cache, looking for unused module files and module
1031 llvm::error_code EC;
1032 SmallString<128> ModuleCachePathNative;
1033 llvm::sys::path::native(HSOpts.ModuleCachePath, ModuleCachePathNative);
1034 for (llvm::sys::fs::directory_iterator
1035 Dir(ModuleCachePathNative.str(), EC), DirEnd;
1036 Dir != DirEnd && !EC; Dir.increment(EC)) {
1037 // If we don't have a directory, there's nothing to look into.
1039 if (llvm::sys::fs::is_directory(Dir->path(), IsDirectory) || !IsDirectory)
1042 // Walk all of the files within this directory.
1043 bool RemovedAllFiles = true;
1044 for (llvm::sys::fs::directory_iterator File(Dir->path(), EC), FileEnd;
1045 File != FileEnd && !EC; File.increment(EC)) {
1046 // We only care about module and global module index files.
1047 if (llvm::sys::path::extension(File->path()) != ".pcm" &&
1048 llvm::sys::path::filename(File->path()) != "modules.idx") {
1049 RemovedAllFiles = false;
1053 // Look at this file. If we can't stat it, there's nothing interesting
1055 if (::stat(File->path().c_str(), &StatBuf)) {
1056 RemovedAllFiles = false;
1060 // If the file has been used recently enough, leave it there.
1061 time_t FileAccessTime = StatBuf.st_atime;
1062 if (CurrentTime - FileAccessTime <=
1063 time_t(HSOpts.ModuleCachePruneAfter)) {
1064 RemovedAllFiles = false;
1070 if (llvm::sys::fs::remove(File->path(), Existed) || !Existed) {
1071 RemovedAllFiles = false;
1075 // If we removed all of the files in the directory, remove the directory
1077 if (RemovedAllFiles) {
1079 llvm::sys::fs::remove(Dir->path(), Existed);
1085 CompilerInstance::loadModule(SourceLocation ImportLoc,
1087 Module::NameVisibilityKind Visibility,
1088 bool IsInclusionDirective) {
1089 // If we've already handled this import, just return the cached result.
1090 // This one-element cache is important to eliminate redundant diagnostics
1091 // when both the preprocessor and parser see the same import declaration.
1092 if (!ImportLoc.isInvalid() && LastModuleImportLoc == ImportLoc) {
1093 // Make the named module visible.
1094 if (LastModuleImportResult)
1095 ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility,
1096 ImportLoc, /*Complain=*/false);
1097 return LastModuleImportResult;
1100 // Determine what file we're searching from.
1101 StringRef ModuleName = Path[0].first->getName();
1102 SourceLocation ModuleNameLoc = Path[0].second;
1104 clang::Module *Module = 0;
1106 // If we don't already have information on this module, load the module now.
1107 llvm::DenseMap<const IdentifierInfo *, clang::Module *>::iterator Known
1108 = KnownModules.find(Path[0].first);
1109 if (Known != KnownModules.end()) {
1110 // Retrieve the cached top-level module.
1111 Module = Known->second;
1112 } else if (ModuleName == getLangOpts().CurrentModule) {
1113 // This is the module we're building.
1114 Module = PP->getHeaderSearchInfo().getModuleMap().findModule(ModuleName);
1115 Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first;
1117 // Search for a module with the given name.
1118 Module = PP->getHeaderSearchInfo().lookupModule(ModuleName);
1119 std::string ModuleFileName;
1121 ModuleFileName = PP->getHeaderSearchInfo().getModuleFileName(Module);
1123 ModuleFileName = PP->getHeaderSearchInfo().getModuleFileName(ModuleName);
1125 // If we don't already have an ASTReader, create one now.
1126 if (!ModuleManager) {
1127 if (!hasASTContext())
1130 // If we're not recursively building a module, check whether we
1131 // need to prune the module cache.
1132 if (getSourceManager().getModuleBuildStack().empty() &&
1133 getHeaderSearchOpts().ModuleCachePruneInterval > 0 &&
1134 getHeaderSearchOpts().ModuleCachePruneAfter > 0) {
1135 pruneModuleCache(getHeaderSearchOpts());
1138 std::string Sysroot = getHeaderSearchOpts().Sysroot;
1139 const PreprocessorOptions &PPOpts = getPreprocessorOpts();
1140 ModuleManager = new ASTReader(getPreprocessor(), *Context,
1141 Sysroot.empty() ? "" : Sysroot.c_str(),
1142 PPOpts.DisablePCHValidation,
1143 /*AllowASTWithCompilerErrors=*/false,
1144 getFrontendOpts().UseGlobalModuleIndex);
1145 if (hasASTConsumer()) {
1146 ModuleManager->setDeserializationListener(
1147 getASTConsumer().GetASTDeserializationListener());
1148 getASTContext().setASTMutationListener(
1149 getASTConsumer().GetASTMutationListener());
1151 OwningPtr<ExternalASTSource> Source;
1152 Source.reset(ModuleManager);
1153 getASTContext().setExternalSource(Source);
1155 ModuleManager->InitializeSema(getSema());
1156 if (hasASTConsumer())
1157 ModuleManager->StartTranslationUnit(&getASTConsumer());
1160 // Try to load the module file.
1161 unsigned ARRFlags = ASTReader::ARR_OutOfDate | ASTReader::ARR_Missing;
1162 switch (ModuleManager->ReadAST(ModuleFileName, serialization::MK_Module,
1163 ImportLoc, ARRFlags)) {
1164 case ASTReader::Success:
1167 case ASTReader::OutOfDate: {
1168 // The module file is out-of-date. Remove it, then rebuild it.
1170 llvm::sys::fs::remove(ModuleFileName, Existed);
1172 // Fall through to build the module again.
1174 case ASTReader::Missing: {
1175 // The module file is (now) missing. Build it.
1177 // If we don't have a module, we don't know how to build the module file.
1178 // Complain and return.
1180 getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found)
1182 << SourceRange(ImportLoc, ModuleNameLoc);
1183 ModuleBuildFailed = true;
1184 return ModuleLoadResult();
1187 // Check whether there is a cycle in the module graph.
1188 ModuleBuildStack ModPath = getSourceManager().getModuleBuildStack();
1189 ModuleBuildStack::iterator Pos = ModPath.begin(), PosEnd = ModPath.end();
1190 for (; Pos != PosEnd; ++Pos) {
1191 if (Pos->first == ModuleName)
1195 if (Pos != PosEnd) {
1196 SmallString<256> CyclePath;
1197 for (; Pos != PosEnd; ++Pos) {
1198 CyclePath += Pos->first;
1199 CyclePath += " -> ";
1201 CyclePath += ModuleName;
1203 getDiagnostics().Report(ModuleNameLoc, diag::err_module_cycle)
1204 << ModuleName << CyclePath;
1205 return ModuleLoadResult();
1208 // Check whether we have already attempted to build this module (but
1210 if (getPreprocessorOpts().FailedModules &&
1211 getPreprocessorOpts().FailedModules->hasAlreadyFailed(ModuleName)) {
1212 getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_built)
1214 << SourceRange(ImportLoc, ModuleNameLoc);
1215 ModuleBuildFailed = true;
1216 return ModuleLoadResult();
1219 // Try to compile the module.
1220 compileModule(*this, ModuleNameLoc, Module, ModuleFileName);
1222 // Try to read the module file, now that we've compiled it.
1223 ASTReader::ASTReadResult ReadResult
1224 = ModuleManager->ReadAST(ModuleFileName,
1225 serialization::MK_Module, ImportLoc,
1226 ASTReader::ARR_Missing);
1227 if (ReadResult != ASTReader::Success) {
1228 if (ReadResult == ASTReader::Missing) {
1229 getDiagnostics().Report(ModuleNameLoc,
1230 Module? diag::err_module_not_built
1231 : diag::err_module_not_found)
1233 << SourceRange(ImportLoc, ModuleNameLoc);
1236 if (getPreprocessorOpts().FailedModules)
1237 getPreprocessorOpts().FailedModules->addFailed(ModuleName);
1238 KnownModules[Path[0].first] = 0;
1239 ModuleBuildFailed = true;
1240 return ModuleLoadResult();
1243 // Okay, we've rebuilt and now loaded the module.
1247 case ASTReader::VersionMismatch:
1248 case ASTReader::ConfigurationMismatch:
1249 case ASTReader::HadErrors:
1250 // FIXME: The ASTReader will already have complained, but can we showhorn
1251 // that diagnostic information into a more useful form?
1252 KnownModules[Path[0].first] = 0;
1253 return ModuleLoadResult();
1255 case ASTReader::Failure:
1256 // Already complained, but note now that we failed.
1257 KnownModules[Path[0].first] = 0;
1258 ModuleBuildFailed = true;
1259 return ModuleLoadResult();
1263 // If we loaded the module directly, without finding a module map first,
1264 // we'll have loaded the module's information from the module itself.
1265 Module = PP->getHeaderSearchInfo().getModuleMap()
1266 .findModule((Path[0].first->getName()));
1269 // Cache the result of this top-level module lookup for later.
1270 Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first;
1273 // If we never found the module, fail.
1275 return ModuleLoadResult();
1277 // Verify that the rest of the module path actually corresponds to
1279 if (Path.size() > 1) {
1280 for (unsigned I = 1, N = Path.size(); I != N; ++I) {
1281 StringRef Name = Path[I].first->getName();
1282 clang::Module *Sub = Module->findSubmodule(Name);
1285 // Attempt to perform typo correction to find a module name that works.
1286 SmallVector<StringRef, 2> Best;
1287 unsigned BestEditDistance = (std::numeric_limits<unsigned>::max)();
1289 for (clang::Module::submodule_iterator J = Module->submodule_begin(),
1290 JEnd = Module->submodule_end();
1292 unsigned ED = Name.edit_distance((*J)->Name,
1293 /*AllowReplacements=*/true,
1295 if (ED <= BestEditDistance) {
1296 if (ED < BestEditDistance) {
1298 BestEditDistance = ED;
1301 Best.push_back((*J)->Name);
1305 // If there was a clear winner, user it.
1306 if (Best.size() == 1) {
1307 getDiagnostics().Report(Path[I].second,
1308 diag::err_no_submodule_suggest)
1309 << Path[I].first << Module->getFullModuleName() << Best[0]
1310 << SourceRange(Path[0].second, Path[I-1].second)
1311 << FixItHint::CreateReplacement(SourceRange(Path[I].second),
1314 Sub = Module->findSubmodule(Best[0]);
1319 // No submodule by this name. Complain, and don't look for further
1321 getDiagnostics().Report(Path[I].second, diag::err_no_submodule)
1322 << Path[I].first << Module->getFullModuleName()
1323 << SourceRange(Path[0].second, Path[I-1].second);
1331 // Make the named module visible, if it's not already part of the module
1333 if (ModuleName != getLangOpts().CurrentModule) {
1334 if (!Module->IsFromModuleFile) {
1335 // We have an umbrella header or directory that doesn't actually include
1336 // all of the headers within the directory it covers. Complain about
1337 // this missing submodule and recover by forgetting that we ever saw
1339 // FIXME: Should we detect this at module load time? It seems fairly
1340 // expensive (and rare).
1341 getDiagnostics().Report(ImportLoc, diag::warn_missing_submodule)
1342 << Module->getFullModuleName()
1343 << SourceRange(Path.front().second, Path.back().second);
1345 return ModuleLoadResult(0, true);
1348 // Check whether this module is available.
1350 if (!Module->isAvailable(getLangOpts(), getTarget(), Feature)) {
1351 getDiagnostics().Report(ImportLoc, diag::err_module_unavailable)
1352 << Module->getFullModuleName()
1354 << SourceRange(Path.front().second, Path.back().second);
1355 LastModuleImportLoc = ImportLoc;
1356 LastModuleImportResult = ModuleLoadResult();
1357 return ModuleLoadResult();
1360 ModuleManager->makeModuleVisible(Module, Visibility, ImportLoc,
1364 // Check for any configuration macros that have changed.
1365 clang::Module *TopModule = Module->getTopLevelModule();
1366 for (unsigned I = 0, N = TopModule->ConfigMacros.size(); I != N; ++I) {
1367 checkConfigMacro(getPreprocessor(), TopModule->ConfigMacros[I],
1371 // If this module import was due to an inclusion directive, create an
1372 // implicit import declaration to capture it in the AST.
1373 if (IsInclusionDirective && hasASTContext()) {
1374 TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl();
1375 ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU,
1377 Path.back().second);
1378 TU->addDecl(ImportD);
1380 Consumer->HandleImplicitImportDecl(ImportD);
1383 LastModuleImportLoc = ImportLoc;
1384 LastModuleImportResult = ModuleLoadResult(Module, false);
1385 return LastModuleImportResult;
1388 void CompilerInstance::makeModuleVisible(Module *Mod,
1389 Module::NameVisibilityKind Visibility,
1390 SourceLocation ImportLoc,
1392 ModuleManager->makeModuleVisible(Mod, Visibility, ImportLoc, Complain);