diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2020-11-11 15:08:16 +0100 |
---|---|---|
committer | Eric Botcazou <ebotcazou@adacore.com> | 2020-11-11 15:08:16 +0100 |
commit | 4e1a215870a4194c9ca884ef838103c094aa38c8 (patch) | |
tree | 5d7691de83cb47420e00970c33c7748cf95a4b70 /gcc/ada | |
parent | ec1b8711945e99677fe5b135d343781bc2e106ad (diff) | |
download | gcc-4e1a215870a4194c9ca884ef838103c094aa38c8.zip gcc-4e1a215870a4194c9ca884ef838103c094aa38c8.tar.gz gcc-4e1a215870a4194c9ca884ef838103c094aa38c8.tar.bz2 |
Fix biased integer arithmetic
The Ada compiler uses a biased representation when a size clause reserves
fewer bits than normal either for the lower or for the upper bound.
gcc/ada/ChangeLog:
* gcc-interface/trans.c (build_binary_op_trapv): Convert operands
to the result type before doing generic overflow checking.
gcc/testsuite/ChangeLog:
* gnat.dg/bias2.adb: New test.
Diffstat (limited to 'gcc/ada')
-rw-r--r-- | gcc/ada/gcc-interface/trans.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 065fcd2..7be8463 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -9361,6 +9361,11 @@ build_binary_op_trapv (enum tree_code code, tree gnu_type, tree left, /* If no operand is a constant, we use the generic implementation. */ if (TREE_CODE (lhs) != INTEGER_CST && TREE_CODE (rhs) != INTEGER_CST) { + /* First convert the operands to the result type like build_binary_op. + This is where the bias is made explicit for biased types. */ + lhs = convert (gnu_type, lhs); + rhs = convert (gnu_type, rhs); + /* Never inline a 64-bit mult for a 32-bit target, it's way too long. */ if (code == MULT_EXPR && precision == 64 && BITS_PER_WORD < 64) { |