Skip to content

Commit 96cd618

Browse files
committed
[cxx-interop] Fix crash when lowering self arg in foriegn reference type method call.
1 parent 485c8cc commit 96cd618

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
@@ -1526,7 +1526,10 @@ class DestructureInputs {
15261526
convention = Convs.getIndirect(ownership, forSelf, origParamIndex,
15271527
origType, substTLConv);
15281528
assert(isIndirectFormalParameter(convention));
1529-
} else if (substTL.isTrivial()) {
1529+
} else if (substTL.isTrivial() ||
1530+
// Foreign reference types are passed trivially.
1531+
(substType->getClassOrBoundGenericClass() &&
1532+
substType->isForeignReferenceType())) {
15301533
convention = ParameterConvention::Direct_Unowned;
15311534
} else {
15321535
// 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)