public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ludovic at ludovic-brenta dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ada/30740] Improper semantics in gnat's compilation of certain expressions involving modular arithmetic
Date: Fri, 09 Feb 2007 14:34:00 -0000	[thread overview]
Message-ID: <20070209143412.30576.qmail@sourceware.org> (raw)
In-Reply-To: <bug-30740-14071@http.gcc.gnu.org/bugzilla/>



------- 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


  reply	other threads:[~2007-02-09 14:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-09  0:53 [Bug ada/30740] New: " jaffem at erau dot edu
2007-02-09 14:34 ` ludovic at ludovic-brenta dot org [this message]
2007-02-10  0:22 ` [Bug ada/30740] " jaffem at erau dot edu
2007-11-25 14:26 ` sam at gcc dot gnu dot org
2008-05-20 12:39 ` charlet at gcc dot gnu dot org
2008-05-20 12:46 ` charlet at gcc dot gnu dot org
2008-05-20 13:08 ` charlet at gcc dot gnu dot org
2008-05-20 20:26 ` sam at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070209143412.30576.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).