@@ -128,6 +128,23 @@ static void addDiagnosticInfoForArchitectureMismatch(ASTContext &ctx,
128128 archName, foundArchs);
129129}
130130
131+ static std::pair<llvm::SmallString<16 >, llvm::SmallString<16 >>
132+ getArchSpecificModuleFileNames (StringRef archName) {
133+ llvm::SmallString<16 > archFile, archDocFile;
134+
135+ if (!archName.empty ()) {
136+ archFile += archName;
137+ archFile += ' .' ;
138+ archFile += file_types::getExtension (file_types::TY_SwiftModuleFile);
139+
140+ archDocFile += archName;
141+ archDocFile += ' .' ;
142+ archDocFile += file_types::getExtension (file_types::TY_SwiftModuleDocFile);
143+ }
144+
145+ return {archFile, archDocFile};
146+ }
147+
131148bool
132149SerializedModuleLoaderBase::findModule (AccessPathElem moduleID,
133150 std::unique_ptr<llvm::MemoryBuffer> *moduleBuffer,
@@ -143,19 +160,19 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
143160 moduleDocFilename +=
144161 file_types::getExtension (file_types::TY_SwiftModuleDocFile);
145162
146- // FIXME: Which name should we be using here? Do we care about CPU subtypes?
147- // FIXME: At the very least, don't hardcode "arch".
148- llvm::SmallString<16 > archName{
149- Ctx.LangOpts .getPlatformConditionValue (PlatformConditionKind::Arch)};
150- llvm::SmallString<16 > archFile{archName};
151- llvm::SmallString<16 > archDocFile{archName};
152- if (!archFile.empty ()) {
153- archFile += ' .' ;
154- archFile += file_types::getExtension (file_types::TY_SwiftModuleFile);
163+ StringRef archName = Ctx.LangOpts .Target .getArchName ();
164+ auto archFileNames = getArchSpecificModuleFileNames (archName);
155165
156- archDocFile += ' .' ;
157- archDocFile += file_types::getExtension (file_types::TY_SwiftModuleDocFile);
158- }
166+ // FIXME: We used to use "major architecture" names for these files---the
167+ // names checked in "#if arch(...)". Fall back to that name in the one case
168+ // where it's different from what Swift 4.2 supported: 32-bit ARM platforms.
169+ // We should be able to drop this once there's an Xcode that supports the
170+ // new names.
171+ StringRef alternateArchName;
172+ if (Ctx.LangOpts .Target .getArch () == llvm::Triple::ArchType::arm)
173+ alternateArchName = " arm" ;
174+ auto alternateArchFileNames =
175+ getArchSpecificModuleFileNames (alternateArchName);
159176
160177 llvm::SmallString<128 > scratch;
161178 llvm::SmallString<128 > currPath;
@@ -169,10 +186,19 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
169186 currPath = path;
170187 llvm::sys::path::append (currPath, moduleFilename.str ());
171188 err = openModuleFiles (currPath,
172- archFile. str (), archDocFile. str () ,
189+ archFileNames. first , archFileNames. second ,
173190 moduleBuffer, moduleDocBuffer,
174191 scratch);
175192
193+ if (err == std::errc::no_such_file_or_directory &&
194+ !alternateArchName.empty ()) {
195+ err = openModuleFiles (currPath,
196+ alternateArchFileNames.first ,
197+ alternateArchFileNames.second ,
198+ moduleBuffer, moduleDocBuffer,
199+ scratch);
200+ }
201+
176202 if (err == std::errc::no_such_file_or_directory) {
177203 addDiagnosticInfoForArchitectureMismatch (
178204 Ctx, moduleID.second , moduleName, archName, currPath);
@@ -197,9 +223,18 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID,
197223 }
198224
199225 llvm::sys::path::append (currPath, " Modules" , moduleFilename.str ());
200- auto err = openModuleFiles (currPath, archFile.str (), archDocFile.str (),
226+ auto err = openModuleFiles (currPath,
227+ archFileNames.first , archFileNames.second ,
201228 moduleBuffer, moduleDocBuffer, scratch);
202229
230+ if (err == std::errc::no_such_file_or_directory &&
231+ !alternateArchName.empty ()) {
232+ err = openModuleFiles (currPath,
233+ alternateArchFileNames.first ,
234+ alternateArchFileNames.second ,
235+ moduleBuffer, moduleDocBuffer, scratch);
236+ }
237+
203238 if (err == std::errc::no_such_file_or_directory) {
204239 addDiagnosticInfoForArchitectureMismatch (
205240 Ctx, moduleID.second , moduleName, archName, currPath);
0 commit comments