]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Compiler crash on sliding of fixed-lower-bound object in Loop_Invariant
authorGary Dismukes <dismukes@adacore.com>
Thu, 25 Mar 2021 17:37:58 +0000 (13:37 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 21 Jun 2021 10:45:01 +0000 (06:45 -0400)
gcc/ada/

* exp_util.adb (Expand_Sliding_Conversion): Only perform
expansion when Expander_Active is True. Add a comment about this
and refine existing comment regarding string literals.

gcc/ada/exp_util.adb

index ed1a016be48dd3c60fe489530317786d8b4064e6..d02e587d853792b1f98950253af88676fa7f9ef2 100644 (file)
@@ -5343,10 +5343,15 @@ package body Exp_Util is
       All_FLBs_Match : Boolean := True;
 
    begin
-      --  Sliding should never be needed for string literals, because they have
-      --  their bounds set according to the applicable index constraint.
-
-      if Nkind (N) /= N_String_Literal then
+      --  This procedure is called during semantic analysis, and we only expand
+      --  a sliding conversion when Expander_Active, to avoid doing it during
+      --  preanalysis (which can lead to problems with the target subtype not
+      --  getting properly expanded during later full analysis). Also, sliding
+      --  should never be needed for string literals, because their bounds are
+      --  determined directly based on the fixed lower bound of Arr_Typ and
+      --  their length.
+
+      if Expander_Active and then Nkind (N) /= N_String_Literal then
          Constraints := New_List;
 
          Act_Subt  := Get_Actual_Subtype (N);