]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix expansion of structural subprogram variants
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 27 Apr 2022 15:30:59 +0000 (17:30 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 30 May 2022 08:29:04 +0000 (08:29 +0000)
When implementing structural subprogram variants we ignored them in
expansion of the pragma itself, but not in expansion of a recursive
subprogram call. Now fixed.

gcc/ada/

* exp_ch6.adb (Check_Subprogram_Variant): Ignore structural
variants.

gcc/ada/exp_ch6.adb

index 44d198798c64b77f74d559e075bfdd8e0d890e45..7d507271428993d1c58bafb1db361375271e0435 100644 (file)
@@ -3298,19 +3298,33 @@ package body Exp_Ch6 is
          Variant_Prag : constant Node_Id :=
            Get_Pragma (Current_Scope, Pragma_Subprogram_Variant);
 
+         Pragma_Arg1  : Node_Id;
          Variant_Proc : Entity_Id;
 
       begin
          if Present (Variant_Prag) and then Is_Checked (Variant_Prag) then
 
-            --  Analysis of the pragma rewrites its argument with a reference
-            --  to the internally generated procedure.
+            Pragma_Arg1 :=
+              Expression (First (Pragma_Argument_Associations (Variant_Prag)));
 
-            Variant_Proc :=
-              Entity
-                (Expression
-                   (First
-                      (Pragma_Argument_Associations (Variant_Prag))));
+            --  If pragma parameter is still an aggregate, it comes from a
+            --  structural variant, which is not expanded and ignored for
+            --  run-time execution.
+
+            if Nkind (Pragma_Arg1) = N_Aggregate then
+               pragma Assert
+                 (Chars
+                    (First
+                      (Choices
+                         (First (Component_Associations (Pragma_Arg1))))) =
+                  Name_Structural);
+               return;
+            end if;
+
+            --  Otherwise, analysis of the pragma rewrites its argument with a
+            --  reference to the internally generated procedure.
+
+            Variant_Proc := Entity (Pragma_Arg1);
 
             Insert_Action (Call_Node,
               Make_Procedure_Call_Statement (Loc,