Fix mismatched precisions in tree arithmetic
commitcb7bca5f786ec53f02e19b8a206b578290bebc4d
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 2 Oct 2017 09:45:40 +0000 (2 09:45 +0000)
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 2 Oct 2017 09:45:40 +0000 (2 09:45 +0000)
treee5cca47aca114b176833f91da6a74b6829051ce5
parent380dd89cf280105564730c53a55d7cd79464cfac
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).

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253341 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/ada/ChangeLog
gcc/ada/gcc-interface/decl.c
gcc/c-family/ChangeLog
gcc/c-family/c-warn.c
gcc/calls.c
gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/gimple-ssa-warn-alloca.c
gcc/match.pd
gcc/tree.h