https://gcc.gnu.org/g:073a51b03ab076928878b1093d403fd1f7621b81

commit r16-8989-g073a51b03ab076928878b1093d403fd1f7621b81
Author: Javier Miranda <[email protected]>
Date:   Wed Jan 21 19:36:30 2026 +0000

    ada: Boolean flag for Unsigned_Base_Range aspect is ignored
    
    Unsigned_Base_Range is erroneously enabled when set to False.
    
    gcc/ada/ChangeLog:
    
            * sem_ch13.adb (Analyze_One_Aspect): For Unsigned_Base_Range aspect,
            skip generating its corresponding pragma when the aspect is set
            to False.
            * sem_ch3.adb (Analyze_Full_Type_Declaration): Fix initialization
            of local variable Is_Unsigned_Base_Range_Type_Decl to handle
            Unsigned_Base_Range aspect set to False.

Diff:
---
 gcc/ada/sem_ch13.adb | 13 ++++++++++---
 gcc/ada/sem_ch3.adb  | 14 ++++++++++++--
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index f2493e53a719..dd54bddf0229 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -3734,7 +3734,7 @@ package body Sem_Ch13 is
                   then
                      Delay_Required := False;
 
-                  --  For Unsigned_Base_Range aspect, do not delay becase we
+                  --  For Unsigned_Base_Range aspect, do not delay because we
                   --  need to process it before any type or subtype derivation
                   --  is analyzed.
 
@@ -5505,10 +5505,17 @@ package body Sem_Ch13 is
                      goto Continue;
 
                   --  GNAT Core Extension: Checks for this aspect are performed
-                  --  when the corresponding pragma is analyzed.
+                  --  when the corresponding pragma is analyzed; if aspect has
+                  --  no effect, pragma generation is skipped.
 
                   elsif A_Id = Aspect_Unsigned_Base_Range then
-                     null;
+                     if Present (Expr) then
+                        Analyze_And_Resolve (Expr, Standard_Boolean);
+
+                        if Is_False (Static_Boolean (Expr)) then
+                           goto Continue;
+                        end if;
+                     end if;
 
                   --  Ada 2022 (AI12-0279)
 
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 390a4f6093d7..327a9ae74832 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -3197,12 +3197,22 @@ package body Sem_Ch3 is
    begin
       if Present (Aspect_Specifications (Parent (Def))) then
          declare
-            Asp : Node_Id;
+            Asp  : Node_Id;
+            Expr : Node_Id;
+
          begin
             Asp := First (Aspect_Specifications (Parent (Def)));
             while Present (Asp) loop
                if Chars (Identifier (Asp)) = Name_Unsigned_Base_Range then
-                  Is_Unsigned_Base_Range_Type_Decl := True;
+                  Expr := Expression (Asp);
+
+                  if Present (Expr) then
+                     Analyze_And_Resolve (Expr, Standard_Boolean);
+                  end if;
+
+                  Is_Unsigned_Base_Range_Type_Decl :=
+                    No (Expression (Asp))
+                      or else Is_True (Static_Boolean (Expr));
                   exit;
                end if;

Reply via email to