[nvptx] Fix UB in nvptx_assemble_value
authorTom de Vries <tdevries@suse.de>
Fri, 11 Sep 2020 05:13:25 +0000 (07:13 +0200)
committerTom de Vries <tdevries@suse.de>
Fri, 11 Sep 2020 05:27:56 +0000 (07:27 +0200)
commit5e044c673f8e7d473a2207cd3ba32910c4f5fc75
tree7264d8140c269edddc43d605a816501766715353
parent60e537a026c037d8f3e5678acd148f9e44b4fb9c
[nvptx] Fix UB in nvptx_assemble_value

When nvptx_assemble_value is called with size == 16, this bitshift runs
into UB:
...
  val &= ((unsigned  HOST_WIDE_INT)2 << (size * BITS_PER_UNIT - 1)) - 1;
...

Fix this by checking the shift amount.

Tested on nvptx.

gcc/ChangeLog:

* config/nvptx/nvptx.c (nvptx_assemble_value): Fix undefined
behaviour.
gcc/config/nvptx/nvptx.c