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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,ed872c72866dab2b,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news2.google.com!goblin2!goblin.stu.neva.ru!news.internetdienste.de!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!news.mind.de!bolzen.all.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail User-Agent: NewsTap/2.1.7 (iPhone/iPod Touch) From: georg bauhaus Newsgroups: comp.lang.ada Content-Type: text/plain; charset=UTF-8 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: <678085105329914667.504682rmhost.bauhaus-maps.arcor.de@news.arcor.de> Subject: expression function bug or think? Date: 16 Jun 2011 11:00:02 GMT Organization: Arcor NNTP-Posting-Date: 16 Jun 2011 13:00:02 CEST NNTP-Posting-Host: 054416eb.newsspool4.arcor-online.net X-Trace: DXC=;N8OIHKhhoT5TOT9_N5iY When I compile the following program with GNAT GPL 2011 on Mac, I get confusingly different behavior depending on whether or not I suppress checks. *Suppressing* the checks results in the desired program behavior. (The effect reminds me of potential for Ariane 5 gossip—or simply of me being dense.) When checks are *disabled* (-gnatp), the program runs as expected and prints fib(10) = 55. When checks are enabled (no -gnatp) I get a constraint error on L.6. Optimization does not affect the result, only -gnatp. Is the program correct, at least in theory? raised CONSTRAINT_ERROR : fib.ada:6 range check failed package Functions is function Fib (N : Natural) return Natural is (case N is when 0 => 0, when 1 => 1, when others => Fib(N-1) + Fib(N-2)); -- L.6 end Functions; with Functions; with Ada.Text_IO; procedure Run_Fib is N : Natural; begin if Functions.Fib(0) /= 0 then raise Program_Error; end if; N := Functions.Fib(10); Ada.Text_IO.Put_Line ("fib(10) =" & Natural'Image(N)); end Run_Fib; The debugger says that N=0 at L.6. Therefore, my guess is that translating in normal Ada mode (implying range checks) breaks the instruction sequence for case somewhere. (I haven't understood the asm yet, takes time and effort since I don't read that every day.) Maybe there is a hint in http://gcc.gnu.org/ml/gcc-patches/2010-10/txt00134.txt of http://gcc.gnu.org/ml/gcc-patches/2010-10/msg00579.html Is this a bug?