[Bug c/110656] New: Floating point to char/short or bitfield conversions
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jul 13 12:41:02 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110656
Bug ID: 110656
Summary: Floating point to char/short or bitfield conversions
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
While implementing floating point to _BitInt convertions, I'm wondering if it
is correct that we implement say float -> signed char conversion effectively as
float -> int -> signed char.
signed char foo (float x) { return x; }
with foo (512.0f).
ISO C17 has in F.4 says
"or if the integral part of the floating value
exceeds the range of the integer type, then the “invalid” floating-point
exception is raised and the resulting value is unspecified."
but we even with -ftrapping-math trigger invalid say for 8589934592.0f (when it
doesn't fit into int), but the above just does
cvttss2sil %xmm0, %eax
movsbl %al, %eax
on x86_64.
In the scope of _BitInt, I wonder if I should care, i.e. whether I should call
say a library routine for floating point to _BitInt(N)/unsigned _BitInt(N)
conversions when
N is smaller than bit width of __int128 (if it exists, long long otherwise) and
is not equal to width of int, long or long long, or if I can implement those
like it is implemented for char/short and bitfields.
I guess for now I'll try to implement the library side so that it handles
correctly all valid Ns and we can decide on the compiler side later.
More information about the Gcc-bugs
mailing list