Skip to content

[cxx-interop] Disable rvalue references. We don't support them correc… #65578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2356,12 +2356,17 @@ ClangImporter::Implementation::importParameterType(
dyn_cast<clang::TemplateTypeParmType>(paramTy)) {
swiftParamTy = findGenericTypeInGenericDecls(
*this, templateParamType, genericParams, attrs, addImportDiagnosticFn);
} else if (auto refType = dyn_cast<clang::ReferenceType>(paramTy)) {
} else if (auto refType = dyn_cast<clang::ReferenceType>(paramTy)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we introduced some whitespace at the end here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's resolved in updated PR

// We don't support reference type to a dependent type, just bail.
if (refType->getPointeeType()->isDependentType()) {
return None;
}

// We don't support rvalue reference types, just bail.
if (refType->isRValueReferenceType()) {
return None;
}

paramTy = refType->getPointeeType();
if (!paramTy.isConstQualified())
isInOut = true;
Expand Down
16 changes: 0 additions & 16 deletions test/Interop/Cxx/reference/reference-irgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,3 @@ public func setCxxConstRef() {

// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main14setCxxConstRefyyF"()
// CHECK: call void @{{_Z20setConstStaticIntRefRKi|"\?setConstStaticIntRef@@YAXAEBH@Z"}}(i32* %{{.*}})

public func setCxxRvalueRef() {
var val: CInt = 21
setStaticIntRvalueRef(&val)
}

// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main15setCxxRvalueRefyyF"()
// CHECK: call void @{{_Z21setStaticIntRvalueRefOi|"\?setStaticIntRvalueRef@@YAX\$\$QEAH@Z"}}(i32* %{{.*}})

public func setCxxConstRvalueRef() {
let val: CInt = 21
setConstStaticIntRvalueRef(val)
}

// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main20setCxxConstRvalueRefyyF"()
// CHECK: call void @{{_Z26setConstStaticIntRvalueRefOKi|"\?setConstStaticIntRvalueRef@@YAX\$\$QEBH@Z"}}(i32* %{{.*}})
4 changes: 2 additions & 2 deletions test/Interop/Cxx/reference/reference-module-interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
// CHECK: func getConstStaticIntRvalueRef() -> UnsafePointer<Int32>
// CHECK: func setStaticInt(_: Int32)
// CHECK: func setStaticIntRef(_: inout Int32)
// CHECK: func setStaticIntRvalueRef(_: inout Int32)
// CHECK: func setConstStaticIntRef(_: Int32)
// CHECK: func setConstStaticIntRvalueRef(_: Int32)
// CHECK: func getFuncRef() -> @convention(c) () -> Int32
// CHECK: func getFuncRvalueRef() -> @convention(c) () -> Int32
// CHECK: func refToTemplate<T>(_ t: inout T) -> UnsafeMutablePointer<T>
Expand All @@ -18,3 +16,5 @@
// CHECK-NOT: refToDependent
// CHECK-NOT: refToDependentParam
// CHECK-NOT: dontImportAtomicRef
// CHECK-NOT: setStaticIntRvalueRef
// CHECK-NOT: setConstStaticIntRvalueRef
18 changes: 0 additions & 18 deletions test/Interop/Cxx/reference/reference-silgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,3 @@ func setCxxConstRef() {
// CHECK: sil hidden @$s4main14setCxxConstRefyyF : $@convention(thin) () -> ()
// CHECK: [[REF:%.*]] = function_ref @{{_Z20setConstStaticIntRefRKi|\?setConstStaticIntRef@@YAXAEBH@Z}} : $@convention(c) (@in_guaranteed Int32) -> ()
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@in_guaranteed Int32) -> ()

func setCxxRvalueRef() {
var val: CInt = 21
setStaticIntRvalueRef(&val)
}

// CHECK: sil hidden @$s4main15setCxxRvalueRefyyF : $@convention(thin) () -> ()
// CHECK: [[REF:%.*]] = function_ref @{{_Z21setStaticIntRvalueRefOi|\?setStaticIntRvalueRef@@YAX\$\$QEAH@Z}} : $@convention(c) (@inout Int32) -> ()
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@inout Int32) -> ()

func setCxxConstRvalueRef() {
let val: CInt = 21
setConstStaticIntRvalueRef(val)
}

// CHECK: sil hidden @$s4main20setCxxConstRvalueRefyyF : $@convention(thin) () -> ()
// CHECK: [[REF:%.*]] = function_ref @{{_Z26setConstStaticIntRvalueRefOKi|\?setConstStaticIntRvalueRef@@YAX\$\$QEBH@Z}} : $@convention(c) (@in_guaranteed Int32) -> ()
// CHECK: apply [[REF]](%{{[0-9]+}}) : $@convention(c) (@in_guaranteed Int32) -> ()
14 changes: 0 additions & 14 deletions test/Interop/Cxx/reference/reference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,6 @@ ReferenceTestSuite.test("pass-const-lvalue-reference") {
expectEqual(22, getStaticInt())
}

ReferenceTestSuite.test("pass-rvalue-reference") {
expectNotEqual(52, getStaticInt())
var val: CInt = 52
setStaticIntRvalueRef(&val)
expectEqual(52, getStaticInt())
}

ReferenceTestSuite.test("pass-const-rvalue-reference") {
expectNotEqual(53, getStaticInt())
let val: CInt = 53
setConstStaticIntRvalueRef(val)
expectEqual(53, getStaticInt())
}

ReferenceTestSuite.test("func-reference") {
let cxxF: @convention(c) () -> Int32 = getFuncRef()

Expand Down