@@ -1604,6 +1604,10 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
1604
1604
// arguments in the textual interface file. So copy to use a new compiler
1605
1605
// invocation.
1606
1606
CompilerInvocation subInvocation = genericSubInvocation;
1607
+
1608
+ // Save the target triple from the original context.
1609
+ llvm::Triple originalTargetTriple (subInvocation.getLangOptions ().Target );
1610
+
1607
1611
std::vector<StringRef> BuildArgs (GenericArgs.begin (), GenericArgs.end ());
1608
1612
assert (BuildArgs.size () == GenericArgs.size ());
1609
1613
// Configure inputs
@@ -1653,6 +1657,22 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
1653
1657
if (subInvocation.parseArgs (SubArgs, *Diags)) {
1654
1658
return std::make_error_code (std::errc::not_supported);
1655
1659
}
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
+
1656
1676
CompilerInstance subInstance;
1657
1677
SubCompilerInstanceInfo info;
1658
1678
info.Instance = &subInstance;
0 commit comments