From: Aldy Hernandez Date: Wed, 3 Oct 2018 17:18:52 +0000 (+0000) Subject: tree-vrp.c (extract_range_from_unary_expr): Special case all pointer conversions. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2e103ae2138ede8a4db831dea30065fe0041bc58;p=gcc.git tree-vrp.c (extract_range_from_unary_expr): Special case all pointer conversions. * tree-vrp.c (extract_range_from_unary_expr): Special case all pointer conversions. Do not do anything special for anti-ranges. From-SVN: r264815 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f17bee7ea79..6acb077b357 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-10-3 Aldy Hernandez + + * tree-vrp.c (extract_range_from_unary_expr): Special case all + pointer conversions. + Do not do anything special for anti-ranges. + 2018-10-03 Jérôme Lambourg * config/arm/vxworks.h (ARM_TARGET2_DWARF_FORMAT): Adjust to diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index f95437b3040..005fc2ffe2d 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1800,9 +1800,14 @@ extract_range_from_unary_expr (value_range *vr, tree inner_type = op0_type; tree outer_type = type; - /* If the expression evaluates to a pointer, we are only interested in - determining if it evaluates to NULL [0, 0] or non-NULL (~[0, 0]). */ - if (POINTER_TYPE_P (type)) + /* If the expression involves a pointer, we are only interested in + determining if it evaluates to NULL [0, 0] or non-NULL (~[0, 0]). + + This may lose precision when converting (char *)~[0,2] to + int, because we'll forget that the pointer can also not be 1 + or 2. In practice we don't care, as this is some idiot + storing a magic constant to a pointer. */ + if (POINTER_TYPE_P (type) || POINTER_TYPE_P (op0_type)) { if (!range_includes_zero_p (&vr0)) set_value_range_to_nonnull (vr, type); @@ -1813,15 +1818,12 @@ extract_range_from_unary_expr (value_range *vr, return; } - /* We normalize everything to a VR_RANGE, but for constant - anti-ranges we must handle them by leaving the final result - as an anti range. This allows us to convert things like - ~[0,5] seamlessly. */ - value_range_type vr_type = VR_RANGE; - if (vr0.type == VR_ANTI_RANGE - && TREE_CODE (vr0.min) == INTEGER_CST - && TREE_CODE (vr0.max) == INTEGER_CST) - vr_type = VR_ANTI_RANGE; + /* The POINTER_TYPE_P code above will have dealt with all + pointer anti-ranges. Any remaining anti-ranges at this point + will be integer conversions from SSA names that will be + normalized into VARYING. For instance: ~[x_55, x_55]. */ + gcc_assert (vr0.type != VR_ANTI_RANGE + || TREE_CODE (vr0.min) != INTEGER_CST); /* NOTES: Previously we were returning VARYING for all symbolics, but we can do better by treating them as [-MIN, +MAX]. For @@ -1844,7 +1846,7 @@ extract_range_from_unary_expr (value_range *vr, { tree min = wide_int_to_tree (outer_type, wmin); tree max = wide_int_to_tree (outer_type, wmax); - set_and_canonicalize_value_range (vr, vr_type, min, max, NULL); + set_and_canonicalize_value_range (vr, VR_RANGE, min, max, NULL); } else set_value_range_to_varying (vr);