public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Compiler rejects legal allocator in record component constraint expression
@ 2022-07-04  7:50 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-07-04  7:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: Steve Baird

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

In some cases when a legal allocator which defines a new subtype for the
allocated object occurs as part of a record component constraint
expression, the compiler would incorrectly reject the allocator.

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

gcc/ada/

	* sem_ch4.adb (Analyze_Allocator): After calling Insert_Action
	to insert a subtype declaration associated with an allocator,
	the subtype declaration will usually be analyzed. But not
	always. Add an explicit call to Preanalyze to cope with the
	unusual case. The subtype declaration must be at least
	preanalyzed before the call to Sem_Ch3.Process_Subtype a little
	while later, during which we analyze an identifier that refers
	to the subtype.

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

diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb
--- a/gcc/ada/sem_ch4.adb
+++ b/gcc/ada/sem_ch4.adb
@@ -670,10 +670,19 @@ package body Sem_Ch4 is
                then
                   Def_Id := Make_Temporary (Loc, 'S');
 
-                  Insert_Action (E,
-                    Make_Subtype_Declaration (Loc,
-                      Defining_Identifier => Def_Id,
-                      Subtype_Indication  => Relocate_Node (E)));
+                  declare
+                     Subtype_Decl : constant Node_Id :=
+                       Make_Subtype_Declaration (Loc,
+                         Defining_Identifier => Def_Id,
+                         Subtype_Indication  => Relocate_Node (E));
+                  begin
+                     Insert_Action (E, Subtype_Decl);
+
+                     --  Handle unusual case where Insert_Action does not
+                     --  analyze the declaration. Subtype_Decl must be
+                     --  preanalyzed before call to Process_Subtype below.
+                     Preanalyze (Subtype_Decl);
+                  end;
 
                   if Sav_Errs /= Serious_Errors_Detected
                     and then Nkind (Constraint (E)) =



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

only message in thread, other threads:[~2022-07-04  7:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-04  7:50 [Ada] Compiler rejects legal allocator in record component constraint expression 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).