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: 103376,5b9a38a75a50e726 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Feature or Bug? 2#1111# shifted by 4 is 224 References: <20080602191145.1b75b1ee.tero.koskinen@iki.fi> Date: Mon, 02 Jun 2008 19:59:33 +0200 Message-ID: <873anvk9a2.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:/XPdJ4VpHQ17q3mR9/z0rr1jV3o= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tele2 X-Trace: DXC=g[`6STNjfPOa\Mo6Y1n?[C6`Y6aWje^YJSLg0ZJXiadJ]9LCQDYXe7@SOWU?G<`gSL4Q9HhFmY7EM Xref: g2news1.google.com comp.lang.ada:530 Date: 2008-06-02T19:59:33+02:00 List-Id: Tero Koskinen writes: > On Mon, 02 Jun 2008 17:17:19 +0200 Dennis Hoppe wrote: >> Hi, >> >> we probably found a bug in Ada or we cannot realize, that this is indeed >> a feature ;) > [snip] >> >> In Example B, we limit the parameter N to Positive, because we do not >> want "negative" shifts. The result of Shift_Left(2#1111#, 4) is 224 >> (2#11100000#) ! >> >> -- Example B >> type Modular_Type is mod 2**4; >> function Shift_Left (Item : in Modular_Type; >> N : in Positive) return Modular_Type is >> begin >> return Item * 2**N; >> end Shift_Left; >> >> Why does this happen? > > It is a bug in GCC on i386 platform. I can repeat it with GNAT GPL 2007 > and GCC 4.3.0 (OpenBSD/i386). With GCC 4.3.0 optimization flags > (-O2 vs. -O0) seem to affect to the result. > > On Solaris (5.10 Generic_127111-05 sun4u sparc SUNW,Sun-Fire-V240) with > GCC 4.2.1 the example returns 0 always. > > Here is more complete test case: > with Ada.Text_IO; use Ada.Text_IO; > procedure Shift is > > type Modular_Type is mod 2**4; > function Shift_Left (Item : in Modular_Type; > N : in Positive) return Modular_Type is > begin > return Item * (2**N); > end Shift_Left; > > X : Modular_Type; > begin > X := Shift_Left(2#1111#, 4); > Put_Line (X'Img); > end Shift; This looks like http://gcc.gnu.org/PR30740 which is fixed in Debian unstable :) Could you confirm that this is the same bug indeed? -- Ludovic Brenta.