From 6273e85ad801e9e0bfe60451708940cd90baa67a Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Mon, 27 Apr 2020 15:31:30 +0200 Subject: Fix operator_mult::op1_range for when overflow wraps. We can't solve 0 = OP1 * N by dividing by N with a wrapping type. For example: For 0 = OP1 * 2, OP1 could be 0, or MAXINT. So bail, when overflow wraps. --- gcc/range-op.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'gcc') diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 85fb187..ec60af0 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1123,6 +1123,18 @@ operator_mult::op1_range (irange &r, tree type, const irange &lhs, const irange &op2) const { tree offset; + + // FIXME: We can't solve 0 = OP1 * N by dividing by N with a + // wrapping type. Bail for now. + // + // For example: For 0 = OP1 * 2, OP1 could be 0, or + // MAXINT. + // + // For example: For 4 = OP1 * 2, OP1 could be 2 or 130 (unsigned + // 8-bit) + if (TYPE_OVERFLOW_WRAPS (type)) + return false; + if (op2.singleton_p (&offset) && !integer_zerop (offset)) return range_op_handler (TRUNC_DIV_EXPR, type)->fold_range (r, type, lhs, op2); -- cgit v1.1