This is useful in particular to be able to mark a formal parameter of an
expression function as unreferenced:

   function F (Param : Integer with Unreferenced) return Integer is (1);

We also add the infrastructure to support other aspects on formal
parameters in the future.

Put this feature under -gnatX for now since the Ada RM doesn't support
this syntax (yet).

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

gcc/ada/

        * aspects.adb (Has_Aspect_Specifications_Flag): Add
        N_Parameter_Specification.
        * par-ch13.adb (Aspect_Specifications_Present): Also handle case
        of an unknown aspect on the last formal parameter (terminated by
        a Tok_Right_Paren). Minor reformatting.
        * par-ch6.adb (P_Formal_Part): Scan aspects on formal
        parameters.
        * par.adb: Fix typos.
        * sem_ch6.adb (Process_Formals): Add processing of aspects and
        in particular Unreferenced aspect for now.
        * sinfo.ads: Allow ASPECT_SPECIFICATIONS on a
        PARAMETER_SPECIFICATION.
        * doc/gnat_rm/implementation_defined_aspects.rst
        (Aspect Unreferenced): Update documentation.
        * gnat_rm.texi: Regenerate.
diff --git a/gcc/ada/aspects.adb b/gcc/ada/aspects.adb
--- a/gcc/ada/aspects.adb
+++ b/gcc/ada/aspects.adb
@@ -455,6 +455,7 @@ package body Aspects is
       N_Package_Instantiation                  => True,
       N_Package_Specification                  => True,
       N_Package_Renaming_Declaration           => True,
+      N_Parameter_Specification                => True,
       N_Private_Extension_Declaration          => True,
       N_Private_Type_Declaration               => True,
       N_Procedure_Instantiation                => True,


diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_aspects.rst b/gcc/ada/doc/gnat_rm/implementation_defined_aspects.rst
--- a/gcc/ada/doc/gnat_rm/implementation_defined_aspects.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_aspects.rst
@@ -564,9 +564,11 @@ Aspect Unreferenced
 ===================
 .. index:: Unreferenced
 
-This boolean aspect is equivalent to :ref:`pragma Unreferenced<Pragma-Unreferenced>`. Note that
-in the case of formal parameters, it is not permitted to have aspects for
-a formal parameter, so in this case the pragma form must be used.
+This boolean aspect is equivalent to :ref:`pragma Unreferenced<Pragma-Unreferenced>`.
+
+When using the ``-gnatX`` switch, this aspect is also supported on formal
+parameters, which is in particular the only form possible for expression
+functions.
 
 Aspect Unreferenced_Objects
 ===========================


diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -9923,9 +9923,11 @@ This boolean aspect is equivalent to @ref{10b,,pragma Unmodified}.
 
 @geindex Unreferenced
 
-This boolean aspect is equivalent to @ref{10c,,pragma Unreferenced}. Note that
-in the case of formal parameters, it is not permitted to have aspects for
-a formal parameter, so in this case the pragma form must be used.
+This boolean aspect is equivalent to @ref{10c,,pragma Unreferenced}.
+
+When using the @code{-gnatX} switch, this aspect is also supported on formal
+parameters, which is in particular the only form possible for expression
+functions.
 
 @node Aspect Unreferenced_Objects,Aspect Value_Size,Aspect Unreferenced,Implementation Defined Aspects
 @anchor{gnat_rm/implementation_defined_aspects aspect-unreferenced-objects}@anchor{15e}


diff --git a/gcc/ada/par-ch13.adb b/gcc/ada/par-ch13.adb
--- a/gcc/ada/par-ch13.adb
+++ b/gcc/ada/par-ch13.adb
@@ -153,7 +153,8 @@ package body Ch13 is
             Result := True;
          else
             Scan; -- past identifier
-            Result := Token in Tok_Arrow | Tok_Comma | Tok_Is | Tok_Semicolon;
+            Result := Token in
+              Tok_Arrow | Tok_Comma | Tok_Is | Tok_Semicolon | Tok_Right_Paren;
          end if;
 
       --  If earlier than Ada 2012, check for valid aspect identifier (possibly
@@ -956,7 +957,7 @@ package body Ch13 is
          --  If Decl is Error, we ignore the aspects, and issue a message
 
          elsif Decl = Error
-            or else not Permits_Aspect_Specifications (Decl)
+           or else not Permits_Aspect_Specifications (Decl)
          then
             Error_Msg ("aspect specifications not allowed here", Ptr);
 


diff --git a/gcc/ada/par-ch6.adb b/gcc/ada/par-ch6.adb
--- a/gcc/ada/par-ch6.adb
+++ b/gcc/ada/par-ch6.adb
@@ -1627,6 +1627,25 @@ package body Ch6 is
             Scan; -- past right paren
             exit Specification_Loop;
 
+         --  Support for aspects on formal parameters is a GNAT extension for
+         --  the time being.
+
+         elsif Token = Tok_With then
+            if not Extensions_Allowed then
+               Error_Msg_SP ("aspect on formal parameter requires -gnatX");
+            end if;
+
+            P_Aspect_Specifications (Specification_Node, False);
+
+            if Token = Tok_Right_Paren then
+               Scan;  -- past right paren
+               exit Specification_Loop;
+
+            elsif Token = Tok_Semicolon then
+               Save_Scan_State (Scan_State);
+               Scan; -- past semicolon
+            end if;
+
          --  Special check for common error of using comma instead of semicolon
 
          elsif Token = Tok_Comma then


diff --git a/gcc/ada/par.adb b/gcc/ada/par.adb
--- a/gcc/ada/par.adb
+++ b/gcc/ada/par.adb
@@ -995,10 +995,10 @@ function Par (Configuration_Pragmas : Boolean) return List_Id is
       procedure P_Aspect_Specifications
         (Decl      : Node_Id;
          Semicolon : Boolean := True);
-      --  This procedure scans out a series of aspect spefications. If argument
-      --  Semicolon is True, a terminating semicolon is also scanned. If this
-      --  argument is False, the scan pointer is left pointing past the aspects
-      --  and the caller must check for a proper terminator.
+      --  This procedure scans out a series of aspect specifications. If
+      --  argument Semicolon is True, a terminating semicolon is also scanned.
+      --  If this argument is False, the scan pointer is left pointing past the
+      --  aspects and the caller must check for a proper terminator.
       --
       --  P_Aspect_Specifications is called with the current token pointing
       --  to either a WITH keyword starting an aspect specification, or an


diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -672,9 +672,9 @@ package body Sem_Ch6 is
       end if;
    end Analyze_Expression_Function;
 
-   ----------------------------------------
-   -- Analyze_Extended_Return_Statement  --
-   ----------------------------------------
+   ---------------------------------------
+   -- Analyze_Extended_Return_Statement --
+   ---------------------------------------
 
    procedure Analyze_Extended_Return_Statement (N : Node_Id) is
    begin
@@ -12282,6 +12282,27 @@ package body Sem_Ch6 is
             end if;
          end if;
 
+         --  Deal with aspects on formal parameters. Only Unreferenced is
+         --  supported for the time being.
+
+         if Has_Aspects (Param_Spec) then
+            declare
+               Aspect : Node_Id := First (Aspect_Specifications (Param_Spec));
+            begin
+               while Present (Aspect) loop
+                  if Chars (Identifier (Aspect)) = Name_Unreferenced then
+                     Set_Has_Pragma_Unreferenced (Formal);
+                  else
+                     Error_Msg_NE
+                       ("unsupported aspect& on parameter",
+                        Aspect, Identifier (Aspect));
+                  end if;
+
+                  Next (Aspect);
+               end loop;
+            end;
+         end if;
+
       <<Continue>>
          Next (Param_Spec);
       end loop;


diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads
--- a/gcc/ada/sinfo.ads
+++ b/gcc/ada/sinfo.ads
@@ -5414,9 +5414,9 @@ package Sinfo is
 
       --  PARAMETER_SPECIFICATION ::=
       --    DEFINING_IDENTIFIER_LIST : [ALIASED] MODE [NULL_EXCLUSION]
-      --      SUBTYPE_MARK [:= DEFAULT_EXPRESSION]
+      --      SUBTYPE_MARK [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATIONS]
       --  | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
-      --      [:= DEFAULT_EXPRESSION]
+      --      [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATIONS]
 
       --  Although the syntax allows multiple identifiers in the list, the
       --  semantics is as though successive specifications were given with


Reply via email to