[SILVerifier] Verify that debug variable types match the SSA type

This commit is contained in:
Emil Pedersen
2024-05-09 15:26:07 -07:00
parent 5f2926ca29
commit ac865eb2f9

View File

@@ -1486,39 +1486,34 @@ public:
void checkDebugVariable(SILInstruction *inst) {
std::optional<SILDebugVariable> varInfo;
if (auto *di = dyn_cast<AllocStackInst>(inst))
varInfo = di->getVarInfo();
else if (auto *di = dyn_cast<AllocBoxInst>(inst))
varInfo = di->getVarInfo();
else if (auto *di = dyn_cast<DebugValueInst>(inst))
varInfo = di->getVarInfo();
if (auto di = DebugVarCarryingInst(inst))
varInfo = di.getVarInfo();
if (!varInfo)
return;
// Retrieve debug variable type
SILType DebugVarTy;
if (varInfo->Type)
DebugVarTy = *varInfo->Type;
else {
// Fetch from related SSA value
switch (inst->getKind()) {
case SILInstructionKind::AllocStackInst:
case SILInstructionKind::AllocBoxInst:
DebugVarTy = inst->getResult(0)->getType();
break;
case SILInstructionKind::DebugValueInst:
DebugVarTy = inst->getOperand(0)->getType();
if (DebugVarTy.isAddress()) {
// FIXME: op_deref could be applied to address types only.
// FIXME: Add this check
if (varInfo->DIExpr.startsWithDeref())
DebugVarTy = DebugVarTy.getObjectType();
}
break;
default:
llvm_unreachable("impossible instruction kind");
}
SILType SSAType;
switch (inst->getKind()) {
case SILInstructionKind::AllocStackInst:
case SILInstructionKind::AllocBoxInst:
// TODO: unwrap box for AllocBox
SSAType = inst->getResult(0)->getType().getObjectType();
break;
case SILInstructionKind::DebugValueInst:
SSAType = inst->getOperand(0)->getType();
break;
default:
llvm_unreachable("impossible instruction kind");
}
SILType DebugVarTy = varInfo->Type ? *varInfo->Type :
SSAType.getObjectType();
if (!varInfo->DIExpr && !isa<AllocBoxInst>(inst)) {
// FIXME: Remove getObjectType() below when we fix create/createAddr
require(DebugVarTy.removingMoveOnlyWrapper()
== SSAType.getObjectType().removingMoveOnlyWrapper(),
"debug type mismatch without a DIExpr");
}
auto *debugScope = inst->getDebugScope();