public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [Ada] Fix problematic line debug info attached to call to finalizer
Date: Tue, 6 Sep 2022 09:16:05 +0200	[thread overview]
Message-ID: <20220906071605.GA1280575@poulhies-Precision-5550> (raw)

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

The End_Label is not defined for body nodes so a small tweak is needed.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* gcc-interface/trans.cc (At_End_Proc_to_gnu): Use the End_Label of
	the child Handled_Statement_Sequence for body nodes.
	(set_end_locus_from_node): Minor tweaks.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2171 bytes --]

diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc
--- a/gcc/ada/gcc-interface/trans.cc
+++ b/gcc/ada/gcc-interface/trans.cc
@@ -3806,18 +3806,27 @@ static void
 At_End_Proc_to_gnu (Node_Id gnat_node)
 {
   tree proc_decl = gnat_to_gnu (At_End_Proc (gnat_node));
+  Node_Id gnat_end_label;
 
   /* When not optimizing, disable inlining of finalizers as this can
      create a more complex CFG in the parent function.  */
   if (!optimize || optimize_debug)
     DECL_DECLARED_INLINE_P (proc_decl) = 0;
 
+  /* Retrieve the end label attached to the node, if any.  */
+  if (Nkind (gnat_node) == N_Handled_Sequence_Of_Statements)
+    gnat_end_label = End_Label (gnat_node);
+  else if (Present (Handled_Statement_Sequence (gnat_node)))
+    gnat_end_label = End_Label (Handled_Statement_Sequence (gnat_node));
+  else
+    gnat_end_label = Empty;
+
   /* If there is no end label attached, we use the location of the At_End
      procedure because Expand_Cleanup_Actions might reset the location of
-      the enclosing construct to that of an inner statement.  */
+     the enclosing construct to that of an inner statement.  */
   add_cleanup (build_call_n_expr (proc_decl, 0),
-	       Present (End_Label (gnat_node))
-	       ? End_Label (gnat_node) : At_End_Proc (gnat_node));
+	       Present (gnat_end_label)
+	       ? gnat_end_label : At_End_Proc (gnat_node));
 }
 
 /* Subroutine of gnat_to_gnu to translate GNAT_NODE, an N_Subprogram_Body.  */
@@ -10418,7 +10427,6 @@ set_end_locus_from_node (tree gnu_node, Node_Id gnat_node)
 	gnat_end_label = End_Label (Handled_Statement_Sequence (gnat_node));
       else
 	gnat_end_label = Empty;
-
       break;
 
     case N_Package_Declaration:
@@ -10439,7 +10447,7 @@ set_end_locus_from_node (tree gnu_node, Node_Id gnat_node)
      transient block does not receive the sloc of a source condition.  */
   if (!Sloc_to_locus (Sloc (gnat_node), &end_locus,
                       No (gnat_end_label)
-                      && (Nkind (gnat_node) == N_Block_Statement)))
+                      && Nkind (gnat_node) == N_Block_Statement))
     return false;
 
   switch (TREE_CODE (gnu_node))



                 reply	other threads:[~2022-09-06  7:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220906071605.GA1280575@poulhies-Precision-5550 \
    --to=poulhies@adacore.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).