]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Boolean flag for Unsigned_Base_Range aspect is ignored
authorJavier Miranda <miranda@adacore.com>
Wed, 21 Jan 2026 19:36:30 +0000 (19:36 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 26 May 2026 08:38:17 +0000 (10:38 +0200)
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.

gcc/ada/sem_ch13.adb
gcc/ada/sem_ch3.adb

index 158bdb1c516614c0d512eab5844bf82519e6f13b..eb4f05b20719a89a74c9e3a96d26313dd1858d6f 100644 (file)
@@ -3780,7 +3780,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.
 
@@ -5646,10 +5646,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)
 
index e726abad476009f6ea8229aa79c7831d294c138e..6adc627b48a319686ac4020a9997010dfcc20667 100644 (file)
@@ -3193,12 +3193,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;