From 650ad524d8a5928998037c1f6434054d46a400d4 Mon Sep 17 00:00:00 2001 From: Bob Duff Date: Wed, 11 Aug 2021 07:44:31 -0400 Subject: [PATCH] [Ada] Fix latent bug in set_end_locus_from_node gcc/ada/ * gcc-interface/trans.c (set_end_locus_from_node): Check that Handled_Statement_Sequence is not Empty before calling End_Label, because the Empty node has no End_Label, and depending on the exact node layout chosen by gen_il, calling End_Label might crash, or might work OK by accident. --- gcc/ada/gcc-interface/trans.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 158bfe35f7b..4aaa567237c 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -10507,10 +10507,15 @@ set_end_locus_from_node (tree gnu_node, Node_Id gnat_node) case N_Package_Body: case N_Subprogram_Body: case N_Block_Statement: - gnat_end_label = End_Label (Handled_Statement_Sequence (gnat_node)); + if (Present (Handled_Statement_Sequence (gnat_node))) + gnat_end_label = End_Label (Handled_Statement_Sequence (gnat_node)); + else + gnat_end_label = Empty; + break; case N_Package_Declaration: + gcc_checking_assert (Present (Specification (gnat_node))); gnat_end_label = End_Label (Specification (gnat_node)); break;