public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Compiler crash on sliding of fixed-lower-bound object in Loop_Invariant
@ 2021-06-21 11:05 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-06-21 11:05 UTC (permalink / raw)
  To: gcc-patches; +Cc: Gary Dismukes

[-- Attachment #1: Type: text/plain, Size: 775 bytes --]

When a sliding conversion is expanded during preanalysis of certain
assertion pragmas (such as Loop_Invariant), to convert an object of to
an array subtype with a fixed lower bound, a Val attribute created as
part of the upper bound expression of the conversion's subtype is not
expanded later when the pragma argument is reanalyzed as part of the
Check pragma that replaces the assertion pragma. This can lead to a
crash in gigi. This is fixed by not expanding sliding conversions during
preanalysis (when Expander_Active is False).

Tested on x86_64-pc-linux-gnu, committed on trunk

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1074 bytes --]

diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -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);



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-21 11:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 11:05 [Ada] Compiler crash on sliding of fixed-lower-bound object in Loop_Invariant Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).