Skip to content

Commit ac865eb

Browse files
committed
[SILVerifier] Verify that debug variable types match the SSA type
1 parent 5f2926c commit ac865eb

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,39 +1486,34 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
14861486

14871487
void checkDebugVariable(SILInstruction *inst) {
14881488
std::optional<SILDebugVariable> varInfo;
1489-
if (auto *di = dyn_cast<AllocStackInst>(inst))
1490-
varInfo = di->getVarInfo();
1491-
else if (auto *di = dyn_cast<AllocBoxInst>(inst))
1492-
varInfo = di->getVarInfo();
1493-
else if (auto *di = dyn_cast<DebugValueInst>(inst))
1494-
varInfo = di->getVarInfo();
1489+
if (auto di = DebugVarCarryingInst(inst))
1490+
varInfo = di.getVarInfo();
14951491

14961492
if (!varInfo)
14971493
return;
14981494

14991495
// Retrieve debug variable type
1500-
SILType DebugVarTy;
1501-
if (varInfo->Type)
1502-
DebugVarTy = *varInfo->Type;
1503-
else {
1504-
// Fetch from related SSA value
1505-
switch (inst->getKind()) {
1506-
case SILInstructionKind::AllocStackInst:
1507-
case SILInstructionKind::AllocBoxInst:
1508-
DebugVarTy = inst->getResult(0)->getType();
1509-
break;
1510-
case SILInstructionKind::DebugValueInst:
1511-
DebugVarTy = inst->getOperand(0)->getType();
1512-
if (DebugVarTy.isAddress()) {
1513-
// FIXME: op_deref could be applied to address types only.
1514-
// FIXME: Add this check
1515-
if (varInfo->DIExpr.startsWithDeref())
1516-
DebugVarTy = DebugVarTy.getObjectType();
1517-
}
1518-
break;
1519-
default:
1520-
llvm_unreachable("impossible instruction kind");
1521-
}
1496+
SILType SSAType;
1497+
switch (inst->getKind()) {
1498+
case SILInstructionKind::AllocStackInst:
1499+
case SILInstructionKind::AllocBoxInst:
1500+
// TODO: unwrap box for AllocBox
1501+
SSAType = inst->getResult(0)->getType().getObjectType();
1502+
break;
1503+
case SILInstructionKind::DebugValueInst:
1504+
SSAType = inst->getOperand(0)->getType();
1505+
break;
1506+
default:
1507+
llvm_unreachable("impossible instruction kind");
1508+
}
1509+
1510+
SILType DebugVarTy = varInfo->Type ? *varInfo->Type :
1511+
SSAType.getObjectType();
1512+
if (!varInfo->DIExpr && !isa<AllocBoxInst>(inst)) {
1513+
// FIXME: Remove getObjectType() below when we fix create/createAddr
1514+
require(DebugVarTy.removingMoveOnlyWrapper()
1515+
== SSAType.getObjectType().removingMoveOnlyWrapper(),
1516+
"debug type mismatch without a DIExpr");
15221517
}
15231518

15241519
auto *debugScope = inst->getDebugScope();

0 commit comments

Comments
 (0)