Skip to content

Commit 0e97216

Browse files
vgvassilevdevajithvs
authored andcommitted
[cxxmodules] Don't complain when modulemap for implicit modules has changed
This patch (also) aims to make runtime module installable. This part of code in Clang is comparing the location of "modulemap which is currently loaded and gives a definition of current module (say, stl) and "the location of the modulemap where the current implicit module (like stl) was built". This was problematic for CMSSW, as they should install modulemaps and prebuilt pcms to other directory. stl and libc pcms should be prebuilt, installed and used from installed directory, so this check is redundant for that usecase.
1 parent 62405d9 commit 0e97216

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

clang/lib/Serialization/ASTReader.cpp

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,27 @@ ASTReader::ReadControlBlock(ModuleFile &F,
30763076
return Missing;
30773077
}
30783078

3079+
// Check if ImportedFile exists on disk
3080+
if (!llvm::sys::fs::is_directory(ImportedFile)) {
3081+
StringRef ModuleName = llvm::sys::path::filename(ImportedFile.c_str());
3082+
ModuleName.consume_back(".pcm");
3083+
// Get clang::Module pointer by looking up the module name
3084+
HeaderSearch &HS = PP.getHeaderSearchInfo();
3085+
Module *M = HS.lookupModule(ModuleName, SourceLocation(),
3086+
/*AllowSearch*/ true,
3087+
/*AllowExtraModuleMapSearch*/ true);
3088+
if (M) {
3089+
std::string Path = HS.getPrebuiltModuleFileName(M->Name);
3090+
if (Path.empty())
3091+
Path = HS.getCachedModuleFileName(M->Name,
3092+
HS.getModuleMap().getModuleMapFileForUniquing(M)->getName());
3093+
// FIXME: Add a hash comparison to check if ImportedFile's hash and the
3094+
// new Modules Path's hash matches or not.
3095+
if (!Path.empty())
3096+
ImportedFile = Path;
3097+
}
3098+
}
3099+
30793100
// If our client can't cope with us being out of date, we can't cope with
30803101
// our dependency being missing.
30813102
unsigned Capabilities = ClientLoadCapabilities;
@@ -4066,11 +4087,31 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
40664087
? ModuleMgr.lookupByModuleName(Name)
40674088
: ModuleMgr.lookupByFileName(Name));
40684089
if (!OM) {
4069-
std::string Msg =
4070-
"SourceLocation remap refers to unknown module, cannot find ";
4071-
Msg.append(std::string(Name));
4072-
Error(Msg);
4073-
return;
4090+
StringRef ModuleName = llvm::sys::path::filename(Name);
4091+
ModuleName.consume_back(".pcm");
4092+
HeaderSearch &HS = PP.getHeaderSearchInfo();
4093+
Module *M = HS.lookupModule(ModuleName, SourceLocation(),
4094+
/*AllowSearch*/ true,
4095+
/*AllowExtraModuleMapSearch*/ true);
4096+
std::string Path;
4097+
// If module definition exists in modulemap, search the modulepath in HeaderSearchInfo
4098+
if (M) {
4099+
Path = HS.getPrebuiltModuleFileName(M->Name);
4100+
if (Path.empty())
4101+
Path = HS.getCachedModuleFileName(M->Name,
4102+
HS.getModuleMap().getModuleMapFileForUniquing(M)->getName());
4103+
4104+
}
4105+
4106+
StringRef NewName = StringRef(Path);
4107+
OM = ModuleMgr.lookupByFileName(NewName);
4108+
if (!OM) {
4109+
std::string Msg =
4110+
"SourceLocation remap refers to unknown module, cannot find ";
4111+
Msg.append(std::string(NewName));
4112+
Error(Msg);
4113+
return;
4114+
}
40744115
}
40754116

40764117
SourceLocation::UIntTy SLocOffset =

0 commit comments

Comments
 (0)