aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/RuntimeCheck.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-13 08:43:17 +0000
committer_ov4 <ov4@ov4.org>2026-10-13 08:43:17 +0000
commitc6dbd14ec8ff94df47d3c2137cc5234203ec5e0c (patch)
tree6e07a8384d28c9a92ca56e9cb2dca2017b1817cb /lib/CodeGen/RuntimeCheck.cc
parent56f17f199ee2bc0a77e090c43dd367f43c909f2c (diff)
fix: check division and modulo for zero divisors
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/RuntimeCheck.cc')
-rw-r--r--lib/CodeGen/RuntimeCheck.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/CodeGen/RuntimeCheck.cc b/lib/CodeGen/RuntimeCheck.cc
index 40304fd..8075873 100644
--- a/lib/CodeGen/RuntimeCheck.cc
+++ b/lib/CodeGen/RuntimeCheck.cc
@@ -57,7 +57,12 @@ void RuntimeCheck::emitErrorAndExit(Value *Condition, Value *Msg, ArrayRef<Value
}
void RuntimeCheck::emitDivZeroCheck(Value *Divisor, int Line) {
- Value *IsZero = Builder.CreateICmpEQ(Divisor, ConstantInt::get(TheContext, APInt(64, 0)), "is_zero");
+ Value *IsZero;
+ if (Divisor->getType()->isDoubleTy()) {
+ IsZero = Builder.CreateFCmpOEQ(Divisor, ConstantFP::get(Divisor->getType(), 0.0), "is_zero");
+ } else {
+ IsZero = Builder.CreateICmpEQ(Divisor, ConstantInt::get(Divisor->getType(), 0), "is_zero");
+ }
emitErrorAndExit(IsZero, DivZeroMsg, Line);
}