public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "fantasquex at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug build/29501] Check failed on stdlib/tst-strfrom while building for RISCV64 on a unmatched hardware
Date: Thu, 15 Sep 2022 16:11:56 +0000	[thread overview]
Message-ID: <bug-29501-131-rZ04Z7CfmZ@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-29501-131@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=29501

--- Comment #7 from Letu Ren <fantasquex at gmail dot com> ---
The root cause is that in function STRFROM of stdlib/strfrom-skeleton.c

```c
/* Single-precision values need to be stored in a double type, because
   __printf_fp_l and __printf_fphex do not accept the float type.  */
union {
  double flt;
  FLOAT value;
} fpnum;
const void *fpptr;
fpptr = &fpnum;

/* Single-precision values need to be converted into double-precision,
   because __printf_fp and __printf_fphex only accept double and long double
   as the floating-point argument.  */
if (__builtin_types_compatible_p (FLOAT, float))
  fpnum.flt = f;
else
  fpnum.value = f;
```


argument f with type float is converted to double in the beginning. On riscv64,
-NAN with type float doesn't keep signbit when it is converted to double. That
is why this testcase only fails with strfromf.

I have confirmed that if the signbit is kept, the testcase will pass.

I'm really curious why the implementation converts the argument to double in
the beginning and look through ISO/IEC TS 18661-1:2014.

> The strfromd, strfromf, and strfroml functions are equivalent to snprintf(s, n, format, fp) (7.21.6.5), except the format string contains only the character	 %, an optional precision that does not contain an asterisk *, and one of the conversion specifiers a, A, e, E, f, F,	g, or G, which applies to the type (double, float,	or long double)	indicated by the function suffix (rather than  by a length modifier). Use of these functions with any other 20 format string results	in undefined behavior.

Since `snprintf` doesn't consume an argument with type double, there must be a
conversion from float to double. According to spec of IEEE 754 and RISCV-ISA
manual, all these behaviors are reasonable. The signbit of NAN doesn't matter.

I understand what you mean a hook. Get the signbit of the argument, copy the
value and also copy the signbit explicitly. As I mentioned before, all current
behaviors are reasonable according to the spec. I really doubt whether we
should add such a hook to resolve a problem which shouldn't be a problem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2022-09-15 16:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-29501-131@http.sourceware.org/bugzilla/>
2022-09-11 15:34 ` fantasquex at gmail dot com
2022-09-12 17:39 ` joseph at codesourcery dot com
2022-09-15 16:11 ` fantasquex at gmail dot com [this message]
2022-10-28 14:49 ` cvs-commit at gcc dot gnu.org
2022-10-28 16:35 ` adhemerval.zanella at linaro dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-29501-131-rZ04Z7CfmZ@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).