comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: GNAT does not consistently raise an exception to log(0.0)
Date: Sat, 13 Jul 2013 08:34:36 +0100
Date: 2013-07-13T08:34:36+01:00	[thread overview]
Message-ID: <ly8v1avroz.fsf@pushface.org> (raw)
In-Reply-To: 74c64a2c-f062-4b59-aafb-40c0bac39203@googlegroups.com

Jerry <lanceboyle@qwest.net> 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

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

  parent reply	other threads:[~2013-07-13  7:34 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 [this message]
2013-07-14  3:42   ` Jerry
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