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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: GNAT does not consistently raise an exception to log(0.0) Date: Sat, 13 Jul 2013 08:34:36 +0100 Organization: A noiseless patient Spider Message-ID: References: <74c64a2c-f062-4b59-aafb-40c0bac39203@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="c8504a89c76ea11bda6664e6198ae3cd"; logging-data="23521"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1ym9lvAQTRbr0M8zHaE4bMmYyiYTMXI8=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:kUysokbnGwRuN1+h147faRwPBpw= sha1:1VdakfKCp6BU+DcxDATKHQ5KsqA= Xref: news.eternal-september.org comp.lang.ada:16342 Date: 2013-07-13T08:34:36+01:00 List-Id: 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 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