Skip to content

Commit 2adcf4f

Browse files
committed
[sil] Catch if we are creating ABI incompatible convert_function instructions when constructing the inst.
I ran into this earlier today. It is a pretty annoying error to track down in SILGen since the verifier doesn't run until the full function is emitted. With this change, we get a check immediately when the value is constructed by SILBuilder making it a very easy problem to track down.
1 parent 7f25e57 commit 2adcf4f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/SIL/SILInstructions.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,8 +2107,18 @@ ConvertFunctionInst::create(SILDebugLocation DebugLoc, SILValue Operand,
21072107
unsigned size =
21082108
totalSizeToAlloc<swift::Operand>(1 + TypeDependentOperands.size());
21092109
void *Buffer = Mod.allocateInst(size, alignof(ConvertFunctionInst));
2110-
return ::new (Buffer) ConvertFunctionInst(DebugLoc, Operand,
2111-
TypeDependentOperands, Ty);
2110+
auto *CFI = ::new (Buffer)
2111+
ConvertFunctionInst(DebugLoc, Operand, TypeDependentOperands, Ty);
2112+
// Make sure we are not performing ABI-incompatible conversions.
2113+
CanSILFunctionType opTI =
2114+
CFI->getOperand()->getType().castTo<SILFunctionType>();
2115+
(void)opTI;
2116+
CanSILFunctionType resTI =
2117+
CFI->getOperand()->getType().castTo<SILFunctionType>();
2118+
(void)resTI;
2119+
assert(opTI->isABICompatibleWith(resTI).isCompatible() &&
2120+
"Can not convert in between ABI incompatible function types");
2121+
return CFI;
21122122
}
21132123

21142124
bool KeyPathPatternComponent::isComputedSettablePropertyMutating() const {

0 commit comments

Comments
 (0)