public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* FPE_FLTSUB where FLT_FLTINV is expected
@ 2018-06-26 10:33 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2018-06-26 14:18 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2018-06-26 10:33 UTC (permalink / raw)
  To: cygwin

Hello,

The following code produces FPE_FLTSUB(22) for the signal code whereas all platforms (Linux, Mac, FreeBSD) where I tested it, consistently yield FPE_FLTINV
(which on CYGWIN has a value of 21):

#define _GNU_SOURCE
#include <fenv.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

void sigfpe(int signo, siginfo_t* si, void* ucontext)
{
    printf("code = %d\n", si->si_code);
    _exit(255);
}

int main()
{
    double a = 0, b = 0;
    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_sigaction = sigfpe;
    sa.sa_flags = SA_SIGINFO;
    sigaction(SIGFPE, &sa, 0);
    feenableexcept(FE_ALL_EXCEPT);
    printf("%lf", a / b);
    return 0;
}

I suppose that this block of code in exceptions.cc is not particularly correct, and only the last case (STACK_CHECK) actually pertains to the FLTSUB situation,
while all previous labels should be redirected to FPE_FLTINV (which, BTW, seems not being used at all in CYGWIN):

    case STATUS_FLOAT_DENORMAL_OPERAND:
    case STATUS_FLOAT_DIVIDE_BY_ZERO:
    case STATUS_FLOAT_INVALID_OPERATION:
    case STATUS_FLOAT_STACK_CHECK:
      si.si_signo = SIGFPE;
      si.si_code = FPE_FLTSUB;
      break;

Thanks for looking into this!

Regards,

Anton Lavrentiev
Contractor NIH/NLM/NCBI


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: FPE_FLTSUB where FLT_FLTINV is expected
  2018-06-26 10:33 FPE_FLTSUB where FLT_FLTINV is expected Lavrentiev, Anton (NIH/NLM/NCBI) [C]
@ 2018-06-26 14:18 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2018-06-26 14:18 UTC (permalink / raw)
  To: cygwin

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

On Jun 25 20:51, Lavrentiev, Anton (NIH/NLM/NCBI) [C] wrote:
> Hello,
> 
> The following code produces FPE_FLTSUB(22) for the signal code whereas all platforms (Linux, Mac, FreeBSD) where I tested it, consistently yield FPE_FLTINV
> (which on CYGWIN has a value of 21):
> 
> #define _GNU_SOURCE
> #include <fenv.h>
> #include <signal.h>
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h>
> 
> void sigfpe(int signo, siginfo_t* si, void* ucontext)
> {
>     printf("code = %d\n", si->si_code);
>     _exit(255);
> }
> 
> int main()
> {
>     double a = 0, b = 0;
>     struct sigaction sa;
>     memset(&sa, 0, sizeof(sa));
>     sa.sa_sigaction = sigfpe;
>     sa.sa_flags = SA_SIGINFO;
>     sigaction(SIGFPE, &sa, 0);
>     feenableexcept(FE_ALL_EXCEPT);
>     printf("%lf", a / b);
>     return 0;
> }
> 
> I suppose that this block of code in exceptions.cc is not particularly correct, and only the last case (STACK_CHECK) actually pertains to the FLTSUB situation,
> while all previous labels should be redirected to FPE_FLTINV (which, BTW, seems not being used at all in CYGWIN):
> 
>     case STATUS_FLOAT_DENORMAL_OPERAND:
>     case STATUS_FLOAT_DIVIDE_BY_ZERO:
>     case STATUS_FLOAT_INVALID_OPERATION:
>     case STATUS_FLOAT_STACK_CHECK:
>       si.si_signo = SIGFPE;
>       si.si_code = FPE_FLTSUB;
>       break;
> 
> Thanks for looking into this!

Thanks for the testcase!  I pushed a patch.  Expect new devloper
snapshots on https://cygwin.com/snapshots later today.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

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

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

end of thread, other threads:[~2018-06-26  8:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-26 10:33 FPE_FLTSUB where FLT_FLTINV is expected Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2018-06-26 14:18 ` Corinna Vinschen

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