@@ -964,7 +964,8 @@ void swift::serialization::diagnoseSerializedASTLoadFailure(
964
964
}
965
965
}
966
966
967
- bool swift::extractCompilerFlagsFromInterface (StringRef buffer,
967
+ bool swift::extractCompilerFlagsFromInterface (StringRef interfacePath,
968
+ StringRef buffer,
968
969
llvm::StringSaver &ArgSaver,
969
970
SmallVectorImpl<const char *> &SubArgs) {
970
971
SmallVector<StringRef, 1 > FlagMatches;
@@ -973,6 +974,29 @@ bool swift::extractCompilerFlagsFromInterface(StringRef buffer,
973
974
return true ;
974
975
assert (FlagMatches.size () == 2 );
975
976
llvm::cl::TokenizeGNUCommandLine (FlagMatches[1 ], ArgSaver, SubArgs);
977
+
978
+ auto intFileName = llvm::sys::path::filename (interfacePath);
979
+
980
+ // Sanitize arch if the file name and the encoded flags disagree.
981
+ // It's a known issue that we are using arm64e interfaces contents for the arm64 target,
982
+ // meaning the encoded module flags are using -target arm64e-x-x. Fortunately,
983
+ // we can tell the target arch from the interface file name, so we could sanitize
984
+ // the target to use by inferring target from the file name.
985
+ StringRef arm64 = " arm64" ;
986
+ StringRef arm64e = " arm64e" ;
987
+ if (intFileName.contains (arm64) && !intFileName.contains (arm64e)) {
988
+ for (unsigned I = 1 ; I < SubArgs.size (); ++I) {
989
+ if (strcmp (SubArgs[I - 1 ], " -target" ) != 0 ) {
990
+ continue ;
991
+ }
992
+ StringRef triple (SubArgs[I]);
993
+ if (triple.startswith (arm64e)) {
994
+ SubArgs[I] = ArgSaver.save ((llvm::Twine (arm64) +
995
+ triple.substr (arm64e.size ())).str ()).data ();
996
+ }
997
+ }
998
+ }
999
+
976
1000
SmallVector<StringRef, 1 > IgnFlagMatches;
977
1001
// Cherry-pick supported options from the ignorable list.
978
1002
auto IgnFlagRe = llvm::Regex (" ^// swift-module-flags-ignorable:(.*)$" ,
@@ -1011,7 +1035,8 @@ swift::extractUserModuleVersionFromInterface(StringRef moduleInterfacePath) {
1011
1035
llvm::BumpPtrAllocator alloc;
1012
1036
llvm::StringSaver argSaver (alloc);
1013
1037
SmallVector<const char *, 8 > args;
1014
- (void )extractCompilerFlagsFromInterface ((*file)->getBuffer (), argSaver, args);
1038
+ (void )extractCompilerFlagsFromInterface (moduleInterfacePath,
1039
+ (*file)->getBuffer (), argSaver, args);
1015
1040
for (unsigned I = 0 , N = args.size (); I + 1 < N; I++) {
1016
1041
// Check the version number specified via -user-module-version.
1017
1042
StringRef current (args[I]), next (args[I + 1 ]);
0 commit comments