aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@linaro.org>2017-10-02 09:45:40 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2017-10-02 09:45:40 +0000
commita1488398d4abf50ff8b2ec25d6a75185aefc52c8 (patch)
treee5cca47aca114b176833f91da6a74b6829051ce5 /gcc/c-family
parent1a6da556c414bbbec6df82fdb342e8b84e205507 (diff)
downloadgcc-a1488398d4abf50ff8b2ec25d6a75185aefc52c8.zip
gcc-a1488398d4abf50ff8b2ec25d6a75185aefc52c8.tar.gz
gcc-a1488398d4abf50ff8b2ec25d6a75185aefc52c8.tar.bz2
Fix mismatched precisions in tree arithmetic
The tree wi:: decompose routine wasn't asserting that the requested precision matched the tree's precision. This could make a difference for unsigned trees that are exactly N HWIs wide and that have the upper bit set, since we then need an extra zero HWI when extending it to wider precisions (as for wi::to_widest). This patch adds the assert and fixes the fallout shown by the testsuite. Go seems to be unaffected. 2017-10-02 Richard Sandiford <richard.sandiford@linaro.org> gcc/ * tree.h (wi::int_traits <const_tree>::decompose): Assert that the requested precision matches the type's. * calls.c (alloc_max_size): Calculate the new candidate size as a widest_int and use wi::to_widest when comparing it with the current candidate size. * gimple-ssa-warn-alloca.c (pass_walloca::execute): Compare with zero rather than integer_zero_node. * match.pd: Check for a no-op conversion before using wi::add rather than after. Use tree_to_uhwi when summing small shift counts into an unsigned int. gcc/c-family/ * c-warn.c (warn_tautological_bitwise_comparison): Use wi::to_widest when combining the original unconverted comparison operands. gcc/cp/ * constexpr.c (cxx_eval_store_expression): Use wi::to_widest when comparing the array bounds with an ARRAY_REF index. gcc/ada/ * gcc-interface/decl.c (annotate_value): Use wi::to_widest when handling the form (plus/mult (convert @0) @1). From-SVN: r253341
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-warn.c10
2 files changed, 11 insertions, 4 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 3c4bd05..58797f0 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2017-10-02 Richard Sandiford <richard.sandiford@linaro.org>
+
+ * c-warn.c (warn_tautological_bitwise_comparison): Use wi::to_widest
+ when combining the original unconverted comparison operands.
+
2017-09-29 Jakub Jelinek <jakub@redhat.com>
* c-attribs.c (handle_noipa_attribute): Don't add "stack_protect"
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 0749d16..f86de10 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -355,15 +355,17 @@ warn_tautological_bitwise_comparison (location_t loc, tree_code code,
else
return;
- wide_int res;
+ /* Note that the two operands are from before the usual integer
+ conversions, so their types might not be the same. */
+ widest_int res;
if (TREE_CODE (bitop) == BIT_AND_EXPR)
- res = wi::bit_and (bitopcst, cst);
+ res = wi::to_widest (bitopcst) & wi::to_widest (cst);
else
- res = wi::bit_or (bitopcst, cst);
+ res = wi::to_widest (bitopcst) | wi::to_widest (cst);
/* For BIT_AND only warn if (CST2 & CST1) != CST1, and
for BIT_OR only if (CST2 | CST1) != CST1. */
- if (res == cst)
+ if (res == wi::to_widest (cst))
return;
if (code == EQ_EXPR)