Skip to content

Commit f8e007a

Browse files
committed
SR-12802: Disambiguate functions with lvalue and rvalue reference parameters in the same overload set
1 parent 33335f9 commit f8e007a

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,9 +2291,11 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
22912291
return nullptr;
22922292
}
22932293

2294-
paramTy = refType->getPointeeType();
2295-
if (!paramTy.isConstQualified())
2296-
isInOut = true;
2294+
paramTy = refType->getPointeeType();
2295+
if (isa<clang::LValueReferenceType>(paramTy)
2296+
&& !paramTy.isConstQualified()) {
2297+
isInOut = true;
2298+
}
22972299
}
22982300

22992301
if (!swiftParamTy) {

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,9 +1327,25 @@ static bool isClangTypeMoreIndirectThanSubstType(TypeConverter &TC,
13271327
// Pass C++ const reference types indirectly. Right now there's no way to
13281328
// express immutable borrowed params, so we have to have this hack.
13291329
// Eventually, we should just express these correctly: rdar://89647503
1330-
if (clangTy->isReferenceType() &&
1331-
clangTy->getPointeeType().isConstQualified())
1332-
return true;
1330+
1331+
/*
1332+
Why does this not compile?
1333+
if (clangTy->getPointeeType().isConstQualified() ||
1334+
clangTy->isRValueReferenceType()) {
1335+
1336+
return true;
1337+
}
1338+
*/
1339+
if (clangTy->isReferenceType()) {
1340+
if (clangTy->getPointeeType().isConstQualified() ||
1341+
//The tests in Interop/Cxx/stdlib/use-std-vector.swift fails if we dont have this check.
1342+
clangTy->isRValueReferenceType()) {
1343+
1344+
// printf("clangTy->getPointeeType(): %s", clangTy->getPointeeType().getAsString().c_str());
1345+
1346+
return true;
1347+
}
1348+
}
13331349

13341350
return false;
13351351
}

test/Interop/Cxx/class/method/ambiguous-methods-module-interface.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// CHECK: func increment(_ a: Int32) -> Int32
44
// CHECK: mutating func incrementMutating(_ a: Int32) -> Int32
55

6-
// CHECK: mutating func incrementMutating(_ a: Int32, _ b: Int32, _ c: inout Int32)
7-
// CHECK: func increment(_ a: Int32, _ b: Int32, _ c: inout Int32)
6+
// CHECK: mutating func incrementMutating(_ a: Int32, _ b: Int32, _ c: Int32)
7+
// CHECK: func increment(_ a: Int32, _ b: Int32, _ c: Int32)
88

9-
// CHECK: mutating func incrementMutating(_ a: inout Int32, _ b: Int32)
10-
// CHECK: func increment(_ a: inout Int32, _ b: Int32)
9+
// CHECK: mutating func incrementMutating(_ a: Int32, _ b: Int32)
10+
// CHECK: func increment(_ a: Int32, _ b: Int32)
1111

1212
// CHECK: func numberOfMutableMethodsCalled() -> Int32
1313
// CHECK: mutating func numberOfMutableMethodsCalledMutating() -> Int32

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public func getConstCxxRvalueRef() -> UnsafePointer<CInt> {
3232

3333
public func setCxxRef() {
3434
var val: CInt = 21
35-
setStaticIntRef(&val)
35+
setStaticIntRef(val)
3636
}
3737

3838
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main9setCxxRefyyF"()
@@ -48,7 +48,7 @@ public func setCxxConstRef() {
4848

4949
public func setCxxRvalueRef() {
5050
var val: CInt = 21
51-
setStaticIntRvalueRef(&val)
51+
setStaticIntRvalueRef(val)
5252
}
5353

5454
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main15setCxxRvalueRefyyF"()

test/Interop/Cxx/stdlib/use-std-vector.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ StdVectorTestSuite.test("init") {
2424

2525
StdVectorTestSuite.test("push back") {
2626
var v = Vector()
27-
var _42: CInt = 42
28-
v.push_back(&_42)
27+
v.push_back(42)
2928
expectEqual(v.size(), 1)
3029
expectFalse(v.empty())
3130
expectEqual(v[0], 42)
3231
}
3332

3433
func fill(vector v: inout Vector) {
35-
var _1: CInt = 1, _2: CInt = 2, _3: CInt = 3
36-
v.push_back(&_1)
37-
v.push_back(&_2)
38-
v.push_back(&_3)
34+
v.push_back(1)
35+
v.push_back(2)
36+
v.push_back(3)
3937
}
4038

4139
// TODO: in some configurations the stdlib emits a "initializeWithCopy" where the arguments

0 commit comments

Comments
 (0)