]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Make pp and friends more robust
authorBob Duff <duff@adacore.com>
Wed, 23 Jul 2025 18:46:13 +0000 (14:46 -0400)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 4 Aug 2025 13:04:11 +0000 (15:04 +0200)
Print_Node_Ref, which is called by pp, sometimes calls
Compile_Time_Known_Value, which blows up if Entity (N)
is empty. Rearrange the tests here, and test for
Present (Entity (N)) before calling Compile_Time_Known_Value.
Remove test "Nkind (N) in N_Subexpr", which is redundant with other
tests.

We don't want to make Compile_Time_Known_Value more
robust; you shouldn't call it on half-baked nodes.
But ideally pp should be able to print such nodes.

This change fixes one of many such cases.

gcc/ada/ChangeLog:

* treepr.adb (Print_Node_Ref): Protect against
Entity (N) being empty before calling
Compile_Time_Known_Value.

gcc/ada/treepr.adb

index 375608d2ba66c5f40a745b71dbb869a81d8d4ec3..857b9263f01245d78cb8297c8c81b69a6fd380fa 100644 (file)
@@ -1600,19 +1600,17 @@ package body Treepr is
          --  If this is a discrete expression whose value is known, print that
          --  value.
 
-         if Nkind (N) in N_Subexpr
+         if ((Is_Entity_Name (N) -- e.g. enumeration literal
+               and then Present (Entity (N)))
+              or else Nkind (N) in N_Integer_Literal
+                                 | N_Character_Literal
+                                 | N_Unchecked_Type_Conversion)
            and then Compile_Time_Known_Value (N)
            and then Present (Etype (N))
            and then Is_Discrete_Type (Etype (N))
          then
-            if Is_Entity_Name (N) -- e.g. enumeration literal
-              or else Nkind (N) in N_Integer_Literal
-                                 | N_Character_Literal
-                                 | N_Unchecked_Type_Conversion
-            then
-               Print_Str (" val = ");
-               UI_Write (Expr_Value (N));
-            end if;
+            Print_Str (" val = ");
+            UI_Write (Expr_Value (N));
          end if;
 
          if Nkind (N) in N_Entity then