Date: Tue, 12 Aug 2025 01:10:52 +0000 From: bugzilla-noreply@freebsd.org To: numerics@FreeBSD.org Subject: [Bug 288778] [libm] Fix undefined behavior of a left shifted of a signed integer Message-ID: <bug-288778-18636-IOEV5kq8LH@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-288778-18636@https.bugs.freebsd.org/bugzilla/>
index | next in thread | previous in thread | raw e-mail
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.help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-288778-18636-IOEV5kq8LH>
