Skip to content

Commit

Permalink
partialexecuter: check for division/remainder by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyxogen authored and alexp-sssup committed Feb 13, 2024
1 parent a7897fe commit 4b9467d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions llvm/lib/CheerpWriter/PartialExecuter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,6 @@ class PartialInterpreter : public llvm::Interpreter {
if (!areOperandsComputed(I))
return true;

if (isa<CastInst>(I) || isa<BinaryOperator>(I))
return false;

switch (I.getOpcode())
{
case Instruction::Br:
Expand Down Expand Up @@ -516,9 +513,21 @@ class PartialInterpreter : public llvm::Interpreter {
// TODO(carlo): Possibly even Loads of Alloca might be proven valid
break;
}
case Instruction::SRem:
case Instruction::URem:
case Instruction::SDiv:
case Instruction::UDiv:
{
Value *Src2 = I.getOperand(1);
if (isValueComputed(Src2) && getOperandValue(Src2).IntVal.isZero())
return true; // Division or remainder by zero
return false; // Is a binary operator
}
default:
{
//Default case is for Instruction to be skipped
if (isa<CastInst>(I) || isa<BinaryOperator>(I))
return false;
// Default case is for Instruction to be skipped
return true;
}
}
Expand Down

0 comments on commit 4b9467d

Please sign in to comment.