This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Don't constant fold 1.0/0.0 at compile-time
Richard Henderson <rth@redhat.com> writes:
> On Tue, Jul 01, 2003 at 02:12:22AM -0600, Roger Sayle wrote:
> > ... hence code such as the initialized global variable in fp-cmp-1.c now
> > fail to compile:
> >
> > double dnan = 1.0/0.0 - 1.0/0.0;
>
> Ug.
>
> > Is there some mechanism that fold
> > can use to determine whether we're folding an initializer?
>
> No, but I think we can add one. Probably not to fold
> directly, as that would touch too much code, but to a
> new sister function.
>
> > Could one of the language lawyers post their opinions on "x = 1.0/0.0"?
>
> Not supported by a standard, per-se, but well entrenched as an idiom.
I believe that
- an expressions in a static initializer that causes an FP exception
triggers undefined behaviour
- in other initializers (of automatic variables) FP exceptions happen
as you'd expect from the abstract machine.
But, this is from memory, so I may be wrong.
--
- Geoffrey Keating <geoffk@geoffk.org>