Skip to content

Commit d6b2f07

Browse files
committed
[SILVerifier] Verify that debug variable types match the SSA type
(cherry picked from commit ac865eb)
1 parent f2466f5 commit d6b2f07

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
@@ -1465,39 +1465,34 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
14651465

14661466
void checkDebugVariable(SILInstruction *inst) {
14671467
std::optional<SILDebugVariable> varInfo;
1468-
if (auto *di = dyn_cast<AllocStackInst>(inst))
1469-
varInfo = di->getVarInfo();
1470-
else if (auto *di = dyn_cast<AllocBoxInst>(inst))
1471-
varInfo = di->getVarInfo();
1472-
else if (auto *di = dyn_cast<DebugValueInst>(inst))
1473-
varInfo = di->getVarInfo();
1468+
if (auto di = DebugVarCarryingInst(inst))
1469+
varInfo = di.getVarInfo();
14741470

14751471
if (!varInfo)
14761472
return;
14771473

14781474
// Retrieve debug variable type
1479-
SILType DebugVarTy;
1480-
if (varInfo->Type)
1481-
DebugVarTy = *varInfo->Type;
1482-
else {
1483-
// Fetch from related SSA value
1484-
switch (inst->getKind()) {
1485-
case SILInstructionKind::AllocStackInst:
1486-
case SILInstructionKind::AllocBoxInst:
1487-
DebugVarTy = inst->getResult(0)->getType();
1488-
break;
1489-
case SILInstructionKind::DebugValueInst:
1490-
DebugVarTy = inst->getOperand(0)->getType();
1491-
if (DebugVarTy.isAddress()) {
1492-
// FIXME: op_deref could be applied to address types only.
1493-
// FIXME: Add this check
1494-
if (varInfo->DIExpr.startsWithDeref())
1495-
DebugVarTy = DebugVarTy.getObjectType();
1496-
}
1497-
break;
1498-
default:
1499-
llvm_unreachable("impossible instruction kind");
1500-
}
1475+
SILType SSAType;
1476+
switch (inst->getKind()) {
1477+
case SILInstructionKind::AllocStackInst:
1478+
case SILInstructionKind::AllocBoxInst:
1479+
// TODO: unwrap box for AllocBox
1480+
SSAType = inst->getResult(0)->getType().getObjectType();
1481+
break;
1482+
case SILInstructionKind::DebugValueInst:
1483+
SSAType = inst->getOperand(0)->getType();
1484+
break;
1485+
default:
1486+
llvm_unreachable("impossible instruction kind");
1487+
}
1488+
1489+
SILType DebugVarTy = varInfo->Type ? *varInfo->Type :
1490+
SSAType.getObjectType();
1491+
if (!varInfo->DIExpr && !isa<AllocBoxInst>(inst)) {
1492+
// FIXME: Remove getObjectType() below when we fix create/createAddr
1493+
require(DebugVarTy.removingMoveOnlyWrapper()
1494+
== SSAType.getObjectType().removingMoveOnlyWrapper(),
1495+
"debug type mismatch without a DIExpr");
15011496
}
15021497

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

0 commit comments

Comments
 (0)