public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: Agner Fog <agner@agner.org>
Cc: cygwin@cygwin.com
Subject: Re: Bug report. Clang sqrtl(-1) causes access violation
Date: Mon, 03 Jun 2019 11:11:00 -0000	[thread overview]
Message-ID: <20190603111057.GE3437@calimero.vinschen.de> (raw)
In-Reply-To: <c80240c2-a30e-41b5-7635-cf31f54741d1@agner.org>

[-- Attachment #1: Type: text/plain, Size: 2279 bytes --]

On May 10 14:57, Agner Fog wrote:
> Bug description:
> 
> The sqrtl function under Clang causes an access violation when the argument
> is negative.
> 
> This error occurs only under Cygwin.
> 
> This error occurs only with the sqrtl function, not with sqrt or sqrtf
> 
> Attached:
> 
> sqrt.cpp: program to reproduce the error. Compile clang sqrt.cpp and run
> ./a.exe

Thanks for the testcase.

This looks like a bug in clang-5.0.  It does not occur when building the
testcase with gcc, nor does it occur when building with clang-4.0.

Looking with GDB, it seems the conversion from float to long double is
screwed up.  The sequence converting float to long double prior to
calling sqrtl is very different:

With gcc:

  Thread 1 "sqrtl" hit Temporary breakpoint 1, main () at sqrtl.c:6
  6           float b = sqrtl(a);
  (gdb) s
  sqrtl (x=-1)
      at /home/corinna/src/cygwin/vanilla/winsup/cygwin/math/sqrt.def.h:69
  69        __FLT_TYPE res = __FLT_CST (0.0);
  (gdb) n
  70        int x_class = fpclassify (x);
  (gdb) p x
  $1 = -1
  (gdb) x/4x &x
  0xffffcaf0:     0x00000000      0x80000000      0x0004bfff      0x00000006

  => 0x100401093 <main+19>:       lea    -0x20(%rbp),%rax
  => 0x100401097 <main+23>:       fstpt  -0x30(%rbp)
  => 0x10040109a <main+26>:       lea    -0x30(%rbp),%rdx
  => 0x10040109e <main+30>:       mov    %rax,%rcx
  => 0x1004010a1 <main+33>:       callq  0x100401110 <sqrtl>

With clang:

  Thread 1 "sqrtl" hit Temporary breakpoint 1, main () at sqrtl.c:6
  6           float b = sqrtl(a);
  (gdb) s
  sqrtl (x=<invalid float value>)
      at /home/corinna/src/cygwin/vanilla/winsup/cygwin/math/sqrt.def.h:69
  69        __FLT_TYPE res = __FLT_CST (0.0);
  (gdb) n
  70        int x_class = fpclassify (x);
  (gdb) p x
  $1 = <invalid float value>
  (gdb) x/4x &x
  0xffffcb10:     0x00000000      0x00000000      0x00040524      0x00000006

  => 0x100401096 <main+22>:       movabs $0x100402010,%rax
  => 0x1004010a0 <main+32>:       flds   (%rax)
  => 0x1004010a2 <main+34>:       mov    %rsp,%rax
  => 0x1004010a5 <main+37>:       fstpt  0x20(%rax)
  => 0x1004010a8 <main+40>:       callq  0x100401120 <sqrtl>


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2019-06-03 11:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-10 12:58 Agner Fog
2019-05-10 13:38 ` Sam Habiel
2019-05-10 14:04   ` Franz Fehringer
2019-05-10 13:50 ` Jose Isaias Cabrera
2019-05-10 19:44   ` Agner Fog
2019-05-10 19:54     ` Jose Isaias Cabrera
2019-05-10 20:56       ` Agner Fog
2019-05-11  3:33         ` Jose Isaias Cabrera
2019-06-03 11:11 ` Corinna Vinschen [this message]

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=20190603111057.GE3437@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=agner@agner.org \
    --cc=cygwin@cygwin.com \
    /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).