[Bug c++/98625] UBSAN: gcc/cp/module.cc:977:15: runtime error: left shift of negative value -1
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98625 Martin Liška changed: What|Removed |Added Resolution|--- |FIXED Status|ASSIGNED|RESOLVED --- Comment #5 from Martin Liška --- Fixed with: commit 911f797a9be2dc8ef59f5d5bd6d68baf650b8822 Author: Nathan Sidwell Date: Wed Jan 20 09:21:02 2021 -0800 c++: Avoid UB in signed shift [PR 98625] I'd forgotten that left shifting a negative value is UB until C++20. Insert some casts to do unsigned shifts. PT c++/98625 gcc/cp/ * module.cc (bytes_in::i, bytes_in::wi): Avoid left shift of signed type. @Nathan: That was very close, s/PT/PR :)
[Bug c++/98625] UBSAN: gcc/cp/module.cc:977:15: runtime error: left shift of negative value -1
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98625 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #4 from Jakub Jelinek --- Note, -1 << x shifts are well defined in C++20 (assuming x < sizeof (int) * CHAR_BIT), but isn't well defined in older C++ versions. For C++11 .. C++17 in particular, x << y is UB if x < 0 or ((unsigned) x >> (sizeof (int) * CHAR_BIT - 1 - y)) > 1 (in addition to the usual y < 0 or y >= sizeof (int) * CHAR_BIT).
[Bug c++/98625] UBSAN: gcc/cp/module.cc:977:15: runtime error: left shift of negative value -1
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98625 --- Comment #3 from Martin Liška --- > only >> 4 and << 8 shifts going on there. The thing is here that -1 is being shifted. That's undefined, you likely want to do shifting in an unsigned type and later cast to an unsigned type.
[Bug c++/98625] UBSAN: gcc/cp/module.cc:977:15: runtime error: left shift of negative value -1
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98625 --- Comment #2 from Nathan Sidwell --- This looks like a ubsan or optimizer bug. I can't see a -ve shift in the source: HOST_WIDE_INT bytes_in::wi () { HOST_WIDE_INT v = 0; if (const char *ptr = read (1)) { v = *ptr & 0xff; if (v & 0x80) { unsigned bytes = (v >> 4) & 0x7; v &= 0xf; if (v & 0x8) v |= -1 ^ 0x7; if ((ptr = read (++bytes))) while (bytes--) v = (v << 8) | (*ptr++ & 0xff); } else if (v & 0x40) v |= -1 ^ 0x3f; } return v; } only >> 4 and << 8 shifts going on there.
[Bug c++/98625] UBSAN: gcc/cp/module.cc:977:15: runtime error: left shift of negative value -1
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98625 Nathan Sidwell changed: What|Removed |Added Status|NEW |ASSIGNED --- Comment #1 from Nathan Sidwell --- magic configure: --with-build-config=bootstrap-ubsan
[Bug c++/98625] UBSAN: gcc/cp/module.cc:977:15: runtime error: left shift of negative value -1
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98625 Martin Liška changed: What|Removed |Added Ever confirmed|0 |1 See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=98624 Last reconfirmed||2021-01-11 Status|UNCONFIRMED |NEW