From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.86.200 with SMTP id t8mr56008453qal.0.1373773333641; Sat, 13 Jul 2013 20:42:13 -0700 (PDT) X-Received: by 10.50.57.112 with SMTP id h16mr534863igq.5.1373773333594; Sat, 13 Jul 2013 20:42:13 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!t19no1440859qam.0!news-out.google.com!f7ni2314qai.0!nntp.google.com!t19no1534287qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 13 Jul 2013 20:42:13 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=97.117.199.112; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG NNTP-Posting-Host: 97.117.199.112 References: <74c64a2c-f062-4b59-aafb-40c0bac39203@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <970fccec-94b8-4ea9-9924-58fb011ca3f7@googlegroups.com> Subject: Re: GNAT does not consistently raise an exception to log(0.0) From: Jerry Injection-Date: Sun, 14 Jul 2013 03:42:13 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3608 Xref: news.eternal-september.org comp.lang.ada:16348 Date: 2013-07-13T20:42:13-07:00 List-Id: On Saturday, July 13, 2013 12:34:36 AM UTC-7, Simon Wright wrote: > Jerry writes: >=20 > > $ gnatmake -f bomb_log.adb -OX > > > > then if X =3D 0 (zero) the expected exception is raised and reported th= usly: > > > > raised CONSTRAINT_ERROR : a-ngelfu.adb:744 explicit raise > > > > else if X > 0 no exception is raised. > > > > > > with Ada.Numerics.Long_Elementary_Functions;=20 > > use Ada.Numerics.Long_Elementary_Functions; > > procedure Bomb_Log is > > x : Long_Float; > > begin > > x :=3D log(0.0); > > end Bomb_Log; >=20 > If you compile with -gnatwa (most warnings), the report is >=20 > 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 ref= erenced >=20 > and at -O1 or greater the compiler takes the opportunity to eliminate > the call of log, because of >=20 > pragma Pure (Long_Elementary_Functions); >=20 > so that the generated code (gnatmake -c -u -f -S bomb_log.adb) is >=20 > .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 v= ariable y: with Ada.Numerics.Long_Elementary_Functions;=20 use Ada.Numerics.Long_Elementary_Functions; procedure Bomb_Log is x, y : Long_Float; begin x :=3D log(0.0); y :=3D 2.0 * x; end Bomb_Log; there is no warning about "x" but the warnings are now about "y" being assi= gned but not read, and never being referenced. So the optimzizer still snif= fs it out. And Constraint_Error is still raised or not raised in excactly t= he same conditions as in my original post. >=20 > If you change the code to >=20 > procedure Bomb_Log is > x : Long_Float with Volatile; > begin > x :=3D log(0.0); > end Bomb_Log; >=20 > (that's -gnat12, of course, use pragma Volatile (X); otherwise) then > things work as you had expected: >=20 > .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