Commit c35a27f3 authored by Stefan Behnel's avatar Stefan Behnel

avoid useless signedness checks in overflow handling when we know the type is signed

parent 17191aad
...@@ -9239,13 +9239,17 @@ class DivNode(NumBinopNode): ...@@ -9239,13 +9239,17 @@ class DivNode(NumBinopNode):
code.putln("}") code.putln("}")
if self.type.is_int and self.type.signed and self.operator != '%': if self.type.is_int and self.type.signed and self.operator != '%':
code.globalstate.use_utility_code(division_overflow_test_code) code.globalstate.use_utility_code(division_overflow_test_code)
type_of_op2 = self.operand2.type.declaration_code('') if self.operand2.type.signed == 2:
code.putln("else if (sizeof(%s) == sizeof(long)" # explicitly signed, no runtime check needed
" && (!(((%s)-1) > 0)) && unlikely(%s == (%s)-1)" minus1_check = 'unlikely(%s == -1)' % self.operand2.result()
else:
type_of_op2 = self.operand2.type.declaration_code('')
minus1_check = '(!(((%s)-1) > 0)) && unlikely(%s == (%s)-1)' % (
type_of_op2, self.operand2.result(), type_of_op2)
code.putln("else if (sizeof(%s) == sizeof(long) && %s "
" && unlikely(UNARY_NEG_WOULD_OVERFLOW(%s))) {" % ( " && unlikely(UNARY_NEG_WOULD_OVERFLOW(%s))) {" % (
self.type.declaration_code(''), self.type.declaration_code(''),
type_of_op2, minus1_check,
self.operand2.result(), type_of_op2,
self.operand1.result())) self.operand1.result()))
code.put_ensure_gil() code.put_ensure_gil()
code.putln('PyErr_SetString(PyExc_OverflowError, "value too large to perform division");') code.putln('PyErr_SetString(PyExc_OverflowError, "value too large to perform division");')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment