Skip to content

Commit b0de482

Browse files
authored
Merge pull request #61757 from zoecarver/frt-method-call-crash
[cxx-interop] Fix crash when lowering self arg in foriegn reference t…
2 parents ae2afe1 + 96cd618 commit b0de482

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,10 @@ class DestructureInputs {
14971497
convention = Convs.getIndirect(ownership, forSelf, origParamIndex,
14981498
origType, substTLConv);
14991499
assert(isIndirectFormalParameter(convention));
1500-
} else if (substTL.isTrivial()) {
1500+
} else if (substTL.isTrivial() ||
1501+
// Foreign reference types are passed trivially.
1502+
(substType->getClassOrBoundGenericClass() &&
1503+
substType->isForeignReferenceType())) {
15011504
convention = ParameterConvention::Direct_Unowned;
15021505
} else {
15031506
// If we are no implicit copy, our ownership is always Owned.

test/Interop/Cxx/foreign-reference/Inputs/reference-counted.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ __attribute__((swift_attr("release:LCRelease"))) LocalCount {
2121
static LocalCount *create() {
2222
return new (malloc(sizeof(LocalCount))) LocalCount();
2323
}
24+
25+
int returns42() { return 42; }
26+
int constMethod() const { return 42; }
2427
};
2528

2629
}

test/Interop/Cxx/foreign-reference/reference-counted.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ func localTest() {
1919
var x = NS.LocalCount.create()
2020
expectEqual(x.value, 6) // This is 6 because of "var x" "x.value" * 2 and "(x, x, x)".
2121

22+
expectEqual(x.returns42(), 42)
23+
expectEqual(x.constMethod(), 42)
24+
2225
let t = (x, x, x)
2326
expectEqual(x.value, 5)
2427
}

0 commit comments

Comments
 (0)