public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/97965] New: constexpr evaluation vs. NaNs inconsistency @ 2020-11-24 10:21 jakub at gcc dot gnu.org 2020-11-24 21:39 ` [Bug c++/97965] " joseph at codesourcery dot com ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: jakub at gcc dot gnu.org @ 2020-11-24 10:21 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97965 Bug ID: 97965 Summary: constexpr evaluation vs. NaNs inconsistency Product: gcc Version: 11.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: --- constexpr bool a = __builtin_nan ("") > 0.0; constexpr bool b = __builtin_nans ("") > 0.0; constexpr bool c = __builtin_nan ("") < 0.0; constexpr bool d = __builtin_nans ("") < 0.0; strangely accepts the < 0.0 comparisons and rejects the > 0.0 comparisons. clang++ accepts all of them. IMHO either we should accept all of them, or just the ones not involving SNaNs, or reject all of them, it is unclear what exceptions appart from division by zero (and does that apply to floating point?) should cause constexpr evaluation to fail (I'd hope inexact exception doesn't count, another question is underflow/overflow, another one is invalid operations that from non-NaN operands create NaN, another one are operations with NaNs, another one are operations with SNaNs). Seems the reason why < 0.0 is accepted is fold_binary_loc uses tree_expr_nonnegative_warnv_p on the NaN REAL_CST which in the end uses tree_single_nonnegative_warnv_p which uses !REAL_VALUE_NEGATIVE. While NaNs have a sign in the representation, it shouldn't affect behavior of the comparisons, so I think we should never treat NaNs with the sign bit clear as non-negative. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97965] constexpr evaluation vs. NaNs inconsistency 2020-11-24 10:21 [Bug c++/97965] New: constexpr evaluation vs. NaNs inconsistency jakub at gcc dot gnu.org @ 2020-11-24 21:39 ` joseph at codesourcery dot com 2020-12-08 18:47 ` jason at gcc dot gnu.org 2020-12-08 19:02 ` jakub at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: joseph at codesourcery dot com @ 2020-11-24 21:39 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97965 --- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> --- I don't think there should be any difference between quiet and signaling NaNs here, since < <= > >= comparisons with either kind of NaN raise "invalid"; it's == != (and the __builtin_is* comparisons) that only raise exceptions for signaling NaN but not quiet. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97965] constexpr evaluation vs. NaNs inconsistency 2020-11-24 10:21 [Bug c++/97965] New: constexpr evaluation vs. NaNs inconsistency jakub at gcc dot gnu.org 2020-11-24 21:39 ` [Bug c++/97965] " joseph at codesourcery dot com @ 2020-12-08 18:47 ` jason at gcc dot gnu.org 2020-12-08 19:02 ` jakub at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: jason at gcc dot gnu.org @ 2020-12-08 18:47 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97965 --- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> --- See also PR88683 and PR88173. I notice that the match.pd REAL_CST patterns starting around line 4045 only look at the RHS of the comparison, so that nan > inf is handled very differently from inf < nan. And tree_swap_operands_p doesn't swap them around to make it work properly. #define inf __builtin_huge_val() #define nan __builtin_nan("") constexpr bool b1 = inf > nan; constexpr bool b2 = nan < inf; ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97965] constexpr evaluation vs. NaNs inconsistency 2020-11-24 10:21 [Bug c++/97965] New: constexpr evaluation vs. NaNs inconsistency jakub at gcc dot gnu.org 2020-11-24 21:39 ` [Bug c++/97965] " joseph at codesourcery dot com 2020-12-08 18:47 ` jason at gcc dot gnu.org @ 2020-12-08 19:02 ` jakub at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: jakub at gcc dot gnu.org @ 2020-12-08 19:02 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97965 --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560463.html https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560515.html are some mails on the topic. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-12-08 19:02 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-11-24 10:21 [Bug c++/97965] New: constexpr evaluation vs. NaNs inconsistency jakub at gcc dot gnu.org 2020-11-24 21:39 ` [Bug c++/97965] " joseph at codesourcery dot com 2020-12-08 18:47 ` jason at gcc dot gnu.org 2020-12-08 19:02 ` jakub at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).