summaryrefslogtreecommitdiff
path: root/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Frontend/CompilerInstance.cpp')
-rw-r--r--lib/Frontend/CompilerInstance.cpp74
1 files changed, 59 insertions, 15 deletions
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index bb6a665cb456..32f1232bbe24 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -300,12 +300,16 @@ CompilerInstance::createDiagnostics(DiagnosticOptions *Opts,
// File Manager
-void CompilerInstance::createFileManager() {
+FileManager *CompilerInstance::createFileManager() {
if (!hasVirtualFileSystem()) {
- // TODO: choose the virtual file system based on the CompilerInvocation.
- setVirtualFileSystem(vfs::getRealFileSystem());
+ if (IntrusiveRefCntPtr<vfs::FileSystem> VFS =
+ createVFSFromCompilerInvocation(getInvocation(), getDiagnostics()))
+ setVirtualFileSystem(VFS);
+ else
+ return nullptr;
}
FileMgr = new FileManager(getFileSystemOpts(), VirtualFileSystem);
+ return FileMgr.get();
}
// Source Manager
@@ -382,6 +386,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
Invocation->getPreprocessorOptsPtr(), getDiagnostics(), getLangOpts(),
getSourceManager(), getPCMCache(), *HeaderInfo, *this, PTHMgr,
/*OwnsHeaderSearch=*/true, TUKind);
+ getTarget().adjust(getLangOpts());
PP->Initialize(getTarget(), getAuxTarget());
// Note that this is different then passing PTHMgr to Preprocessor's ctor.
@@ -759,9 +764,15 @@ std::unique_ptr<llvm::raw_pwrite_stream> CompilerInstance::createOutputFile(
if (UseTemporary) {
// Create a temporary file.
- SmallString<128> TempPath;
- TempPath = OutFile;
+ // Insert -%%%%%%%% before the extension (if any), and because some tools
+ // (noticeable, clang's own GlobalModuleIndex.cpp) glob for build
+ // artifacts, also append .tmp.
+ StringRef OutputExtension = llvm::sys::path::extension(OutFile);
+ SmallString<128> TempPath =
+ StringRef(OutFile).drop_back(OutputExtension.size());
TempPath += "-%%%%%%%%";
+ TempPath += OutputExtension;
+ TempPath += ".tmp";
int fd;
std::error_code EC =
llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath);
@@ -832,8 +843,8 @@ bool CompilerInstance::InitializeSourceManager(
: Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
if (Input.isBuffer()) {
- SourceMgr.setMainFileID(SourceMgr.createFileID(
- std::unique_ptr<llvm::MemoryBuffer>(Input.getBuffer()), Kind));
+ SourceMgr.setMainFileID(SourceMgr.createFileID(SourceManager::Unowned,
+ Input.getBuffer(), Kind));
assert(SourceMgr.getMainFileID().isValid() &&
"Couldn't establish MainFileID!");
return true;
@@ -997,8 +1008,17 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) {
OS << " and ";
if (NumErrors)
OS << NumErrors << " error" << (NumErrors == 1 ? "" : "s");
- if (NumWarnings || NumErrors)
- OS << " generated.\n";
+ if (NumWarnings || NumErrors) {
+ OS << " generated";
+ if (getLangOpts().CUDA) {
+ if (!getLangOpts().CUDAIsDevice) {
+ OS << " when compiling for host";
+ } else {
+ OS << " when compiling for " << getTargetOpts().CPU;
+ }
+ }
+ OS << ".\n";
+ }
}
if (getFrontendOpts().ShowStats) {
@@ -1595,7 +1615,22 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
Module::NameVisibilityKind Visibility,
bool IsInclusionDirective) {
// Determine what file we're searching from.
- StringRef ModuleName = Path[0].first->getName();
+ // FIXME: Should we be deciding whether this is a submodule (here and
+ // below) based on -fmodules-ts or should we pass a flag and make the
+ // caller decide?
+ std::string ModuleName;
+ if (getLangOpts().ModulesTS) {
+ // FIXME: Same code as Sema::ActOnModuleDecl() so there is probably a
+ // better place/way to do this.
+ for (auto &Piece : Path) {
+ if (!ModuleName.empty())
+ ModuleName += ".";
+ ModuleName += Piece.first->getName();
+ }
+ }
+ else
+ ModuleName = Path[0].first->getName();
+
SourceLocation ModuleNameLoc = Path[0].second;
// If we've already handled this import, just return the cached result.
@@ -1620,6 +1655,14 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
} else if (ModuleName == getLangOpts().CurrentModule) {
// This is the module we're building.
Module = PP->getHeaderSearchInfo().lookupModule(ModuleName);
+ /// FIXME: perhaps we should (a) look for a module using the module name
+ // to file map (PrebuiltModuleFiles) and (b) diagnose if still not found?
+ //if (Module == nullptr) {
+ // getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found)
+ // << ModuleName;
+ // ModuleBuildFailed = true;
+ // return ModuleLoadResult();
+ //}
Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first;
} else {
// Search for a module with the given name.
@@ -1641,16 +1684,17 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
}
// Try to load the module from the prebuilt module path.
- if (Source == ModuleNotFound && !HSOpts.PrebuiltModulePaths.empty()) {
- ModuleFileName = PP->getHeaderSearchInfo().getModuleFileName(
- ModuleName, "", /*UsePrebuiltPath*/ true);
+ if (Source == ModuleNotFound && (!HSOpts.PrebuiltModuleFiles.empty() ||
+ !HSOpts.PrebuiltModulePaths.empty())) {
+ ModuleFileName =
+ PP->getHeaderSearchInfo().getPrebuiltModuleFileName(ModuleName);
if (!ModuleFileName.empty())
Source = PrebuiltModulePath;
}
// Try to load the module from the module cache.
if (Source == ModuleNotFound && Module) {
- ModuleFileName = PP->getHeaderSearchInfo().getModuleFileName(Module);
+ ModuleFileName = PP->getHeaderSearchInfo().getCachedModuleFileName(Module);
Source = ModuleCache;
}
@@ -1810,7 +1854,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// Verify that the rest of the module path actually corresponds to
// a submodule.
- if (Path.size() > 1) {
+ if (!getLangOpts().ModulesTS && Path.size() > 1) {
for (unsigned I = 1, N = Path.size(); I != N; ++I) {
StringRef Name = Path[I].first->getName();
clang::Module *Sub = Module->findSubmodule(Name);