Skip to content

Override -triple on fallback to arm64e interface #39315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style thoughts, but I usually like to throw massive comparison-chains in a std::tie

e.g.

if (pTT.getSubArch() != oTT.getSubArch() &&
    std::tie(pTT.getArch(), pTT.getVendor(), pTT.getOS(), pTT.getEnvironment()) == std::tie(oTT.getArch(), oTT.getVendor(), oTT.getOS(), oTT.getEnvironment())) {
  //...
}

I feel like it hides the redundant == and shows what is equal and what is different more clearly.
I'll leave it up to you, but just throwing it out there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's going to give us a really, really really long line (and also cause a merge conflict), so I think I'll leave this as-is.

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;
Expand Down
4 changes: 1 addition & 3 deletions test/ModuleInterface/arm64e-fallback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
// When run on arm64e, this tests that we build the same interface with
// `#if _ptrauth(_arm64e)` on.
//
// REQUIRES: CPU=arm64
// Disabled arm64e for now since it isn't passing tests on apple silicon.
// XFAIL: CPU=arm64e
// REQUIRES: CPU=arm64 || CPU=arm64e

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

Expand Down
3 changes: 0 additions & 3 deletions test/stdlib/Reflection_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

// Disabled arm64e for now since it is failing
// XFAIL: CPU=arm64e

//
// DO NOT add more tests to this file. Add them to test/1_stdlib/Runtime.swift.
//
Expand Down