Skip to content

🍒[cxx-interop] Relax a SILVerifier assertion for immortal reference types #81674

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 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,13 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {

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

require(objectTy.isReferenceCounted(F.getModule()),
// Immortal C++ foreign reference types are represented as trivially lowered
// types since they do not require retain/release calls.
bool isImmortalFRT = objectTy.isForeignReferenceType() &&
objectTy.getASTType()->getReferenceCounting() ==
ReferenceCounting::None;

require(objectTy.isReferenceCounted(F.getModule()) || isImmortalFRT,
valueDescription + " must have reference semantics");
}

Expand Down
20 changes: 20 additions & 0 deletions test/Interop/Cxx/foreign-reference/unmanaged.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=default -Xfrontend -disable-availability-checking) | %FileCheck %s

// REQUIRES: executable_test

import POD

extension Empty {
public static func == (lhs: Empty, rhs: Empty) -> Bool {
Unmanaged.passUnretained(lhs).toOpaque() == Unmanaged.passUnretained(rhs).toOpaque()
}
}

let x = Empty.create()
let y = Empty.create()

print(x == y)
// CHECK: false

print(x == x)
// CHECK: true