Skip to content

Commit 257b7e6

Browse files
committed
Specify the unchecked_ownership_conversion instruction.
All SIL instructions need their semantics specified in SIL.rst and their constraints specified in SILVerifier.
1 parent 3a0ffbb commit 257b7e6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

docs/SIL.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5894,6 +5894,25 @@ This instruction is assumed to forward a fixed ownership (set upon its
58945894
construction) and lowers to 'unchecked_bitwise_cast' in non-ossa code. This
58955895
causes the cast to lose its guarantee of layout-compatibility.
58965896

5897+
unchecked_ownership_conversion
5898+
``````````````````````````````
5899+
::
5900+
5901+
sil-instruction ::= 'unchecked_ownership_conversion' sil-operand ',' sil-value-ownership-kind 'to' sil-value-ownership-kind
5902+
5903+
%1 = unchecked_ownership_conversion %0 : $A, @guaranteed to @owned
5904+
5905+
Converts its operand to an identical value of the same type but with
5906+
different ownership without performing any semantic operations
5907+
normally required by for ownership conversion.
5908+
5909+
This is used in Objective-C compatible destructors to convert a
5910+
guaranteed parameter to an owned parameter without performing a
5911+
semantic copy.
5912+
5913+
The resulting value must meet the usual ownership requirements; for
5914+
example, a trivial type must have '.none' ownership.
5915+
58975916
ref_to_raw_pointer
58985917
``````````````````
58995918
::

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,17 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
19581958
"Inst with qualified ownership in a function that is not qualified");
19591959
}
19601960

1961+
void checkUncheckedOwnershipConversionInst(
1962+
UncheckedOwnershipConversionInst *uoci) {
1963+
require(
1964+
F.hasOwnership(),
1965+
"Inst with qualified ownership in a function that is not qualified");
1966+
require(!uoci->getType().isAddress(),
1967+
"cannot convert ownership of an address");
1968+
require(uoci->getType() == uoci->getOperand()->getType(),
1969+
"converting ownership does not affect the type");
1970+
}
1971+
19611972
template <class AI>
19621973
void checkAccessEnforcement(AI *AccessInst) {
19631974
if (AccessInst->getModule().getStage() != SILStage::Raw) {

0 commit comments

Comments
 (0)