diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2020-04-11 15:40:24 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2020-06-17 04:14:02 -0400 |
commit | 940eb45810712925fbc10a39b243b7ec001085ec (patch) | |
tree | bbe62a15e56ce657a3de0f236a8dc485c7e19b02 /gcc | |
parent | ac8806c4c5dad67648be37fda737a664961c1cf1 (diff) | |
download | gcc-940eb45810712925fbc10a39b243b7ec001085ec.zip gcc-940eb45810712925fbc10a39b243b7ec001085ec.tar.gz gcc-940eb45810712925fbc10a39b243b7ec001085ec.tar.bz2 |
[Ada] Fix small oversight in change to Optimize_Length_Comparison
2020-06-17 Eric Botcazou <ebotcazou@adacore.com>
gcc/ada/
* exp_ch4.adb (Optimize_Length_Comparison): Make sure the base
types are the same when comparing Y'Last and X'Last directly.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/exp_ch4.adb | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 4297997..7ecc9c3 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -14052,6 +14052,17 @@ package body Exp_Ch4 is Set_Expressions (Left, New_List (New_Copy (Index (1)))); end if; + -- Build the Last reference we will use + + Right := + Make_Attribute_Reference (Loc, + Prefix => New_Occurrence_Of (Ent (1), Loc), + Attribute_Name => Name_Last); + + if Present (Index (1)) then + Set_Expressions (Right, New_List (New_Copy (Index (1)))); + end if; + -- If general value case, then do the addition of (n - 1), and -- also add the needed conversions to type Long_Long_Integer. @@ -14083,16 +14094,27 @@ package body Exp_Ch4 is Analyze (Left); Analyze (Y_First); - -- If X'First = Y'First, rewrite it into a direct comparison - -- of Y'Last and X'Last without conversions. + -- If X'First = Y'First, simplify the above formula into a + -- direct comparison of Y'Last and X'Last. R := Compile_Time_Compare (Left, Y_First, Assume_Valid => True); if R = EQ then - Left := Y_Last; - Comp := Empty; + Analyze (Right); + Analyze (Y_Last); - -- Otherwise, use the above formula + -- If the base types are different, convert both operands to + -- Long_Long_Integer, else compare them directly. + + if Base_Type (Etype (Right)) /= Base_Type (Etype (Y_Last)) + then + Left := Convert_To_Long_Long_Integer (Y_Last); + else + Left := Y_Last; + Comp := Empty; + end if; + + -- Otherwise, use the above formula as-is else Left := @@ -14120,17 +14142,6 @@ package body Exp_Ch4 is end if; end if; - -- Build the Last reference we will use - - Right := - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (Ent (1), Loc), - Attribute_Name => Name_Last); - - if Present (Index (1)) then - Set_Expressions (Right, New_List (New_Copy (Index (1)))); - end if; - -- If general operand, convert Last reference to Long_Long_Integer if Present (Comp) then |