From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.23]) by sourceware.org (Postfix) with ESMTPS id 74C9E3858C53 for ; Wed, 25 Oct 2023 09:21:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74C9E3858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=clisp.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=clisp.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 74C9E3858C53 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=85.215.255.23 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1698225711; cv=pass; b=juSBOk9/TK9GXqtuVCbF4HS4xldo9ZM/5mBO9Je7EA5+F54YUKClUiuB7+aH1uvfHXQ2QfcmlyRjYNVT29cst7NLkNpy7wByDQfNgOr1QayglFkSoOo1L7PpGkTt1wIQkWt04bhpR8OS7g50fqDxb0dyZvX2uS+4I35LjqVVvn8= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1698225711; c=relaxed/simple; bh=7wTs6eUCRzHeZZJAoReAt8sfYvS/qtx9/E7HACj3M8s=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=LSpMfMUWPbAqbQaRTEC1iTbWSPypPYrLHdUvsnn7TkwVAa2jo9TZPOuVWu1J6JtlMd4aT4LiasDl0z/E5OU/WorCvKylauBxmjq/Ocx5Ed290bGc5K7WN7S0DkICOEVqcM5Q9V3VlKNtmfUhATnCe7F7WqK4mMvEvLNG7dZcOns= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1698225707; cv=none; d=strato.com; s=strato-dkim-0002; b=PBaXF08pTVaYr4TVkVahyMVayrjnXIyo0RL9l5GruEw1EyT+gWXGBRU9IZCmYotFw3 XHYIg2VhP628hbENkj6DCojTA8IwXtB0iI31aa8t++p01hXw/4JEeUDonzaLBK4LaB5+ QtfkH6GaWCBkrhY1mMAJgkfZoHeOBRqc8OYYHsUK3dy7SSccRmIPoi74aPYnkPu+y70m tkRqwCuTauKOHVuWuAfN1Ao08dz4Sy4+XQTtSRfEBFGJfj9LhsdfZ9VZRjHaFYcTyqZn bGQ8rm92Vx4+hFM/chcueCGKwD1GWurmPWXJoXT9Yz+N31xY4mmgKg4CjMSr/M0asz8D ppTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1698225707; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=4l9d1n+VpxUigEntbdKpS1bVuHv6+1dOky+Z/e//AUU=; b=AhhEt/Hw1qBSqAbC8/gbA6WYaoZJfrlQ5NDqaXG6FAgnzMMWh6ihoVXXOKYWi+yme6 W+AVKotPNTAv4x6JNELEQ7nU67FEKMTTB+KbVfrFjhiWRMsaD9hkRxoK69rcIwGAUuF8 AgXdxA4+KfpibNjT0RCDYmBmvU1RlI6MR9gfO7//NM2YPtNRgL9JYwwFdx/JIuIrLAlt MtVJtXzVrVVbIqvfkK035RDPly6sdsQIMubKn1H+O/0PUEv/AD9jVpvejKvMIuMZ6gxY kYJhsamDZTOP6vD4/lVZxo54Kdkuz53rKdIONstS6fc2LLvm4W/1hKtpb6a1auFtmWie j09w== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1698225707; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=4l9d1n+VpxUigEntbdKpS1bVuHv6+1dOky+Z/e//AUU=; b=lRkbz5wgOPnyhsyNEmHzJmdv0J9JyOFwnSNRf1fI8OSS5O6lBEiTKFRTp3bN6xpZlF 5goiqMtZ4Z+iZrPsjYggZxAY0dd+6clROodhP/MU4WsWE8eguF3ehp60P+6uXvUZIoyj T2CQLly9CqFfOupZm/PDTb8YG1mqcN2sS9znjtfJJAstoSZRqG5DxGCdKPmvCjwd+khd v594SmUvn/1h1sBvWcpEhtc5sj2eDS9b5ZHNoybG9vUIIKHs2RS9ZOFc9mTuIEySyt8L c1F2OYoKCs/e14j6pRClJAsDuBlkcfjinflurnq6iaR5frbrAh5wmk1ZhiGeDGcp5CuF BvZQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1698225707; s=strato-dkim-0003; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=4l9d1n+VpxUigEntbdKpS1bVuHv6+1dOky+Z/e//AUU=; b=Br7msni/6QwN9U0kbFdh0DjQJiU9LGPfSxb/Uc1IpFJD36b5/oG8C1UHUD0eP0fEKy l3BH0YQ2wxrut/eiLwAQ== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpOQjaEBbGRPJOsIn/JZIZXFBU8r/A==" Received: from nimes.localnet by smtp.strato.de (RZmta 49.9.0 AUTH) with ESMTPSA id Y1a68az9P9LlpEu (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 25 Oct 2023 11:21:47 +0200 (CEST) From: Bruno Haible To: cygwin@cygwin.com Subject: feraiseexcept does not raise traps in Cygwin Date: Wed, 25 Oct 2023 11:21:47 +0200 Message-ID: <39807966.XM6RcZxFsP@nimes> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, Seen on - Cygwin 3.4.6 or 2.9.0 on x86_64. - Cygwin 2.9.0 on i386. According to ISO C 23 =A7 7.6.4.3 "The feraiseexcept function attempts to raise the supported floating-point exceptions represented by its argument. 266) Footnote 266) The effect is intended to be similar to that of floating-p= oint exceptions raised by arithmetic operations. Hence, implementation extens= ions associated with raising a floating-point exception (for example, enabled traps or IEC 60559 alternate exception handling) should be honored." This does not work. How to reproduce: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D foo.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D #define _GNU_SOURCE 1 #include #include int main () { /* Clear FE_INVALID exceptions from past operations. */ if (feclearexcept (FE_INVALID)) return 1; /* An FE_INVALID exception shall trigger a SIGFPE signal, which by default terminates the program. */ if (feenableexcept (FE_INVALID) =3D=3D -1) return 2; if (feraiseexcept (FE_INVALID)) return 3; return 0; } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D =46or x86_64: $ x86_64-pc-cygwin-gcc -Wall foo.c $ ./a.exe; echo $? =46or i386: $ i686-pc-cygwin-gcc -Wall foo.c $ ./a.exe; echo $? Expected result (like seen e.g. on Linux/glibc): =46loating-point exception (core dumped) 136 Actual result: 0 The workaround for x86_64 is to redefine feeraiseexcept in the same way as glibc does. This modified test program includes the workaround: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D foo.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D #define _GNU_SOURCE 1 #include #include /* The floating-point environment of the 387 unit. */ typedef struct { /* 7 32-bit words: */ unsigned short __control_word; /* fctrl register */ unsigned short __reserved1; unsigned short __status_word; /* fstat register */ unsigned short __reserved2; unsigned int more[5]; } x86_387_fenv_t; int feraiseexcept (int exceptions) { exceptions &=3D FE_ALL_EXCEPT; if ((exceptions & ~(FE_INVALID | FE_DIVBYZERO)) =3D=3D 0 && 0) { /* First: invalid exception. */ if (exceptions & FE_INVALID) { double volatile a; double volatile b; a =3D 0; b =3D a / a; (void) b; } /* Next: division by zero. */ if (exceptions & FE_DIVBYZERO) { double volatile a, b; double volatile c; a =3D 1; b =3D 0; c =3D a / b; (void) c; } } else { /* The general case. */ /* Set the bits in the 387 unit. */ x86_387_fenv_t env; unsigned short orig_status_word; __asm__ __volatile__ ("fnstenv %0" : "=3Dm" (*&env)); orig_status_word =3D env.__status_word; env.__status_word |=3D exceptions; if (env.__status_word !=3D orig_status_word) { __asm__ __volatile__ ("fldenv %0" : : "m" (*&env)); /* A trap (if enabled) is triggered only at the next floating-poi= nt instruction. Force it to occur here. */ __asm__ __volatile__ ("fwait"); } } return 0; } int main () { /* Clear FE_INVALID exceptions from past operations. */ if (feclearexcept (FE_INVALID)) return 1; /* An FE_INVALID exception shall trigger a SIGFPE signal, which by default terminates the program. */ if (feenableexcept (FE_INVALID) =3D=3D -1) return 2; if (feraiseexcept (FE_INVALID)) return 3; return 0; } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D (This workaround *should* also work on i386, but it doesn't. I don't know why.) Bruno