Bug 33457 - Renaming in context of ragged array
Summary: Renaming in context of ragged array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-17 18:59 UTC by Anh Vo
Modified: 2008-05-12 21:24 UTC (History)
2 users (show)

See Also:
Host: Red Hat i686
Target:
Build: gcc-4.3-20070914
Known to work: 4.3.0
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anh Vo 2007-09-17 18:59:32 UTC
The object renaming does not behave properly as demonstrated with the test codes below. Note that line 11 of message_services.adb contains the problem. In addition, if line 11 is commented out and line 12 in uncommented, the codes behave properly.

package Message_Services is
   type Message_Code is range 0 .. 100;
   
   subtype Message is String;
   
   function Get_Message (Code : Message_Code) return String;
   pragma Inline (Get_Message);
   
end Message_Services;

package body Message_Services is

   type Message_Handle is access constant Message;
   
   Message_0 : aliased constant Message := "OK";
   Message_1 : aliased constant Message := "Up";
   Message_2 : aliased constant Message := "Down";
   Message_3 : aliased constant Message := "Left";
   Message_4 : aliased constant Message := "Right";
   -- ...
   Default   : Message renames Message_0; -- bug here
--   Default   : aliased constant Message := Message_0; -- work around
   
   Message_Table : array (Message_Code) of Message_Handle := (
                     000 => Message_0'access,
                     001 => Message_1'access,
                     002 => Message_2'access,
                     003 => Message_3'access,
                     004 => Message_4'access,
                     others => Default'access);
                     
   function Get_Message (Code : Message_Code) return String is
   begin
      return Message_Table (Code).all;
   end Get_Message;
   
end Message_Services;

with Ada.Text_IO;

procedure Message_Services.Test is

   use Ada;
   use Text_IO;

   Test_Message : constant Message := "OK";
 
begin

   Put_Line ("Static Ragged Array construction, no heap involvement");
   
   for Index in Message_Code range 0 .. 9 loop
      Put_Line ("Message" & Message_Code'Image (Index) & " is: " & 
                   Get_Message (Index));   
   end loop;
   
   for Index in Message_Code range 5 .. 9 loop
      if Get_Message (Index) /= Test_Message then
         Put_Line ("Test fails");
         return;
      end if;   
   end loop;
   Put_Line ("Test passes");
   
end Message_Services.Test;
Comment 1 Anh Vo 2007-09-17 22:13:21 UTC
Sorry for the typo in problem description paragraph. What I mean was if line 11 commented out and line 12 uncommented, the codes behave properly.
Comment 2 Anh Vo 2008-01-21 21:54:34 UTC
This problem does not occur in gcc-4.3-20080118.
Comment 3 Samuel Tardieu 2008-05-12 14:12:08 UTC
What compilation option did you use? I cannot reproduce this with Debian's 4.3 compiler or with current SVN trunk.
Comment 4 Anh Vo 2008-05-12 15:19:57 UTC
Sam,

If you look at my comment on 21 January 2008. This problem was fixed starting with gcc-4.3-20080118. That is why you did not see the problem existed. In summary, this PR should be closed around that time.
Comment 5 Samuel Tardieu 2008-05-12 21:24:10 UTC
Indeed, I missed the "not" in your message :)

This is great news. Closing.