Skip to content

Commit e05daed

Browse files
committed
[cxx-interop] Disable rvalue references. We don't support them correctly (leading to lifetime issues). We are missing a consuming.
1 parent e4a0b9e commit e05daed

File tree

5 files changed

+8
-51
lines changed

5 files changed

+8
-51
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2356,12 +2356,17 @@ ClangImporter::Implementation::importParameterType(
23562356
dyn_cast<clang::TemplateTypeParmType>(paramTy)) {
23572357
swiftParamTy = findGenericTypeInGenericDecls(
23582358
*this, templateParamType, genericParams, attrs, addImportDiagnosticFn);
2359-
} else if (auto refType = dyn_cast<clang::ReferenceType>(paramTy)) {
2359+
} else if (auto refType = dyn_cast<clang::ReferenceType>(paramTy)) {
23602360
// We don't support reference type to a dependent type, just bail.
23612361
if (refType->getPointeeType()->isDependentType()) {
23622362
return None;
23632363
}
23642364

2365+
// We don't support rvalue reference types, just bail.
2366+
if (refType->isRValueReferenceType()) {
2367+
return None;
2368+
}
2369+
23652370
paramTy = refType->getPointeeType();
23662371
if (!paramTy.isConstQualified())
23672372
isInOut = true;

test/Interop/Cxx/reference/reference-irgen.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,3 @@ public func setCxxConstRef() {
4545

4646
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main14setCxxConstRefyyF"()
4747
// CHECK: call void @{{_Z20setConstStaticIntRefRKi|"\?setConstStaticIntRef@@YAXAEBH@Z"}}(i32* %{{.*}})
48-
49-
public func setCxxRvalueRef() {
50-
var val: CInt = 21
51-
setStaticIntRvalueRef(&val)
52-
}
53-
54-
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main15setCxxRvalueRefyyF"()
55-
// CHECK: call void @{{_Z21setStaticIntRvalueRefOi|"\?setStaticIntRvalueRef@@YAX\$\$QEAH@Z"}}(i32* %{{.*}})
56-
57-
public func setCxxConstRvalueRef() {
58-
let val: CInt = 21
59-
setConstStaticIntRvalueRef(val)
60-
}
61-
62-
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main20setCxxConstRvalueRefyyF"()
63-
// CHECK: call void @{{_Z26setConstStaticIntRvalueRefOKi|"\?setConstStaticIntRvalueRef@@YAX\$\$QEBH@Z"}}(i32* %{{.*}})

test/Interop/Cxx/reference/reference-module-interface.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
// CHECK: func getConstStaticIntRvalueRef() -> UnsafePointer<Int32>
88
// CHECK: func setStaticInt(_: Int32)
99
// CHECK: func setStaticIntRef(_: inout Int32)
10-
// CHECK: func setStaticIntRvalueRef(_: inout Int32)
1110
// CHECK: func setConstStaticIntRef(_: Int32)
12-
// CHECK: func setConstStaticIntRvalueRef(_: Int32)
1311
// CHECK: func getFuncRef() -> @convention(c) () -> Int32
1412
// CHECK: func getFuncRvalueRef() -> @convention(c) () -> Int32
1513
// CHECK: func refToTemplate<T>(_ t: inout T) -> UnsafeMutablePointer<T>
@@ -18,3 +16,5 @@
1816
// CHECK-NOT: refToDependent
1917
// CHECK-NOT: refToDependentParam
2018
// CHECK-NOT: dontImportAtomicRef
19+
// CHECK-NOT: setStaticIntRvalueRef
20+
// CHECK-NOT: setConstStaticIntRvalueRef

test/Interop/Cxx/reference/reference-silgen.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,3 @@ func setCxxConstRef() {
5151
// CHECK: sil hidden @$s4main14setCxxConstRefyyF : $@convention(thin) () -> ()
5252
// CHECK: [[REF:%.*]] = function_ref @{{_Z20setConstStaticIntRefRKi|\?setConstStaticIntRef@@YAXAEBH@Z}} : $@convention(c) (@in_guaranteed Int32) -> ()
5353
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@in_guaranteed Int32) -> ()
54-
55-
func setCxxRvalueRef() {
56-
var val: CInt = 21
57-
setStaticIntRvalueRef(&val)
58-
}
59-
60-
// CHECK: sil hidden @$s4main15setCxxRvalueRefyyF : $@convention(thin) () -> ()
61-
// CHECK: [[REF:%.*]] = function_ref @{{_Z21setStaticIntRvalueRefOi|\?setStaticIntRvalueRef@@YAX\$\$QEAH@Z}} : $@convention(c) (@inout Int32) -> ()
62-
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@inout Int32) -> ()
63-
64-
func setCxxConstRvalueRef() {
65-
let val: CInt = 21
66-
setConstStaticIntRvalueRef(val)
67-
}
68-
69-
// CHECK: sil hidden @$s4main20setCxxConstRvalueRefyyF : $@convention(thin) () -> ()
70-
// CHECK: [[REF:%.*]] = function_ref @{{_Z26setConstStaticIntRvalueRefOKi|\?setConstStaticIntRvalueRef@@YAX\$\$QEBH@Z}} : $@convention(c) (@in_guaranteed Int32) -> ()
71-
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@in_guaranteed Int32) -> ()

test/Interop/Cxx/reference/reference.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ ReferenceTestSuite.test("pass-const-lvalue-reference") {
5151
expectEqual(22, getStaticInt())
5252
}
5353

54-
ReferenceTestSuite.test("pass-rvalue-reference") {
55-
expectNotEqual(52, getStaticInt())
56-
var val: CInt = 52
57-
setStaticIntRvalueRef(&val)
58-
expectEqual(52, getStaticInt())
59-
}
60-
61-
ReferenceTestSuite.test("pass-const-rvalue-reference") {
62-
expectNotEqual(53, getStaticInt())
63-
let val: CInt = 53
64-
setConstStaticIntRvalueRef(val)
65-
expectEqual(53, getStaticInt())
66-
}
67-
6854
ReferenceTestSuite.test("func-reference") {
6955
let cxxF: @convention(c) () -> Int32 = getFuncRef()
7056

0 commit comments

Comments
 (0)