comp.lang.ada
 help / color / mirror / Atom feed
From: georg bauhaus <rmhost.bauhaus@maps.arcor.de>
Subject: expression function bug or think?
Date: 16 Jun 2011 11:00:02 GMT
Date: 2011-06-16T13:00:02+02:00	[thread overview]
Message-ID: <678085105329914667.504682rmhost.bauhaus-maps.arcor.de@news.arcor.de> (raw)

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?



             reply	other threads:[~2011-06-16 11:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-16 11:00 georg bauhaus [this message]
2011-06-16 11:27 ` expression function bug or think? AdaMagica
2011-06-16 15:56 ` Adam Beneschan
2011-06-17  3:56   ` Yannick Duchêne (Hibou57)
2011-06-16 16:16 ` Anh Vo
2011-06-16 18:56 ` Bill Findlay
2011-06-16 19:18   ` Simon Wright
2011-06-16 20:03     ` Georg Bauhaus
2011-06-16 20:03     ` Bill Findlay
2011-06-16 20:31 ` Florian Weimer
2011-06-16 20:41   ` Simon Wright
2011-06-16 21:14     ` Georg Bauhaus
2011-06-16 23:14     ` Bill Findlay
2011-06-17  9:34     ` Martin
2011-06-17 10:33       ` Simon Wright
2011-06-17 10:39         ` Martin
2011-06-17 11:09           ` Niklas Holsti
2011-06-16 21:04   ` Georg Bauhaus
2011-06-17  8:55   ` Georg Bauhaus
2011-06-17  9:10     ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox