Override -triple on fallback to arm64e interface

When we fall back to loading an arm64e module interface during an arm64 build, we want to compile it for the arm64 target so that it is fully compatible with the module that will load it, even though the flags in the file specify the arm64e target. Rewrite the sub-invocation's TargetTriple property in this specific situation. If the two targets differ by more than just the sub-architecture, we will continue to respect the -target flag in the file.

Fixes <rdar://83056545>.
This commit is contained in:
Becca Royal-Gordon
2021-09-14 18:04:34 -07:00
parent 3680f9c260
commit e16cf3085f
3 changed files with 21 additions and 6 deletions

View File

@@ -1604,6 +1604,10 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
// arguments in the textual interface file. So copy to use a new compiler
// invocation.
CompilerInvocation subInvocation = genericSubInvocation;
// Save the target triple from the original context.
llvm::Triple originalTargetTriple(subInvocation.getLangOptions().Target);
std::vector<StringRef> BuildArgs(GenericArgs.begin(), GenericArgs.end());
assert(BuildArgs.size() == GenericArgs.size());
// Configure inputs
@@ -1653,6 +1657,22 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
if (subInvocation.parseArgs(SubArgs, *Diags)) {
return std::make_error_code(std::errc::not_supported);
}
// If the target triple parsed from the Swift interface file differs
// only in subarchitecture from the original target triple, then
// we have loaded a Swift interface from a different-but-compatible
// architecture slice. Use the original subarchitecture.
llvm::Triple parsedTargetTriple(subInvocation.getTargetTriple());
if (parsedTargetTriple.getSubArch() != originalTargetTriple.getSubArch() &&
parsedTargetTriple.getArch() == originalTargetTriple.getArch() &&
parsedTargetTriple.getVendor() == originalTargetTriple.getVendor() &&
parsedTargetTriple.getOS() == originalTargetTriple.getOS() &&
parsedTargetTriple.getEnvironment()
== originalTargetTriple.getEnvironment()) {
parsedTargetTriple.setArchName(originalTargetTriple.getArchName());
subInvocation.setTargetTriple(parsedTargetTriple.str());
}
CompilerInstance subInstance;
SubCompilerInstanceInfo info;
info.Instance = &subInstance;