[Bug middle-end/121593] Miscompiles small function to produce endless(?) loop
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Aug 19 17:39:26 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121593
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #16 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is NOT a GCC bug.
`char*` and `qchar8_t *` don't alias according to the C++ aliasing rules.
So:
auto* &i = reinterpret_cast<const qchar8_t *&>(it);
and then incrrementing i will not work correctly.
This is why -fno-strict-aliasing works.
So the correct fix is:
constexpr char32_t invalidValue = 0xFFFFFFFF;
static_assert(invalidValue > QChar::LastValidCodePoint);
const qchar8_t *i = (const qchar8_t *)it;
const qchar8_t *e = (const qchar8_t *)end;
const char32_t result = QUtf8Functions::nextCharacterFromUtf8(i, e,
invalidValue);
it = (const char *)i;
end = (const char *)e;
return result == invalidValue ? NextResult{U'\0', true}
: NextResult{result, false};
More information about the Gcc-bugs
mailing list