Skip to content

Commit 8cea33a

Browse files
committed
[SIL] Verifier: Disable opaque values for ref_to.
The ref_to_* and *_to_ref instructions must not produce or take as their operands values of address-only type. The AddressLowering pass would trap on encountering such illegal instructions already. Enforce the invariant in the verifier.
1 parent b616d14 commit 8cea33a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,17 +2798,25 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
27982798
requireReferenceStorageCapableValue(I->getOperand(), \
27992799
"Operand of ref_to_" #name); \
28002800
auto operandType = I->getOperand()->getType().getASTType(); \
2801+
require(!I->getOperand()->getType().isAddressOnly(F), \
2802+
"ref_to_" #name " may not take an address-only operand"); \
28012803
auto resultType = \
28022804
requireObjectType(Name##StorageType, I, "Result of ref_to_" #name); \
2805+
require(!I->getType().isAddressOnly(F), \
2806+
"ref_to_" #name " must not produce an address-only value"); \
28032807
requireSameType(resultType.getReferentType(), operandType, \
28042808
"Result of ref_to_" #name " does not have the " \
28052809
"operand's type as its referent type"); \
28062810
} \
28072811
void check##Name##ToRefInst(Name##ToRefInst *I) { \
28082812
auto operandType = requireObjectType(Name##StorageType, I->getOperand(), \
28092813
"Operand of " #name "_to_ref"); \
2814+
require(!I->getOperand()->getType().isAddressOnly(F), \
2815+
#name "_to_ref may not take an address-only operand"); \
28102816
requireReferenceStorageCapableValue(I, "Result of " #name "_to_ref"); \
28112817
auto resultType = I->getType().getASTType(); \
2818+
require(!I->getType().isAddressOnly(F), \
2819+
#name "_to_ref may not produce an address-only value"); \
28122820
requireSameType(operandType.getReferentType(), resultType, \
28132821
"Operand of " #name "_to_ref does not have the " \
28142822
"operand's type as its referent type"); \

0 commit comments

Comments
 (0)