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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.58.69.78 with SMTP id c14mr2689599veu.41.1400098503193; Wed, 14 May 2014 13:15:03 -0700 (PDT) X-Received: by 10.50.25.4 with SMTP id y4mr187081igf.10.1400098503096; Wed, 14 May 2014 13:15:03 -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!news.glorb.com!r10no4652890igi.0!news-out.google.com!gi6ni1825igc.0!nntp.google.com!r10no4652887igi.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 14 May 2014 13:15:02 -0700 (PDT) In-Reply-To: <40c7405d-c4c2-4163-a430-01052b769866@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: <50562e0a-3dfa-44c4-9aaa-70cbe304b54b@googlegroups.com> <40c7405d-c4c2-4163-a430-01052b769866@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <049c868a-e930-4e5d-a96a-611542cd1ce6@googlegroups.com> Subject: Re: Bug or feature? From: Adam Beneschan Injection-Date: Wed, 14 May 2014 20:15:03 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:19828 Date: 2014-05-14T13:15:02-07:00 List-Id: On Wednesday, May 14, 2014 12:57:47 PM UTC-7, Adam Beneschan wrote: > It does appear that GNAT may not always check the range properly when a > function whose result is Positive tries to return a negative value due to > overflow. That would explain why the recursive version doesn't get an > exception. Here's an example: with Ada.Integer_Text_IO; with Ada.Text_IO; procedure Test is Result : Integer; function Add (X1, X2 : Positive) return Positive is begin return X1 + X2; end Add; function Multiply (X1, X2 : Positive) return Positive is begin return X1 * X2; end Multiply; begin Result :=3D Add(2_000_000_000, 2_000_000_000); Ada.Integer_Text_IO.Put (Item =3D> Result, Width =3D> 1); Result :=3D Multiply(6, 2_000_000_000); Ada.Integer_Text_IO.Put (Item =3D> Result, Width =3D> 1); end Test; Compiled without -gnato. The result is that a negative number is output af= ter the call to Add, but the call to Multiply raises an exception. So it l= ooks like when the function result is Positive, a "return" that returns the= result of an addition doesn't check to make sure the result is in range (w= hen overflow is possible), but a "return" that returns the result of a mult= iplication does check. That would also explain why the original Buffer_Ove= rflow test case works but the recursive Fibonacci routine doesn't. -- Adam