https://gcc.gnu.org/g:b0e249afc68917375d5117ff674f80aeb93d051c
commit r16-2756-gb0e249afc68917375d5117ff674f80aeb93d051c Author: Bob Duff <d...@adacore.com> Date: Wed Jul 23 14:46:13 2025 -0400 ada: Make pp and friends more robust 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. Diff: --- gcc/ada/treepr.adb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/gcc/ada/treepr.adb b/gcc/ada/treepr.adb index 375608d2ba66..857b9263f012 100644 --- a/gcc/ada/treepr.adb +++ b/gcc/ada/treepr.adb @@ -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