libm: fix truncl when long double has same size as double#18480
Draft
Cynerd wants to merge 1 commit intoapache:masterfrom
Draft
libm: fix truncl when long double has same size as double#18480Cynerd wants to merge 1 commit intoapache:masterfrom
Cynerd wants to merge 1 commit intoapache:masterfrom
Conversation
The truncl implementation expects 80 bit little endian representation of
the floating point number. That is valid for x86 but not for example
arm. On arm long double is the same as double.
This was discovered with newer version of GCC (15.2.0) that started
emitting warning:
libm/lib_truncl.c: In function 'truncl':
libm/lib_truncl.c:68:14: error: 'u.i.se' is used uninitialized [-Werror=uninitialized]
68 | int e = u.i.se & 0x7fff;
| ~~~^~~
libm/lib_truncl.c:63:17: note: 'u' declared here
63 | union ldshape u =
| ^
libm/lib_truncl.c:69:14: error: 'u.i.se' is used uninitialized [-Werror=uninitialized]
69 | int s = u.i.se >> 15;
| ~~~^~~
libm/lib_truncl.c:63:17: note: 'u' declared here
63 | union ldshape u =
| ^
libm/lib_truncl.c:63:17: error: 'u.i.se' is used uninitialized [-Werror=uninitialized]
Signed-off-by: Karel Kočí <cynerd@email.cz>
Contributor
Author
|
I just tested it with x86 and the condition is wrong because https://github.com/apache/nuttx/blob/master/include/nuttx/lib/float.h#L67 ... ups |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The truncl implementation expects 80 bit little endian representation of the floating point number. That is valid for x86 but not for example arm. On arm long double is the same as double.
This was discovered with newer version of GCC (15.2.0) that started emitting warning:
Impact
This is technically a fix for
trunclon platforms that havelong doubleof the same size asdouble, as the logic was correct only for 80 bit float.Testing
The testing was performed only by compilation, as the implementation just redirects to the
truncinstead. The warning disappeared with the changes made in this PR.