exp_ch3.ads
7.69 KB
-
[Ada] Wrong renaming of variant record equality · 01243764
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
Javier Miranda committed