Please find below ada code that compiles and executes on 2 machines with
different gcc versions
Machine1 has gcc 3.3.3 and compiles and executes correctly
Machine2 has gcc 4.1.1 and compiles without warnings. It executes but produces
the wrong result. As you can see the code zeroes SL(1) and SL(2). 
In both cases the command line is "gnatmake -Wall test" where the code extract
below is in test.adb

#This works
Linux machine1.domain 2.6.10-1.771_FC2smp #1 SMP Mon Mar 28 01:10:51 EST 2005
i686 athlon i386 GNU/Linux

gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --disable-libunwind-exceptions --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix

#Program output
How to set Valid to TRUE, Method 1
Config_Message_Buffer = SL1= 100 SL2= 100 Valid=FALSE 
Config_Message_Buffer = SL1= 100 SL2= 100 Valid=TRUE 
How to set Valid to TRUE, Method 2
Config_Message_Buffer = SL1= 100 SL2= 100 Valid=FALSE 
Config_Message_Buffer = SL1= 100 SL2= 100 Valid=TRUE 


#This doesn't!
Linux machine2.domain 2.6.18-1.2798.fc6 #1 SMP Mon Oct 16 14:37:32 EDT 2006
i686 i686 i386 GNU/Linux

gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=i386-redhat-linux
Thread model: posix

#Program output
How to set Valid to TRUE, Method 1
Config_Message_Buffer = SL1= 100 SL2= 100 Valid=FALSE 
Config_Message_Buffer = SL1= 0 SL2= 0 Valid=TRUE 
How to set Valid to TRUE, Method 2
Config_Message_Buffer = SL1= 100 SL2= 100 Valid=FALSE 
Config_Message_Buffer = SL1= 100 SL2= 100 Valid=TRUE 


----------------------------------------------------------
#Code
with text_io;

procedure test is

   type Data_Type_A_Range is range 100 .. 200;
   type Data_Type_A is array (1..2) of Data_Type_A_Range;

   -- this record would have several declarations inside. 
   -- for this example I have cut it down to a single one called SL
   type Config_Message_Type is
      record
         SL : Data_Type_A;
      end record;

   -- Defines the configuration message buffer type
   type Config_Message_Buffer_Type is
      record
         Data  : Config_Message_Type;
         Valid : Boolean;
      end record;

   -- Defines the default configuration message buffer
   Default_Config_Message_Buffer : constant Config_Message_Buffer_Type :=
Config_Message_Buffer_Type'
     (Data  => Config_Message_Type'(SL  => Data_Type_A'(others =>
Data_Type_A_Range'first)),
      Valid => False);

   -- define 2 variables and set them both to the same default value
   Config_Message_Buffer1 : Config_Message_Buffer_Type :=
Default_Config_Message_Buffer;
   Config_Message_Buffer2 : Config_Message_Buffer_Type :=
Default_Config_Message_Buffer;

   procedure dump_message_buffer (CMB : Config_Message_Buffer_Type) is
   begin
      text_io.put("Config_Message_Buffer = ");
      text_io.put("SL1="   & Data_Type_A_Range'image(CMB.Data.SL(1)) & " ");
      text_io.put("SL2="   & Data_Type_A_Range'image(CMB.Data.SL(2)) & " ");
      text_io.put("Valid=" & boolean'image(CMB.Valid) & " ");
      text_io.new_line;
   end;

begin 

   text_io.put_line ("How to set Valid to TRUE, Method 1");   

   dump_message_buffer(Config_Message_Buffer1);

   -- when Config_Message_Type has several declarations some are altered some
aren't
   -- this is an example of a one that isnt changed and should set itself to
itself
   Config_Message_Buffer1 := Config_Message_Buffer_Type'
     (Data  => Config_Message_Type'(SL => Config_Message_Buffer1.Data.SL),
      Valid => True);

   dump_message_buffer(Config_Message_Buffer1);

   text_io.put_line ("How to set Valid to TRUE, Method 2");   

   dump_message_buffer(Config_Message_Buffer2);

   Config_Message_Buffer2.Valid := True;

   dump_message_buffer(Config_Message_Buffer2);
end test;
#End Code
-----------------------------------------


-- 
           Summary: Value assigned to array element in record always '0'
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: junk2 at fieldhome dot co dot uk


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30037

Reply via email to