From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12167 invoked by alias); 9 Feb 2007 00:53:07 -0000 Received: (qmail 12138 invoked by uid 48); 9 Feb 2007 00:52:54 -0000 Date: Fri, 09 Feb 2007 00:53:00 -0000 Subject: [Bug ada/30740] New: Improper semantics in gnat's compilation of certain expressions involving modular arithmetic X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "jaffem at erau dot edu" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-02/txt/msg00980.txt.bz2 The problem appears in the evaluation of certain expressions with modular variables. Without the use of the -gnato option during compilation, the executable produced by gnat 3.15p on Solaris for the source code shown below produces incorrect results. Here's a sample output line from this program: ______________________________________________________________________________ When J=2, Test_Pattern*2**J =124 or 2#1111100# but Test_Pattern*2**2 = 60 or 2#111100# ______________________________________________________________________________ 60 is correct, 124 is incorrect. So the default behavior of the compiler does not appear to match the semantics of the Ada language standard for modular values and the "workaround" requires use of an option (-gnato) that should not be influencing the behavior of this program. (Overflow is not possible for modular values; they must always wrap around.) See http://groups.google.com/group/comp.lang.ada/browse_thread/thread/4eca860272d4832b/3bca35e8bb0bdb52?hl=en#3bca35e8bb0bdb52 for a complete discussion of this problem. Here's the source code of a program that demonstrates this problem in my environment and, according to others on comp.lang.ada, other environments as well: with Ada.Text_IO; use Ada.Text_IO; procedure Strange_Typing is type Six_Bits is mod 2**6; package Six_Bit_IO is new Ada.Text_IO.Modular_IO(Six_Bits); use Six_Bit_IO; Test_Pattern : Six_Bits := 31; -- 5 bits of ones begin Put("The test pattern is a modulo 2**6 integer = "); Put(Test_Pattern, 0); Put(" or "); Put(Test_Pattern, 0, 2); New_Line(2); for J in 0 .. 5 loop Put("When J="); Put(Six_Bits(J), 0); Put(", "); Put("Test_Pattern*2**J ="); Six_Bit_IO.Put( Test_Pattern*2**J); Put(" or "); Six_Bit_IO.Put( Test_Pattern*2**J, 0, 2); Put(Ascii.Ht & " but "); case J is when 0 => Put("Test_Pattern*2**0 = "); Put( Test_Pattern*2**0, 0); Put(" or "); Put( Test_Pattern*2**0, 0, 2); when 1 => Put("Test_Pattern*2**1 = "); Put( Test_Pattern*2**1, 0); Put(" or "); Put( Test_Pattern*2**1, 0, 2); when 2 => Put("Test_Pattern*2**2 = "); Put( Test_Pattern*2**2, 0); Put(" or "); Put( Test_Pattern*2**2, 0, 2); when 3 => Put("Test_Pattern*2**3 = "); Put( Test_Pattern*2**3, 0); Put(" or "); Put( Test_Pattern*2**3, 0, 2); when 4 => Put("Test_Pattern*2**4 = "); Put( Test_Pattern*2**4, 0); Put(" or "); Put( Test_Pattern*2**4, 0, 2); when 5 => Put("Test_Pattern*2**5 = "); Put( Test_Pattern*2**5, 0); Put(" or "); Put( Test_Pattern*2**5, 0, 2); end case; New_Line; end loop; New_Line; end Strange_Typing; -- Summary: Improper semantics in gnat's compilation of certain expressions involving modular arithmetic Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jaffem at erau dot edu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30740