]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix resolution of assertion levels
authorViljar Indus <indus@adacore.com>
Wed, 30 Jul 2025 07:32:52 +0000 (10:32 +0300)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 9 Sep 2025 12:39:52 +0000 (14:39 +0200)
Unsuccessful preanalyze_and_resolve still marks identifiers as Any_Id.
Override that result if an identifier matched an assertion level.

gcc/ada/ChangeLog:

* ghost.adb (Assertion_Level_From_Arg): Ensure that assertion level
is stored as the entity for its reference.
(Enables_Ghostness): Derive the result from whether or not the
an argument indicated an assertion level.
* tbuild.adb (Make_Assertion_Level): ensure that assertion levels
have a standard scope.

gcc/ada/ghost.adb
gcc/ada/tbuild.adb

index 4af4e4be93e05031ad8e38855c45ef199fbee952..574f7f2cda407d9317e1f86f90ce17b12a635392 100644 (file)
@@ -161,11 +161,13 @@ package body Ghost is
 
       --  Alternatively the argument could be an Assertion_Level
 
-      if Nkind (Expr) = N_Identifier
-        and then Present (Get_Assertion_Level (Chars (Expr)))
-      then
+      if Nkind (Expr) = N_Identifier then
          Level := Get_Assertion_Level (Chars (Expr));
          if Present (Level) then
+            --  The identifier resolved to an assertion level. Override the
+            --  Any_Id from a failed resolution in pre-analysis.
+
+            Set_Entity (Expr, Level);
             return Level;
          end if;
       end if;
@@ -1774,31 +1776,11 @@ package body Ghost is
       -----------------------
 
       function Enables_Ghostness (Arg : Node_Id) return Boolean is
-         Expr : constant Node_Id := Get_Pragma_Arg (Arg);
-
       begin
-         --  Aspect Ghost without an expression enables ghostness
-
-         if No (Expr) then
-            return True;
-         end if;
+         --  Ghostness is enabled if the argument implies a default assertion
+         --  level or it is explicitly a reference to an assertion level.
 
-         --  Check if the expression matches a static boolean expression first
-
-         Preanalyze_And_Resolve_Without_Errors (Expr);
-         if Is_OK_Static_Expression (Expr) then
-            return Is_True (Expr_Value (Expr));
-         end if;
-
-         --  Alternatively the argument could be an Assertion_Level
-
-         if Nkind (Expr) = N_Identifier
-           and then Present (Get_Assertion_Level (Chars (Expr)))
-         then
-            return True;
-         end if;
-
-         return False;
+         return Present (Assertion_Level_From_Arg (Arg));
       end Enables_Ghostness;
 
       --  Local variables
index 57ea93260f13c66ea2e35d9db395e41dcb73aa4b..2840707f2e93d7f0f3cbf7e3b2e12dc5129320ad 100644 (file)
@@ -162,6 +162,7 @@ package body Tbuild is
    begin
       Mutate_Ekind (Level, E_Assertion_Level);
       Set_Etype (Level, Standard_Void_Type);
+      Set_Scope (Level, Standard_Standard);
       return Level;
    end Make_Assertion_Level;