Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] Workaround for gcc complaining about implicit conversions with the ternary ?: operator. #124820

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions libc/src/__support/FPUtil/except_value_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ template <typename T, size_t N> struct ExceptValues {
StorageType out_bits = values[i].rnd_towardzero_result;
switch (fputil::quick_get_round()) {
case FE_UPWARD:
out_bits += sign ? values[i].rnd_downward_offset
: values[i].rnd_upward_offset;
if (sign)
out_bits += values[i].rnd_downward_offset;
else
out_bits += values[i].rnd_upward_offset;
Comment on lines +84 to +87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537, I think you can keep the ternary, and instead work around this as such:

Suggested change
if (sign)
out_bits += values[i].rnd_downward_offset;
else
out_bits += values[i].rnd_upward_offset;
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537
out_bits = out_bits + (sign ? values[i].rnd_downward_offset : values[i].rnd_upward_offset);

ah, but that's not much more readable. Please cite https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537 in either a comment in the sources and/or the PR description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding the root cause of it! I updated the comments.

break;
case FE_DOWNWARD:
out_bits += sign ? values[i].rnd_upward_offset
: values[i].rnd_downward_offset;
if (sign)
out_bits += values[i].rnd_upward_offset;
else
out_bits += values[i].rnd_downward_offset;
break;
case FE_TONEAREST:
out_bits += values[i].rnd_tonearest_offset;
Expand Down