comp.lang.ada
 help / color / mirror / Atom feed
From: Jerry <lanceboyle@qwest.net>
Subject: Re: GNAT does not consistently raise an exception to log(0.0)
Date: Sat, 13 Jul 2013 20:42:13 -0700 (PDT)
Date: 2013-07-13T20:42:13-07:00	[thread overview]
Message-ID: <970fccec-94b8-4ea9-9924-58fb011ca3f7@googlegroups.com> (raw)
In-Reply-To: <ly8v1avroz.fsf@pushface.org>

On Saturday, July 13, 2013 12:34:36 AM UTC-7, Simon Wright wrote:
> Jerry writes:
> 
> > $ gnatmake -f bomb_log.adb -OX
> >
> > then if X = 0 (zero) the expected exception is raised and reported thusly:
> >
> > raised CONSTRAINT_ERROR : a-ngelfu.adb:744 explicit raise
> >
> > else if X > 0 no exception is raised.
> >
> >
> > with Ada.Numerics.Long_Elementary_Functions; 
> > use  Ada.Numerics.Long_Elementary_Functions;
> > procedure Bomb_Log is
> >     x : Long_Float;
> > begin
> >     x := log(0.0);
> > end Bomb_Log;
> 
> If you compile with -gnatwa (most warnings), the report is
> 
>    bomb_log.adb:4:05: warning: variable "x" is assigned but never read
>    bomb_log.adb:6:05: warning: useless assignment to "x", value never referenced
> 
> and at -O1 or greater the compiler takes the opportunity to eliminate
> the call of log, because of
> 
>    pragma Pure (Long_Elementary_Functions);
> 
> so that the generated code (gnatmake -c -u -f -S bomb_log.adb) is
> 
>            .text
>            .globl __ada_bomb_log
>    __ada_bomb_log:
>    LFB1:
>            ret

Well, that nails it down, doesn't it.
Interestingly, if I change the program to have a second line with a seond variable y:

with Ada.Numerics.Long_Elementary_Functions; 
use  Ada.Numerics.Long_Elementary_Functions;
procedure Bomb_Log is
    x, y : Long_Float;
begin
    x := log(0.0);
    y := 2.0 * x;
end Bomb_Log;

there is no warning about "x" but the warnings are now about "y" being assigned but not read, and never being referenced. So the optimzizer still sniffs it out. And Constraint_Error is still raised or not raised in excactly the same conditions as in my original post.

> 
> If you change the code to
> 
>    procedure Bomb_Log is
>        x : Long_Float with Volatile;
>    begin
>        x := log(0.0);
>    end Bomb_Log;
> 
> (that's -gnat12, of course, use pragma Volatile (X); otherwise) then
> things work as you had expected:
> 
>            .text
>            .globl __ada_bomb_log
>    __ada_bomb_log:
>    LFB1:
>            subq    $24, %rsp
>    LCFI0:
>            xorpd   %xmm0, %xmm0
>            call    _ada__numerics__long_elementary_functions__log
>            movsd   %xmm0, 8(%rsp)
>            addq    $24, %rsp
>    LCFI1:
>            ret

I'll look into Volitile.

Jerry

  reply	other threads:[~2013-07-14  3:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-13  0:52 GNAT does not consistently raise an exception to log(0.0) Jerry
2013-07-13  1:47 ` Anh Vo
2013-07-13  2:12   ` Jerry
2013-07-13  2:28     ` Anh Vo
2013-07-13  3:33       ` Jerry
2013-07-14  3:28       ` Jerry
2013-07-14 13:35         ` Anh Vo
2013-07-15  8:25           ` Jerry
2013-07-13  7:26 ` Dmitry A. Kazakov
2013-07-14  3:34   ` Jerry
2013-07-14  3:51   ` Jerry
2013-07-13  7:34 ` Simon Wright
2013-07-14  3:42   ` Jerry [this message]
2013-07-13  9:37 ` AdaMagica
2013-07-14  3:44   ` Jerry
2013-07-15 17:16     ` AdaMagica
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox