From: Bob Duff <[email protected]>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
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 375608d2ba6..857b9263f01 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
--
2.43.0