[Ada] Wrong renaming of variant record equality
authorJavier Miranda <miranda@adacore.com>
Thu, 24 May 2018 13:06:47 +0000 (13:06 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Thu, 24 May 2018 13:06:47 +0000 (13:06 +0000)
commit01243764c0ea83d0086d7e49a8752a8f13bfd802
tree14fea77a675cf77b7a628bcb69d4fc6986420750
parent7037d2bbd04f5b845b899e533a96334c0e2f653e
[Ada] Wrong renaming of variant record equality

For a renaming of the equality operator of a variant record the compiler
erroneously generates code that compares all the record component (thus
computing wrong results).

After this patch the following test provides the correct results.

package Types is
   type Data (Bool : Boolean := False) is record
      case Bool is
         when False =>
            null;

         when True =>
            Val1 : Integer range 0 .. 2 ** 23 - 1;
            Val2 : Float;
      end case;
   end record;

   function IsEqual (Left, Right : Data) return Boolean renames "=";
end Types;

with Types;
with Ada.Text_IO;
procedure Main is
   A : Types.Data := Types.Data'(Bool => True,
                                 Val1 => 16#05A5A5#,
                                 Val2 => 999999999.0);

   B : Types.Data := Types.Data'(Bool => True,
                                 Val1 => 16#0A5A5A#,
                                 Val2 => 6666666666.0);
   use type Types.Data;
begin
   A := (Bool => False);             --  Test
   B := (Bool => False);             --  Test

   if Types.IsEqual (A, B) then      --  Test
      Ada.Text_IO.Put_Line ("OK");
   else
      Ada.Text_IO.Put_Line ("ERROR");
   end if;
end Main;

Command: gnatmake main; ./main
 Output: OK

2018-05-24  Javier Miranda  <miranda@adacore.com>

gcc/ada/

* exp_ch8.adb (Build_Body_For_Renaming): Adding support to build the
body of a variant record equality renaming.
(Expand_N_Subprogram_Renaming_Declaration): Adapt the code to the new
implementation of Build_Body_For_Renaming.
* exp_ch3.ads (Build_Variant_Record_Equality): New library level
function that factorizes the functionality needed by
Build_Body_For_Renaming and Expand_Freeze_Record_Type to build the body
of a variant record equality subprogram.
* exp_ch3.adb (Build_Variant_Record_Equality): New subprogram.
(Build_Variant_Record_Equality): New local procedure of
Expand_Freeze_Record_Type containing all the code specific for freezing
the record type that cannot be place in the new library level function.

From-SVN: r260667
gcc/ada/ChangeLog
gcc/ada/exp_ch3.adb
gcc/ada/exp_ch3.ads
gcc/ada/exp_ch8.adb