Skip to content

Commit d145b2f

Browse files
committed
Fix divide by zero crash in Port Latency Inference of divide and modulo ops
1 parent ff8d4a4 commit d145b2f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

clear_fixed_panics.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ if [ "$#" -ne 1 ]; then
77
fi
88

99
CRASHDUMPS_DIR="$1"
10-
SUS_COMPILER="/home/lennart/Desktop/sus-compiler/target/release/sus_compiler"
10+
cargo build
11+
SUS_COMPILER="/home/lennart/Desktop/sus-compiler/target/debug/sus_compiler"
1112

1213
if [ ! -d "$CRASHDUMPS_DIR" ]; then
1314
echo "Directory $CRASHDUMPS_DIR does not exist."

src/latency/port_latency_inference.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,20 @@ fn recurse_down_expression(
171171
Some(left_v)
172172
}
173173
}
174-
BinaryOperator::Divide => (left_v.is_const() && right_v.is_const()).then(|| {
175-
left_v.const_factor /= right_v.const_factor;
176-
left_v
177-
}),
178-
BinaryOperator::Modulo => (left_v.is_const() && right_v.is_const()).then(|| {
179-
left_v.const_factor %= right_v.const_factor;
180-
left_v
181-
}),
174+
BinaryOperator::Divide => (left_v.is_const()
175+
&& right_v.is_const()
176+
&& right_v.const_factor != 0)
177+
.then(|| {
178+
left_v.const_factor /= right_v.const_factor;
179+
left_v
180+
}),
181+
BinaryOperator::Modulo => (left_v.is_const()
182+
&& right_v.is_const()
183+
&& right_v.const_factor != 0)
184+
.then(|| {
185+
left_v.const_factor %= right_v.const_factor;
186+
left_v
187+
}),
182188
_other => None,
183189
}
184190
}

0 commit comments

Comments
 (0)