Skip to content

Commit 03b41b7

Browse files
author
1475505
committed
A2: pass all tests.
1 parent 135d7d6 commit 03b41b7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

A2/tai-e/src/main/java/pascal/taie/analysis/dataflow/analysis/constprop/ConstantPropagation.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,18 @@ public static Value evaluate(Exp exp, CPFact in) {
164164
} else if (exp instanceof BinaryExp){
165165
Value op1 = evaluate(((BinaryExp) exp).getOperand1(), in);
166166
Value op2 = evaluate(((BinaryExp) exp).getOperand2(), in);
167+
// By issue: https://github.com/pascal-lab/Tai-e-assignments/issues/2
168+
// judge '/0' and '%0' at first.
169+
BinaryExp.Op op = ((BinaryExp) exp).getOperator();
170+
if ( op2.isConstant() && op2.getConstant() == 0 && (op == ArithmeticExp.Op.DIV || op == ArithmeticExp.Op.REM) ){
171+
return Value.getUndef();
172+
}
167173
if ( op1.isNAC() || op2.isNAC()){
168174
return Value.getNAC();
169175
}
170176
if ( !op1.isConstant() || !op2.isConstant()){
171177
return Value.getUndef();
172178
}
173-
BinaryExp.Op op = ((BinaryExp) exp).getOperator();
174179
if (op instanceof ArithmeticExp.Op) {
175180
switch ((ArithmeticExp.Op)op) {
176181
case ADD -> {

0 commit comments

Comments
 (0)