[gcc r11-3127] [nvptx] Fix printing of 128-bit constant
Tom de Vries
vries@gcc.gnu.org
Thu Sep 10 19:30:57 GMT 2020
https://gcc.gnu.org/g:af47a2035a4882e6d4506e3d00b5a42414e3ee2b
commit r11-3127-gaf47a2035a4882e6d4506e3d00b5a42414e3ee2b
Author: Tom de Vries <tdevries@suse.de>
Date: Thu Sep 10 15:54:14 2020 +0200
[nvptx] Fix printing of 128-bit constant
Currently, for this code from c-c++-common/spec-barrier-1.c:
...
__int128 g = 9;
...
we generate:
...
// BEGIN GLOBAL VAR DEF: g
.visible .global .align 8 .u64 g[2] = { 9, 9 };
...
and consequently the test-case fails in execution.
The problem is caused by a shift in nvptx_assemble_value:
...
val >>= part * BITS_PER_UNIT;
...
where the shift amount is equal to the number of bits in val, which is
undefined behaviour.
Fix this by detecting the situation and setting val to 0.
Tested on nvptx.
gcc/ChangeLog:
PR target/97004
* config/nvptx/nvptx.c (nvptx_assemble_value): Handle shift by
number of bits in shift operand.
Diff:
---
gcc/config/nvptx/nvptx.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c
index 0376ad6ce9f..ffcbe591a8f 100644
--- a/gcc/config/nvptx/nvptx.c
+++ b/gcc/config/nvptx/nvptx.c
@@ -2054,7 +2054,11 @@ nvptx_assemble_value (unsigned HOST_WIDE_INT val, unsigned size)
for (unsigned part = 0; size; size -= part)
{
- val >>= part * BITS_PER_UNIT;
+ if (part * BITS_PER_UNIT == HOST_BITS_PER_WIDE_INT)
+ /* Avoid undefined behaviour. */
+ val = 0;
+ else
+ val >>= (part * BITS_PER_UNIT);
part = init_frag.size - init_frag.offset;
part = MIN (part, size);
More information about the Gcc-cvs
mailing list