* [PATCH][rs6000][PR92379] fix UB shift of 64-bit type by 64 bits
@ 2020-03-13 23:10 Aaron Sawdey
0 siblings, 0 replies; only message in thread
From: Aaron Sawdey @ 2020-03-13 23:10 UTC (permalink / raw)
To: gcc-patches; +Cc: segher
This is a fix for PR92379. Passes regstrap on ppc64le. Pre-approved by
Segher, committing after posting.
2020-03-13 Aaron Sawdey <acsawdey@linux.ibm.com>
PR target/92379
* config/rs6000/rs6000.c (num_insns_constant_multi) Don't shift a
64-bit value by 64 bits (UB).
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 24598aff663..5798f924472 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -5612,7 +5612,10 @@ num_insns_constant_multi (HOST_WIDE_INT value,
machine_mode mode)
&& rs6000_is_valid_and_mask (GEN_INT (low), DImode))
insns = 2;
total += insns;
- value >>= BITS_PER_WORD;
+ /* If BITS_PER_WORD is the number of bits in HOST_WIDE_INT, doing
+ it all at once would be UB. */
+ value >>= (BITS_PER_WORD - 1);
+ value >>= 1;
}
return total;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-03-13 23:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 23:10 [PATCH][rs6000][PR92379] fix UB shift of 64-bit type by 64 bits Aaron Sawdey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).