diff mbox

[Fortran] PR 47797 - Improve line number for debugging

Message ID 4D611D48.7090701@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Feb. 20, 2011, 1:55 p.m. UTC
For a local variable such as
    character(len=:), allocatable :: str2
the code for generating the initial nullifying (and the final 
deallocation) happens at the end of procedures, thus input_location 
points to the last line.

This leads to strange locations if one does debugging. Before the patch, 
one has:

   character(kind=1)[1:3] * str2;

   [test.f90 : 6] try
     {
       [test.f90 : 6] str2 = 0B; /* This is the break point.  */
       [test.f90 : 4] [test.f90 : 4] __builtin_memcpy /* str1 = '1234'. */


With the patch:

   [hj4.f90 : 6] try
     {
       [hj4.f90 : 3] str2 = 0B;
       [hj4.f90 : 4] [hj4.f90 : 4] __builtin_memcpy ...


Build and currently regtesting on x86-64-linux.
OK for the trunk?

Tobias

PS: I have not tested all combinations; I think there is room for 
improvement and I hope that I have not introduced location regressions.

Comments

Jerry DeLisle Feb. 20, 2011, 8:20 p.m. UTC | #1
On 02/20/2011 05:55 AM, Tobias Burnus wrote:
> For a local variable such as
> character(len=:), allocatable :: str2
> the code for generating the initial nullifying (and the final deallocation)
> happens at the end of procedures, thus input_location points to the last line.
>
> This leads to strange locations if one does debugging. Before the patch, one has:
>
> character(kind=1)[1:3] * str2;
>
> [test.f90 : 6] try
> {
> [test.f90 : 6] str2 = 0B; /* This is the break point. */
> [test.f90 : 4] [test.f90 : 4] __builtin_memcpy /* str1 = '1234'. */
>
>
> With the patch:
>
> [hj4.f90 : 6] try
> {
> [hj4.f90 : 3] str2 = 0B;
> [hj4.f90 : 4] [hj4.f90 : 4] __builtin_memcpy ...
>
>
> Build and currently regtesting on x86-64-linux.
> OK for the trunk?
>
> Tobias
>
> PS: I have not tested all combinations; I think there is room for improvement
> and I hope that I have not introduced location regressions.

I hope so too.  OK for Trunk.

Jerry
diff mbox

Patch

2011-02-20  Tobias Burnus  <burnus@net-b.de>

	PR fortran/47797
	* trans-decl.c (gfc_trans_deferred_vars): Use gfc_set_backend_locus and
	gfc_restore_backend_locus to have better debug locations.
	* trans-array.c (gfc_trans_deferred_array): Ditto.

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 83f0189..4e901f2 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -7156,6 +7156,8 @@  gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
 		 "allocatable attribute or derived type without allocatable "
 		 "components.");
 
+  gfc_save_backend_locus (&loc);
+  gfc_set_backend_locus (&sym->declared_at);
   gfc_init_block (&init);
 
   gcc_assert (TREE_CODE (sym->backend_decl) == VAR_DECL
@@ -7172,11 +7174,10 @@  gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
   if (sym->attr.dummy || sym->attr.use_assoc || sym->attr.result)
     {
       gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
+      gfc_restore_backend_locus (&loc);
       return;
     }
 
-  gfc_save_backend_locus (&loc);
-  gfc_set_backend_locus (&sym->declared_at);
   descriptor = sym->backend_decl;
 
   /* Although static, derived types with default initializers and
@@ -7225,8 +7226,8 @@  gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
   if (GFC_DESCRIPTOR_TYPE_P (type) && !sym->attr.save)
     gfc_conv_descriptor_data_set (&init, descriptor, null_pointer_node);
 
-  gfc_init_block (&cleanup);
   gfc_restore_backend_locus (&loc);
+  gfc_init_block (&cleanup);
 
   /* Allocatable arrays need to be freed when they go out of scope.
      The allocatable components of pointers must not be touched.  */
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 793b262..a4d399e 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -3278,6 +3298,8 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 	  if (proc_sym->ts.deferred)
 	    {
 	      tmp = NULL;
+	      gfc_save_backend_locus (&loc);
+	      gfc_set_backend_locus (&proc_sym->declared_at);
 	      gfc_start_block (&init);
 	      /* Zero the string length on entry.  */
 	      gfc_add_modify (&init, proc_sym->ts.u.cl->backend_decl,
@@ -3292,6 +3314,7 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 	      gfc_add_modify (&init, tmp,
 			      fold_convert (TREE_TYPE (se.expr),
 					    null_pointer_node));
+	      gfc_restore_backend_locus (&loc);
 
 	      /* Pass back the string length on exit.  */
 	      tmp = proc_sym->ts.u.cl->passed_length;
@@ -3313,7 +3336,10 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
   /* Initialize the INTENT(OUT) derived type dummy arguments.  This
      should be done here so that the offsets and lbounds of arrays
      are available.  */
+  gfc_save_backend_locus (&loc);
+  gfc_set_backend_locus (&proc_sym->declared_at);
   init_intent_out_dt (proc_sym, block);
+  gfc_restore_backend_locus (&loc);
 
   for (sym = proc_sym->tlink; sym != proc_sym; sym = sym->tlink)
     {
@@ -3332,7 +3358,12 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 	      else if (sym->attr.pointer || sym->attr.allocatable)
 		{
 		  if (TREE_STATIC (sym->backend_decl))
-		    gfc_trans_static_array_pointer (sym);
+		    {
+		      gfc_save_backend_locus (&loc);
+		      gfc_set_backend_locus (&sym->declared_at);
+		      gfc_trans_static_array_pointer (sym);
+		      gfc_restore_backend_locus (&loc);
+		    }
 		  else
 		    {
 		      seen_trans_deferred_array = true;
@@ -3341,6 +3372,9 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 		}
 	      else
 		{
+		  gfc_save_backend_locus (&loc);
+		  gfc_set_backend_locus (&sym->declared_at);
+
 		  if (sym_has_alloc_comp)
 		    {
 		      seen_trans_deferred_array = true;
@@ -3358,8 +3392,6 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 					    NULL_TREE);
 		    }
 
-		  gfc_save_backend_locus (&loc);
-		  gfc_set_backend_locus (&sym->declared_at);
 		  gfc_trans_auto_array_allocation (sym->backend_decl,
 						   sym, block);
 		  gfc_restore_backend_locus (&loc);
@@ -3411,6 +3443,8 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 	      gfc_conv_expr (&se, e);
 	      gfc_free_expr (e);
 
+	      gfc_save_backend_locus (&loc);
+	      gfc_set_backend_locus (&sym->declared_at);
 	      gfc_start_block (&init);
 
 	      if (!sym->attr.dummy || sym->attr.intent == INTENT_OUT)
@@ -3437,6 +3471,8 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 		  else
 		    gfc_add_modify (&init, sym->ts.u.cl->backend_decl, tmp);
 
+		  gfc_restore_backend_locus (&loc);
+
 		  /* Pass the final character length back.  */
 		  if (sym->attr.intent != INTENT_IN)
 		    tmp = fold_build2_loc (input_location, MODIFY_EXPR,
@@ -3445,6 +3481,8 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 		  else
 		    tmp = NULL_TREE;
 		}
+	      else
+		gfc_restore_backend_locus (&loc);
 
 	      /* Deallocate when leaving the scope. Nullifying is not
 		 needed.  */
@@ -3457,6 +3495,9 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 		  /* Initialize _vptr to declared type.  */
 		  gfc_symbol *vtab = gfc_find_derived_vtab (sym->ts.u.derived);
 		  tree rhs;
+
+		  gfc_save_backend_locus (&loc);
+		  gfc_set_backend_locus (&sym->declared_at);
 		  e = gfc_lval_expr_from_sym (sym);
 		  gfc_add_vptr_component (e);
 		  gfc_init_se (&se, NULL);
@@ -3466,6 +3507,7 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 		  rhs = gfc_build_addr_expr (TREE_TYPE (se.expr),
 					     gfc_get_symbol_decl (vtab));
 		  gfc_add_modify (&init, se.expr, rhs);
+		  gfc_restore_backend_locus (&loc);
 		}
 
 	      gfc_add_init_cleanup (block, gfc_finish_block (&init), tmp);