[Bug ada/101094] New: [11 regression] 'Enum_Rep returns a unsigned value for the negative representation in gcc-11

demoonlit at panathenaia dot halfmoon.jp gcc-bugzilla@gcc.gnu.org
Wed Jun 16 11:41:01 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101094

            Bug ID: 101094
           Summary: [11 regression] 'Enum_Rep returns a unsigned value for
                    the negative representation in gcc-11
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: demoonlit at panathenaia dot halfmoon.jp
  Target Milestone: ---

'Enum_Rep returns a unsigned value for the run-time value having the negative
representation in gcc-11.
It also returns just a representation value for the compile-time value.

In gcc-10 or older, it always returns just a representation value.
Is this intentional changed or not?

Test code
---------

with Ada.Text_IO;
with Ada.Integer_Text_IO;
procedure main is
   type T is (Nega, Zero, Posi);
   for T use (Nega => -1, Zero => 0, Posi => 1);
begin
   -- literal
   Ada.Text_IO.Put ("Lite:");
   Ada.Integer_Text_IO.Put (T'Enum_Rep (Nega)); -- "-1"
   Ada.Text_IO.New_Line;
   -- compile-time constant
   declare
      Cons : constant T := Nega;
   begin
      Ada.Text_IO.Put ("Cons:");
      Ada.Integer_Text_IO.Put (T'Enum_Rep (Cons)); -- "-1"
      Ada.Text_IO.New_Line;
   end;
   -- variable
   declare
      Vari : T := T'Value ("Nega");
   begin
      Ada.Text_IO.Put ("Vari:");
      Ada.Integer_Text_IO.Put (T'Enum_Rep (Vari)); -- "255"
      Ada.Text_IO.New_Line;
   end;
   -- parameter
   declare
      procedure Sub1 (Para : T) is
      begin
         Ada.Text_IO.Put ("Para:");
         Ada.Integer_Text_IO.Put (T'Enum_Rep (Para)); -- "255"
         Ada.Text_IO.New_Line;
      end Sub1;
   begin
      Sub1 (Nega);
   end;
end main;

With gcc-10
-----------

$ gnatmake --version
GNATMAKE 10.2.0
Copyright (C) 1995-2020, Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

$ gnatmake main
gcc -c main.adb
gnatbind -x main.ali
gnatlink main.ali

$ ./main
Lite:         -1
Cons:         -1
Vari:         -1
Para:         -1

With gcc-11
-----------

$ gnatmake --version
GNATMAKE 11.1.0
Copyright (C) 1995-2021, Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

$ gnatmake main
gcc -c main.adb
gnatbind -x main.ali
gnatlink main.ali

% ./main
Lite:         -1
Cons:         -1
Vari:        255
Para:        255

Thanks.


More information about the Gcc-bugs mailing list