Skip to content

Commit 5583f93

Browse files
authored
Merge pull request #81614 from swiftlang/egorzhdan/silverifier-trivial-frt
[cxx-interop] Relax a SILVerifier assertion for immortal reference types
2 parents ef74028 + 2e3df1c commit 5583f93

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
@@ -1059,7 +1059,13 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
10591059

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

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

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)