]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gas: special-case division / modulo by ±1
authorJan Beulich <jbeulich@suse.com>
Mon, 6 Jan 2025 15:01:07 +0000 (16:01 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 6 Jan 2025 15:01:07 +0000 (16:01 +0100)
commit30200464e9dd7903be8f186ea137b7982f812670
treef6e15a0db753b3377ee8b16dc8c3451b477fb4fa
parent8ac42dbf5001416e6b741c5361be14186afde5b0
gas: special-case division / modulo by ±1

Dividing the largest possible negative value by -1 generally is UB, for
the result not being representable at least in commonly used binary
notation. This UB on x86, for example, is a Floating Point Exception on
Linux, i.e. resulting in an internal error (albeit only when
sizeof(valueT) == sizeof(void *); the library routine otherwise involved
apparently deals with the inputs quite okay).

Leave original values unaltered for division by 1; this may matter down
the road, in case we start including X_unsigned and X_extrabit in
arithmetic. For the same reason treat modulo by 1 the same as modulo by
-1.

The quad and octa tests have more relaxed expecations than intended, for
X_unsigned and X_extrabit not being taken into account [yet]. The upper
halves can wrongly end up as all ones (for .octa, when !BFD64, even the
upper three quarters). Yet it makes little sense to address this just
for div/mod by ±1. quad-div2 is yet more special, to cover for most
32-bit targets being unable to deal with forward-ref expressions in
.quad even when BFD64; even ones being able to (like x86) then still
don't get the values right.
gas/expr.c
gas/symbols.c
gas/testsuite/gas/all/gas.exp
gas/testsuite/gas/all/octa-div.d [new file with mode: 0644]
gas/testsuite/gas/all/octa-div.s [new file with mode: 0644]
gas/testsuite/gas/all/quad-div.d [new file with mode: 0644]
gas/testsuite/gas/all/quad-div.s [new file with mode: 0644]
gas/testsuite/gas/all/quad-div2.d [new file with mode: 0644]
gas/testsuite/gas/all/quad-div2.s [new file with mode: 0644]