Skip to content

Commit 36511a2

Browse files
authored
Merge pull request #81674 from swiftlang/egorzhdan/6.2-silverifier-trivial-frt
🍒[cxx-interop] Relax a SILVerifier assertion for immortal reference types
2 parents 6d254b7 + 069c421 commit 36511a2

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,13 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
10581058

10591059
auto objectTy = value->getType().unwrapOptionalType();
10601060

1061-
require(objectTy.isReferenceCounted(F.getModule()),
1061+
// Immortal C++ foreign reference types are represented as trivially lowered
1062+
// types since they do not require retain/release calls.
1063+
bool isImmortalFRT = objectTy.isForeignReferenceType() &&
1064+
objectTy.getASTType()->getReferenceCounting() ==
1065+
ReferenceCounting::None;
1066+
1067+
require(objectTy.isReferenceCounted(F.getModule()) || isImmortalFRT,
10621068
valueDescription + " must have reference semantics");
10631069
}
10641070

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=default -Xfrontend -disable-availability-checking) | %FileCheck %s
2+
3+
// REQUIRES: executable_test
4+
5+
import POD
6+
7+
extension Empty {
8+
public static func == (lhs: Empty, rhs: Empty) -> Bool {
9+
Unmanaged.passUnretained(lhs).toOpaque() == Unmanaged.passUnretained(rhs).toOpaque()
10+
}
11+
}
12+
13+
let x = Empty.create()
14+
let y = Empty.create()
15+
16+
print(x == y)
17+
// CHECK: false
18+
19+
print(x == x)
20+
// CHECK: true

0 commit comments

Comments
 (0)