SILGen: Have emitSemanticStore cast off concurrency annotations.

If a function is being semantically treated as having different concurrency
annotations because of a `@preconcurrency` import or language mode setting,
then SILGen may try to store an argument or result for a call using a value
that differs only in concurrency annotations, which can be safely bitcast
away.

Fixes rdar://154520999
This commit is contained in:
Joe Groff
2025-07-16 11:22:10 -07:00
parent 2689ef31e1
commit 0e94c63494
3 changed files with 25 additions and 0 deletions

View File

@@ -5227,6 +5227,14 @@ void SILGenFunction::emitSemanticStore(SILLocation loc,
dest = B.createMoveOnlyWrapperToCopyableAddr(loc, dest);
}
// If the dest type differs only in concurrency annotations, we can cast them
// off.
if (dest->getType().getObjectType() != rvalue->getType().getObjectType()
&& dest->getType().stripConcurrency(/*recursive*/true, /*dropGlobal*/true)
== rvalue->getType().stripConcurrency(true, true)) {
dest = B.createUncheckedAddrCast(loc, dest, rvalue->getType().getAddressType());
}
// Easy case: the types match.
if (rvalue->getType().getObjectType() == dest->getType().getObjectType()) {
assert(!silConv.useLoweredAddresses() ||

View File

@@ -0,0 +1,9 @@
@import Foundation;
#define NS_SWIFT_SENDABLE __attribute__((__swift_attr__("@Sendable")))
@interface TestClass: NSObject
- (_Nullable id NS_SWIFT_SENDABLE)foo;
@end

View File

@@ -0,0 +1,8 @@
// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) -import-objc-header %S/Inputs/preconcurrency-bridged-return.h -swift-version 5 %s
//
// REQUIRES: objc_interop
func test(x: TestClass) {
let foo = x.foo()
}