[Bug 288778] [libm] Fix undefined behavior of a left shifted of a signed integer
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 12 Aug 2025 01:10:52 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=288778
Konstantin Belousov <kib@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kib@FreeBSD.org
--- Comment #2 from Konstantin Belousov <kib@FreeBSD.org> ---
The motivation for the UB in signed left shift is that C standard allows
several
signed integer representations, e.g. 2-complement as used by all architectures
supported by FreeBSD, or 1-complement, or sign-bit. Then it is obvious why
they stated that this is UB: depending on the representation, when the shift
moves non-zero bit into the sign position, the result interpreted as signed
integer would have different signed integer value on different arches while
having the same bit pattern.
But the problem is not that, but the current interpretation of UB by compilers.
They consider UB as a license to introduce arbitrary behavior into the compiled
code. The specific case might be not utilized (AKA broken) right now, but the
next version of a compiler can do it.
So fixing UB is vital to avoid damage from hostile compiler authors.
--
You are receiving this mail because:
You are the assignee for the bug.