]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Create a pragma to emit a misplaced Storage_Size aspect error
authorViljar Indus <indus@adacore.com>
Tue, 5 Aug 2025 09:04:18 +0000 (12:04 +0300)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 9 Sep 2025 12:39:56 +0000 (14:39 +0200)
We do not emit an error on misplaced Strorage_Size error when
the aspect is not applied to a task (or an access type). We
instead create an attribute definition which is ignored most of the
time. Create a temporary pragma for the aspect specification to
emit the same misplaced aspect error as we do for pragmas.

gcc/ada/ChangeLog:

* sem_ch13.adb (Analyze_Aspect_Definitions): Create a temporary
pragma for the non-task and access type cases.

gcc/ada/sem_ch13.adb

index 727c92f5c7e5110b76cd6f8772ebdeac2b78ed96..370df803c25c6f8dbf6997b6bdf88babe83f5b55 100644 (file)
@@ -5593,14 +5593,28 @@ package body Sem_Ch13 is
                         goto Continue;
                      end;
 
-                  --  All other cases, generate attribute definition
+                  --  Generate an attribute definition for access types
 
-                  else
+                  elsif Is_Access_Type (E) then
                      Aitem :=
                        Make_Attribute_Definition_Clause (Loc,
                          Name       => Ent,
                          Chars      => Name_Storage_Size,
                          Expression => Relocate_Node (Expr));
+
+                  --  This is likely a misplaced aspect. Create a pragma to
+                  --  emit the actual error.
+
+                  else
+                     Aitem :=
+                       Make_Aitem_Pragma
+                         (Pragma_Argument_Associations =>
+                            New_List
+                              (Make_Pragma_Argument_Association
+                                 (Loc, Expression => Relocate_Node (Expr))),
+                          Pragma_Name                  => Name_Storage_Size);
+                     Insert_Pragma (Aitem);
+                     goto Continue;
                   end if;
 
                when Aspect_External_Initialization =>