Skip to content

Commit b9a8067

Browse files
committed
fix modulo for llvm
1 parent 83bfa12 commit b9a8067

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

compiler/llvm_backend.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,10 @@ def BinaryExpr(self, node: BinaryExpr):
399399
elif operator == "//":
400400
return self.builder.sdiv(lhs, rhs)
401401
elif operator == "%":
402-
return self.builder.srem(lhs, rhs)
402+
# emulate Python modulo with ((a % b) + b) % b)
403+
val = self.builder.srem(lhs, rhs)
404+
val = self.builder.add(val, rhs)
405+
return self.builder.srem(val, rhs)
403406
# relational operators
404407
elif operator in {"<", "<=", ">", ">="}:
405408
return self.builder.icmp_signed(operator, lhs, rhs)

test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"/binary_tree.",
2121
"/doubling_vector.",
2222
"/nonlocal.",
23-
"/exponent.",
24-
"/modulo."
23+
"/exponent."
2524
]
2625

2726
disabled_jvm_tests = []

0 commit comments

Comments
 (0)