]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Spurious elaboration warnings with -gnatc and null procedures
authorArnaud Charlet <charlet@adacore.com>
Sat, 9 May 2020 17:37:13 +0000 (13:37 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 7 Jul 2020 09:26:53 +0000 (05:26 -0400)
gcc/ada/

* sem_elab.adb (Is_Guaranteed_ABE): Take into account null
procedures.

gcc/ada/sem_elab.adb

index 50f0feb4b8258962f527b5ed5222a9d3663712de..e17e927eec4170855201d5dd8ce65d0c2dcd70db 100644 (file)
@@ -9246,6 +9246,7 @@ package body Sem_Elab is
          Target_Decl : Node_Id;
          Target_Body : Node_Id) return Boolean
       is
+         Spec : Node_Id;
       begin
          --  Avoid cascaded errors if there were previous serious infractions.
          --  As a result the scenario will not be treated as a guaranteed ABE.
@@ -9266,12 +9267,20 @@ package body Sem_Elab is
                return Earlier_In_Extended_Unit (N, Target_Body);
 
             --  Otherwise the body has not been encountered yet. The scenario
-            --  is a guaranteed ABE since the body will appear later. It is
-            --  assumed that the caller has already ensured that the scenario
-            --  is ABE-safe because optional bodies are not considered here.
+            --  is a guaranteed ABE since the body will appear later, unless
+            --  this is a null specification, which can occur if expansion is
+            --  disabled (e.g. -gnatc or GNATprove mode). It is assumed that
+            --  the caller has already ensured that the scenario is ABE-safe
+            --  because optional bodies are not considered here.
 
             else
-               return True;
+               Spec := Specification (Target_Decl);
+
+               if Nkind (Spec) /= N_Procedure_Specification
+                 or else not Null_Present (Spec)
+               then
+                  return True;
+               end if;
             end if;
          end if;
 
@@ -9574,7 +9583,7 @@ package body Sem_Elab is
                Error_Msg_N ("\Program_Error will be raised at run time", Call);
             end if;
 
-            --  Mark the call as a guarnateed ABE
+            --  Mark the call as a guaranteed ABE
 
             Set_Is_Known_Guaranteed_ABE (Call);