This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug ada/30740] Improper semantics in gnat's compilation of certain expressions involving modular arithmetic
- From: "jaffem at erau dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Feb 2007 00:21:59 -0000
- Subject: [Bug ada/30740] Improper semantics in gnat's compilation of certain expressions involving modular arithmetic
- References: <bug-30740-14071@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #2 from jaffem at erau dot edu 2007-02-10 00:21 -------
Subject: Re: Improper semantics in gnat's compilation of certain
expressions involving modular arithmetic
For what it's worth (not much, I suspect ;-) I concur that this program,
below, correctly demonstrates the same bug that I reported --- and does
so a great deal more concisely than the demo program I sent in with the
bug report.
ludovic at ludovic-brenta dot org wrote:
> ------- Comment #1 from ludovic at ludovic-brenta dot org 2007-02-09 14:34 -------
> Shorter test case that reproduces the problem.
>
> with Ada.Text_IO;
> procedure test1 is
> type T1 is mod 9;
> package T1_IO is new Ada.Text_IO.Modular_IO(T1);
> X: T1 := 8;
> J1: constant := 5;
> begin
> for J2 in 5..5 loop
> pragma assert(X*(2**J1) = X*(2**J2));
> if X*(2**J1) /= X*(2**J2) then
> Ada.Text_IO.Put_Line("Failed");
> T1_IO.Put(X*(2**J1));
> T1_IO.Put(X*(2**J2));
> Ada.Text_IO.New_Line;
> end if;
> end loop;
> end test1;
>
> prints:
>
> Failed
> 4 0
>
> To reproduce: gnatmake test1
>
> To reproduce with correct behaviour (no output): gnatmake -gnato test1
>
> Notice that when multiplying by 2**J1, the result is always correct because J2
> is a named number and the calculation is done at compile time with the correct
> semantics. In contrast, J2 is non-static and exhibits the wrong semantics
> unless we add -gnato.
>
> Problem reproduced with GCC 4.1.1 but it's been there ever since 3.15p or even
> before.
>
>
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30740