[llvm-dev] PR43374 - when should comparing NaN values raise a floating point exception?
John Brawn via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 8 07:25:33 PDT 2019
> this is observably non-iso c conform so clang miscompiles
> math libraries written in c (math functions are required
> to report errors by signaling floating-point exceptions).
In both C99 and C11, IEEE 754 support (or rather IEC 60559 as it calls it)
is described in annex F, and is optional. Clang doesn't support annex F,
and so doesn't define __STDC_IEC_559__.
So yes, clang may miscompile code that relies on IEEE 754 behaviour (as
described in C99/C11 annex F). This means it cannot be used to reliably
compile math libraries that report errors by exceptions (e.g.
implementations of math.h functions where math_errhandling is set to
MATH_ERREXCEPT).
John
> -----Original Message-----
> From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of
> Szabolcs Nagy via llvm-dev
> Sent: 08 October 2019 14:55
> To: Sanjay Patel
> Cc: llvm-dev; nd
> Subject: Re: [llvm-dev] PR43374 - when should comparing NaN values raise
> a floating point exception?
>
> * Sanjay Patel <spatel at rotateright.com> [2019-10-08 09:03:53 -0400]:
> > On Tue, Oct 8, 2019 at 8:44 AM Szabolcs Nagy <nsz at port70.net> wrote:
> >
> > > * Sanjay Patel <spatel at rotateright.com> [2019-10-08 08:07:10 -0400]:
> > > > On Tue, Oct 8, 2019 at 7:08 AM Szabolcs Nagy <nsz at port70.net>
> wrote:
> > > > > why is that ok?
> > > > >
> > > >
> > > > Because there are no FP exceptions/signals for this IR opcode:
> > > > http://llvm.org/docs/LangRef.html#floating-point-environment
> > >
> > > so llvm cannot support an iso c frontend on an ieee754 target?
> > > (or fortran for that matter)
> > >
> >
> > Not sure. I thought we solved the problems for all of the examples
> given so
> > far.
> > Do you have an end-to-end (C source to asm) example that shows a bug?
> > Please cite the C language law that is violated (add cfe-dev if
> there's a
> > front-end bug?).
>
> anything that should observably raise a floating-point exception
> does not work if llvm only provides silent operations or ignores
> fenv side-effects during lowering, e.g.
>
> #pragma STDC FENV_ACCESS ON
> int cmp(float x, float y)
> {
> return x < y;
> }
>
> is lowered to fcmp olt which you say should be silent:
>
> define dso_local i32 @cmp(float %0, float %1) #0 {
> %3 = alloca float, align 4
> %4 = alloca float, align 4
> store float %0, float* %3, align 4
> store float %1, float* %4, align 4
> %5 = load float, float* %3, align 4
> %6 = load float, float* %4, align 4
> %7 = fcmp olt float %5, %6
> %8 = zext i1 %7 to i32
> ret i32 %8
> }
>
> this is observably non-iso c conform so clang miscompiles
> math libraries written in c (math functions are required
> to report errors by signaling floating-point exceptions).
>
> it also does not support snan, but that's not strictly
> required by iso c.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list