2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-18 16:06:30 +08:00

compiler: fix int boundary checks

Signed-off-by: Florian Agbuya <fa@m-labs.ph>
This commit is contained in:
Florian Agbuya 2024-06-07 12:56:55 +08:00
parent ebc1e3fb76
commit 25168422ab
3 changed files with 8 additions and 8 deletions

View File

@ -747,9 +747,9 @@ class StitchingInferencer(Inferencer):
if elt.__class__ == float: if elt.__class__ == float:
state |= IS_FLOAT state |= IS_FLOAT
elif elt.__class__ == int: elif elt.__class__ == int:
if -2**31 < elt < 2**31-1: if -2**31 <= elt <= 2**31-1:
state |= IS_INT32 state |= IS_INT32
elif -2**63 < elt < 2**63-1: elif -2**63 <= elt <= 2**63-1:
state |= IS_INT64 state |= IS_INT64
else: else:
state = -1 state = -1

View File

@ -14,9 +14,9 @@ class IntMonomorphizer(algorithm.Visitor):
def visit_NumT(self, node): def visit_NumT(self, node):
if builtins.is_int(node.type): if builtins.is_int(node.type):
if types.is_var(node.type["width"]): if types.is_var(node.type["width"]):
if -2**31 < node.n < 2**31-1: if -2**31 <= node.n <= 2**31-1:
width = 32 width = 32
elif -2**63 < node.n < 2**63-1: elif -2**63 <= node.n <= 2**63-1:
width = 64 width = 64
else: else:
diag = diagnostic.Diagnostic("error", diag = diagnostic.Diagnostic("error",

View File

@ -465,12 +465,12 @@ class CommKernel:
self._write_bool(value) self._write_bool(value)
elif tag == "i": elif tag == "i":
check(isinstance(value, (int, numpy.int32)) and check(isinstance(value, (int, numpy.int32)) and
(-2**31 <= value < 2**31), (-2**31 <= value <= 2**31-1),
lambda: "32-bit int") lambda: "32-bit int")
self._write_int32(value) self._write_int32(value)
elif tag == "I": elif tag == "I":
check(isinstance(value, (int, numpy.int32, numpy.int64)) and check(isinstance(value, (int, numpy.int32, numpy.int64)) and
(-2**63 <= value < 2**63), (-2**63 <= value <= 2**63-1),
lambda: "64-bit int") lambda: "64-bit int")
self._write_int64(value) self._write_int64(value)
elif tag == "f": elif tag == "f":
@ -479,8 +479,8 @@ class CommKernel:
self._write_float64(value) self._write_float64(value)
elif tag == "F": elif tag == "F":
check(isinstance(value, Fraction) and check(isinstance(value, Fraction) and
(-2**63 <= value.numerator < 2**63) and (-2**63 <= value.numerator <= 2**63-1) and
(-2**63 <= value.denominator < 2**63), (-2**63 <= value.denominator <= 2**63-1),
lambda: "64-bit Fraction") lambda: "64-bit Fraction")
self._write_int64(value.numerator) self._write_int64(value.numerator)
self._write_int64(value.denominator) self._write_int64(value.denominator)