Skip to content

Commit e16cf30

Browse files
committed
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>.
1 parent 3680f9c commit e16cf30

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,10 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
16041604
// arguments in the textual interface file. So copy to use a new compiler
16051605
// invocation.
16061606
CompilerInvocation subInvocation = genericSubInvocation;
1607+
1608+
// Save the target triple from the original context.
1609+
llvm::Triple originalTargetTriple(subInvocation.getLangOptions().Target);
1610+
16071611
std::vector<StringRef> BuildArgs(GenericArgs.begin(), GenericArgs.end());
16081612
assert(BuildArgs.size() == GenericArgs.size());
16091613
// Configure inputs
@@ -1653,6 +1657,22 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
16531657
if (subInvocation.parseArgs(SubArgs, *Diags)) {
16541658
return std::make_error_code(std::errc::not_supported);
16551659
}
1660+
1661+
// If the target triple parsed from the Swift interface file differs
1662+
// only in subarchitecture from the original target triple, then
1663+
// we have loaded a Swift interface from a different-but-compatible
1664+
// architecture slice. Use the original subarchitecture.
1665+
llvm::Triple parsedTargetTriple(subInvocation.getTargetTriple());
1666+
if (parsedTargetTriple.getSubArch() != originalTargetTriple.getSubArch() &&
1667+
parsedTargetTriple.getArch() == originalTargetTriple.getArch() &&
1668+
parsedTargetTriple.getVendor() == originalTargetTriple.getVendor() &&
1669+
parsedTargetTriple.getOS() == originalTargetTriple.getOS() &&
1670+
parsedTargetTriple.getEnvironment()
1671+
== originalTargetTriple.getEnvironment()) {
1672+
parsedTargetTriple.setArchName(originalTargetTriple.getArchName());
1673+
subInvocation.setTargetTriple(parsedTargetTriple.str());
1674+
}
1675+
16561676
CompilerInstance subInstance;
16571677
SubCompilerInstanceInfo info;
16581678
info.Instance = &subInstance;

test/ModuleInterface/arm64e-fallback.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
// When run on arm64e, this tests that we build the same interface with
1212
// `#if _ptrauth(_arm64e)` on.
1313
//
14-
// REQUIRES: CPU=arm64
15-
// Disabled arm64e for now since it isn't passing tests on apple silicon.
16-
// XFAIL: CPU=arm64e
14+
// REQUIRES: CPU=arm64 || CPU=arm64e
1715

1816
import PtrAuthFramework // expected-remark{{rebuilding module 'PtrAuthFramework' from interface}}
1917

test/stdlib/Reflection_objc.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
// UNSUPPORTED: use_os_stdlib
1313
// UNSUPPORTED: back_deployment_runtime
1414

15-
// Disabled arm64e for now since it is failing
16-
// XFAIL: CPU=arm64e
17-
1815
//
1916
// DO NOT add more tests to this file. Add them to test/1_stdlib/Runtime.swift.
2017
//

0 commit comments

Comments
 (0)