[libc-commits] [libc] [libc] Workaround for gcc complaining about implicit conversions with the ternary ?: operator. (PR #124820)
via libc-commits
libc-commits at lists.llvm.org
Tue Jan 28 13:04:23 PST 2025
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/124820
>From c433cfc88ee09d1101b283d341f88f0ac50e9890 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 28 Jan 2025 18:52:08 +0000
Subject: [PATCH 1/2] [libc] Workaround for gcc complaining about implicit
conversions with the ternary ?: operator.
---
libc/src/__support/FPUtil/except_value_utils.h | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/libc/src/__support/FPUtil/except_value_utils.h b/libc/src/__support/FPUtil/except_value_utils.h
index f8e4e92d3e1fb3..2e58bf2b287fdf 100644
--- a/libc/src/__support/FPUtil/except_value_utils.h
+++ b/libc/src/__support/FPUtil/except_value_utils.h
@@ -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;
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;
>From 48a667c2bfb028802e663e9529b4bf582c3ec3f6 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 28 Jan 2025 21:02:58 +0000
Subject: [PATCH 2/2] Add comment about the root cause.
---
libc/src/__support/FPUtil/except_value_utils.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/src/__support/FPUtil/except_value_utils.h b/libc/src/__support/FPUtil/except_value_utils.h
index 2e58bf2b287fdf..5f767769974d29 100644
--- a/libc/src/__support/FPUtil/except_value_utils.h
+++ b/libc/src/__support/FPUtil/except_value_utils.h
@@ -87,6 +87,9 @@ template <typename T, size_t N> struct ExceptValues {
out_bits += values[i].rnd_upward_offset;
break;
case FE_DOWNWARD:
+ // Use conditionals instead of ternary operator to work around gcc's
+ // -Wconversion false positive bug:
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537
if (sign)
out_bits += values[i].rnd_upward_offset;
else
More information about the libc-commits
mailing list