Skip to content

Commit 11696cd

Browse files
authored
[SILGen] Fix assertion failure when opaque value is enabled (#74676)
emitManagedParameter assumes the passed value has an address type and calls forBorrowedAddressRValue when the parameter convention is Indirect_In_Guaranteed. Call forBorrowedObjectRValue instead when the type isn't an address type. rdar://130456931
1 parent 0d59587 commit 11696cd

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/SILGen/SILGenBridging.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ static ManagedValue emitManagedParameter(SILGenFunction &SGF, SILLocation loc,
319319
return ManagedValue::forLValue(value);
320320

321321
case ParameterConvention::Indirect_In_Guaranteed:
322+
if (!value->getType().isAddress())
323+
return ManagedValue::forBorrowedObjectRValue(value);
324+
322325
if (valueTL.isLoadable()) {
323326
return SGF.B.createLoadBorrow(
324327
loc, ManagedValue::forBorrowedAddressRValue(value));

test/Interop/Cxx/class/Inputs/closure.h

+8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ struct ARCStrong {
2020
void cfuncARCStrong(void (*_Nonnull)(ARCStrong));
2121
#endif
2222

23+
struct ARCWeak {
24+
#if __OBJC__
25+
__weak _Nullable id m;
26+
#endif
27+
};
28+
2329
void cfuncReturnNonTrivial(NonTrivial (^_Nonnull)()) noexcept;
2430
void cfuncReturnNonTrivial2(NonTrivial (*_Nonnull)()) noexcept;
2531

32+
void (*_Nonnull getFnPtr2() noexcept)(ARCWeak) noexcept;
33+
2634
#endif // __CLOSURE__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swiftxx-frontend -I %S/Inputs -enable-sil-opaque-values -emit-silgen %s | %FileCheck --dump-input-filter=all %s
2+
3+
// REQUIRES: OS=macosx
4+
5+
import Closure
6+
7+
// CHECK: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sSo7ARCWeakVIetCi_ABIegn_TR : $@convention(thin) (@in_guaranteed ARCWeak, @convention(c) (@in ARCWeak) -> ()) -> () {
8+
// CHECK: bb0(%[[V0:.*]] : @guaranteed $ARCWeak, %[[V1:.*]] : $@convention(c) (@in ARCWeak) -> ()):
9+
// CHECK: %[[V2:.*]] = copy_value %[[V0]] : $ARCWeak
10+
// CHECK: apply %[[V1]](%[[V2]]) : $@convention(c) (@in ARCWeak) -> ()
11+
12+
public func testARCWeakFunctionPointer2() -> (ARCWeak) -> () {
13+
return getFnPtr2()
14+
}

0 commit comments

Comments
 (0)