[Bug ada/14997] ncurses build fails with Ada

laurent at guerby dot net gcc-bugzilla@gcc.gnu.org
Sun Apr 18 02:21:00 GMT 2004


------- Additional Comments From laurent at guerby dot net  2004-04-17 21:38 -------
Here is a reduced test cases that ICE even at -O0.

But the problem is that the user code is incorrect, it assumes
that Interfaces.C.Unsigned_Long is 64 bits, however it is 32 bits.
In the aux package C_Chtype should be declared as:

   type    C_Chtype   is mod 2**64;

Then everything should work (it compiles, I cannot test fully).

On the GCC side, if the code does the assignement in two steps,
I get a warning not a blow up:

   X : constant C_Chtype := 0;
   Y : Character_Attribute_Set;
   Z : Attributed_Character;
begin
   Z := Chtype_To_AttrChar (X);
   Y := Z.Attr;

$ gcc -c -O1 pq.adb 
pq.adb:70:04: warning: types for unchecked conversion have different sizes

So on the front-end side, a warning should be generated
and may be a way not to ICE in back-end could be found.
Generated code will be meaningless anyway.

Laurent

$ gcc -c -O0 pq.adb 
+===========================GNAT BUG DETECTED==============================+
| 3.5.0 20040417 (experimental) (i686-pc-linux-gnu) GCC error:             |
| in expand_expr_real, at expr.c:7137                                      |
| Error detected at pq.adb:78:29                                           |

--
with Interfaces.C; use Interfaces.C;
with Ada.Unchecked_Conversion;

procedure PQ is

   subtype C_ULong    is Interfaces.C.unsigned_long;
   type    C_Chtype   is new C_ULong;

   type Character_Attribute_Set is
      record
         Stand_Out               : Boolean;
         Under_Line              : Boolean;
         Reverse_Video           : Boolean;
         Blink                   : Boolean;
         Dim_Character           : Boolean;
         Bold_Character          : Boolean;
         Alternate_Character_Set : Boolean;
         Invisible_Character     : Boolean;
         Protected_Character     : Boolean;
         Horizontal              : Boolean;
         Left                    : Boolean;
         Low                     : Boolean;
         Right                   : Boolean;
         Top                     : Boolean;
         Vertical                : Boolean;
      end record;
   pragma Pack (Character_Attribute_Set);
   pragma Convention (C, Character_Attribute_Set);

   for Character_Attribute_Set use
      record
         Stand_Out               at 0 range 47 .. 47;
         Under_Line              at 0 range 46 .. 46;
         Reverse_Video           at 0 range 45 .. 45;
         Blink                   at 0 range 44 .. 44;
         Dim_Character           at 0 range 43 .. 43;
         Bold_Character          at 0 range 42 .. 42;
         Alternate_Character_Set at 0 range 41 .. 41;
         Invisible_Character     at 0 range 40 .. 40;
         Protected_Character     at 0 range 39 .. 39;
         Horizontal              at 0 range 38 .. 38;
         Left                    at 0 range 37 .. 37;
         Low                     at 0 range 36 .. 36;
         Right                   at 0 range 35 .. 35;
         Top                     at 0 range 34 .. 34;
         Vertical                at 0 range 33 .. 33;
      end record;
   for Character_Attribute_Set'Size use 48;

   type Color_Pair is range 0 .. 255;
   for Color_Pair'Size use 8;

   type Attributed_Character is
      record
         Attr  : Character_Attribute_Set;
         Color : Color_Pair;
         Ch    : Character;
      end record;
   pragma Convention (C, Attributed_Character);
   --  This is the counterpart for the chtype in C.

   for Attributed_Character use
      record
         Ch    at 0 range 56 .. 63;
         Color at 0 range 48 .. 55;
         Attr  at 0 range  0 .. 47;
      end record;
   for Attributed_Character'Size use 64;

   function Chtype_To_AttrChar is new
     Ada.Unchecked_Conversion (Source => C_Chtype,
                           Target => Attributed_Character);


   X : constant C_Chtype := 0;
   Y : Character_Attribute_Set;
begin
   Y := Chtype_To_AttrChar (X).Attr;
end PQ;


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|minor                       |normal
           Priority|P3                          |P2


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



More information about the Gcc-bugs mailing list