This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug ada/20593] New: Simple array of string access miscompiled on x86 and x86_64


On 4.1 and 4.0 the following program gets a segmentation fault on x86 (tested
with 4.1.0 20050318 ) and x86_64 (tested with 4.1.0 20050321 and 4.0.0 20050320).

$ cat z
with P1; use P1;
procedure PP is
   A : constant E := Get ("3");
begin
   if A /= Enum_3 then
      raise Program_Error;
   end if;
end PP;
package P1 is
   type E is (Enum_1,Enum_2,Enum_3);
   function Get (Y : in String) return E;
end P1;
package body P1 is
   type Ptr is access constant String;
   type T is array (E) of Ptr;
   X : constant T :=
     (Enum_1 => new String'("1"),
      Enum_2 => new String'("2"),
      Enum_3 => new String'("3"));

   function Get (Y : in String) return E is
   begin
      for I in X'Range loop
         if X (I).all = Y then
            return I;
         end if;
      end loop;
      return Enum_1;
   end Get;
end P1;

$ gnatchop z
$ gnatmake pp
$ ./pp
Segmentation fault
$

We expect no output.

gdb backtrace
Program received signal SIGSEGV, Segmentation fault.
0x000000000040239f in p1.get (y={P_ARRAY = 0x407f5c, P_BOUNDS = 0x407f54}) at
p1.adb:12
12               if X (I).all = Y then
Current language:  auto; currently minimal
(gdb) bt
#0  0x000000000040239f in p1.get (y={P_ARRAY = 0x407f5c, P_BOUNDS = 0x407f54})
at p1.adb:12
#1  0x00000000004025c3 in _ada_pp () at pp.adb:3
#2  0x0000000000401f4b in main (argc=1, argv=548682068712, envp=548682068728) at
b~pp.adb:114

Not investigated yet, found in my own test code. 

This code was working with 3.3.3 and probably all previously released versions
of GCC. This was already failing on 4.0.0 20041214 so it's not brand new.

-- 
           Summary: Simple array of string access miscompiled on x86 and
                    x86_64
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: laurent at guerby dot net
                CC: gcc-bugs at gcc dot gnu dot org,kenner at vlsi1 dot
                    ultra dot nyu dot edu


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]