public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag
@ 2023-08-18  7:18 xry111 at gcc dot gnu.org
  2023-08-18  7:24 ` [Bug c/111058] __builtin_nans (and its friends for other floating-point types) " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-08-18  7:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111058

            Bug ID: 111058
           Summary: __builtin_nans (and its friends) compiles to an
                    external call to __builtin_nans for unsupported tag
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xry111 at gcc dot gnu.org
  Target Milestone: ---

double test(void)
{
        return __builtin_nans("xxx");
}

compiles to:

test:
.LFB0:
        .cfi_startproc
        leaq    .LC0(%rip), %rdi
        jmp     __builtin_nans@PLT
        .cfi_endproc

We should refer to "nans" instead of "__builtin_nans" in the generated code. 
Though nans does not exist in libm for now, it may be added into a future libm
version or the user can provide their own nans implementation.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/111058] __builtin_nans (and its friends for other floating-point types) compiles to an external call to __builtin_nans for unsupported tag
  2023-08-18  7:18 [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag xry111 at gcc dot gnu.org
@ 2023-08-18  7:24 ` pinskia at gcc dot gnu.org
  2023-08-18  8:18 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-18  7:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111058

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-08-18
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fnan
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm

.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/111058] __builtin_nans (and its friends for other floating-point types) compiles to an external call to __builtin_nans for unsupported tag
  2023-08-18  7:18 [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag xry111 at gcc dot gnu.org
  2023-08-18  7:24 ` [Bug c/111058] __builtin_nans (and its friends for other floating-point types) " pinskia at gcc dot gnu.org
@ 2023-08-18  8:18 ` pinskia at gcc dot gnu.org
  2023-08-18  8:34 ` chenxiaolong at loongson dot cn
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-18  8:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111058

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Newer version of that paper:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1011.htm

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/111058] __builtin_nans (and its friends for other floating-point types) compiles to an external call to __builtin_nans for unsupported tag
  2023-08-18  7:18 [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag xry111 at gcc dot gnu.org
  2023-08-18  7:24 ` [Bug c/111058] __builtin_nans (and its friends for other floating-point types) " pinskia at gcc dot gnu.org
  2023-08-18  8:18 ` pinskia at gcc dot gnu.org
@ 2023-08-18  8:34 ` chenxiaolong at loongson dot cn
  2023-08-18  8:44 ` chenxiaolong at loongson dot cn
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: chenxiaolong at loongson dot cn @ 2023-08-18  8:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111058

chenxiaolong <chenxiaolong at loongson dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chenxiaolong at loongson dot cn

--- Comment #3 from chenxiaolong <chenxiaolong at loongson dot cn> ---
//test.c
#include<stdio.h>

int main(void)
{
        _Float128 ret=__builtin_nansf128("NAN");
        printf("ret=%Lf\n",ret);

        return 0;       
}       
Compile command: gcc test.c -s -o -
result:

x86_64:
        ...
        movl    $.LC0, %edi
        call    __builtin_nansf128
        ... 
LoongArch:

       la.local $r4,.LC0
        bl      %plt(__builtin_nansf128)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/111058] __builtin_nans (and its friends for other floating-point types) compiles to an external call to __builtin_nans for unsupported tag
  2023-08-18  7:18 [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag xry111 at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-08-18  8:34 ` chenxiaolong at loongson dot cn
@ 2023-08-18  8:44 ` chenxiaolong at loongson dot cn
  2023-08-18 13:29 ` joseph at codesourcery dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: chenxiaolong at loongson dot cn @ 2023-08-18  8:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111058

--- Comment #4 from chenxiaolong <chenxiaolong at loongson dot cn> ---
(In reply to chenxiaolong from comment #3)
> //test.c
> #include<stdio.h>
> 
> int main(void)
> {
> 	_Float128 ret=__builtin_nansf128("NAN");
> 	printf("ret=%Lf\n",ret);
> 	
> 	return 0;	
> }	
> Compile command: gcc test.c -s -o -
> result:
> 
> x86_64:
>         ...
>      	movl	$.LC0, %edi
> 	call	__builtin_nansf128
>         ... 
> LoongArch:
>  
>        la.local	$r4,.LC0
> 	bl	%plt(__builtin_nansf128)

Compile command: gcc test.c -S -o -

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/111058] __builtin_nans (and its friends for other floating-point types) compiles to an external call to __builtin_nans for unsupported tag
  2023-08-18  7:18 [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag xry111 at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-08-18  8:44 ` chenxiaolong at loongson dot cn
@ 2023-08-18 13:29 ` joseph at codesourcery dot com
  2023-08-18 13:34 ` xry111 at gcc dot gnu.org
  2023-08-18 18:19 ` joseph at codesourcery dot com
  6 siblings, 0 replies; 8+ messages in thread
From: joseph at codesourcery dot com @ 2023-08-18 13:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111058

--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
We should absolutely *not* generate calls to a non-existent function 
"nans" based on a long-obsolescent standard proposal.  The modern way to 
generate a signaling NaN with given payload, as specified in C23, is to 
generate a signaling NaN with one of the *_SNAN macros (FLT128_SNAN in 
this case) in <float.h>, then use the relevant setpayload function 
(setpayloadf128 in this case) to set its payload.

I don't think there is any bug here at all.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/111058] __builtin_nans (and its friends for other floating-point types) compiles to an external call to __builtin_nans for unsupported tag
  2023-08-18  7:18 [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag xry111 at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-08-18 13:29 ` joseph at codesourcery dot com
@ 2023-08-18 13:34 ` xry111 at gcc dot gnu.org
  2023-08-18 18:19 ` joseph at codesourcery dot com
  6 siblings, 0 replies; 8+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-08-18 13:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111058

--- Comment #6 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to joseph@codesourcery.com from comment #5)
> We should absolutely *not* generate calls to a non-existent function 
> "nans" based on a long-obsolescent standard proposal.  The modern way to 
> generate a signaling NaN with given payload, as specified in C23, is to 
> generate a signaling NaN with one of the *_SNAN macros (FLT128_SNAN in 
> this case) in <float.h>, then use the relevant setpayload function 
> (setpayloadf128 in this case) to set its payload.
> 
> I don't think there is any bug here at all.

But generating an external call to __builtin_* just does not make sense at all.

If the payload won't be supported, we should just emit a diagnostic and reject
the code.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c/111058] __builtin_nans (and its friends for other floating-point types) compiles to an external call to __builtin_nans for unsupported tag
  2023-08-18  7:18 [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag xry111 at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-08-18 13:34 ` xry111 at gcc dot gnu.org
@ 2023-08-18 18:19 ` joseph at codesourcery dot com
  6 siblings, 0 replies; 8+ messages in thread
From: joseph at codesourcery dot com @ 2023-08-18 18:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111058

--- Comment #7 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
There shouldn't be such a thing as an unsupported constant payload; both 
__builtin_nan and __builtin_nans should rather be made consistent with 
parsing of payloads by glibc's nan functions (that may in some cases mean 
changing glibc; see https://sourceware.org/bugzilla/show_bug.cgi?id=28322 
- glibc's functions don't handle payloads wider than 64 bits for 
_Float128, but GCC's do).

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-08-18 18:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-18  7:18 [Bug c/111058] New: __builtin_nans (and its friends) compiles to an external call to __builtin_nans for unsupported tag xry111 at gcc dot gnu.org
2023-08-18  7:24 ` [Bug c/111058] __builtin_nans (and its friends for other floating-point types) " pinskia at gcc dot gnu.org
2023-08-18  8:18 ` pinskia at gcc dot gnu.org
2023-08-18  8:34 ` chenxiaolong at loongson dot cn
2023-08-18  8:44 ` chenxiaolong at loongson dot cn
2023-08-18 13:29 ` joseph at codesourcery dot com
2023-08-18 13:34 ` xry111 at gcc dot gnu.org
2023-08-18 18:19 ` joseph at codesourcery dot com

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).