Bug 43983 - var-tracking needlessly throws away location info for SRAed vars
Summary: var-tracking needlessly throws away location info for SRAed vars
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-04 15:11 UTC by Jakub Jelinek
Modified: 2010-05-13 10:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-05-04 15:12:44


Attachments
gcc46-pr43983.patch (5.48 KB, patch)
2010-05-05 15:22 UTC, Jakub Jelinek
Details | Diff
gcc46-pr43983.patch (5.51 KB, patch)
2010-05-06 08:44 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2010-05-04 15:11:29 UTC
track_expr_p has:
4496  /* If this expression is really a debug alias of some other declaration, we
4497     don't need to track this expression if the ultimate declaration is
4498     ignored.  */
4499  realdecl = expr;
4500  if (DECL_DEBUG_EXPR_IS_FROM (realdecl) && DECL_DEBUG_EXPR (realdecl))
4501    {
4502      realdecl = DECL_DEBUG_EXPR (realdecl);
4503      /* ??? We don't yet know how to emit DW_OP_piece for variable
4504         that has been SRA'ed.  */
4505      if (!DECL_P (realdecl))
4506        return 0;
4507    }

I'd say if the DECL_DEBUG_EXPR is a COMPONENT_REF, ARRAY_REF etc. from a reasonably short type, the easiest thing would be just to let var-tracking track the individual vars and let dwarf2out_var_location assemble them together.
Comment 1 Jakub Jelinek 2010-05-04 15:12:44 UTC
Sample testcase:
struct A { int i; int j; };

int
foo (int k)
{
  struct A a = { 4, k + 6 };
  asm ("" : "+r" (a.i));
  a.j++;
  bar (a.i);
  bar (a.j);
  return a.i + a.j;
}
Comment 2 Jakub Jelinek 2010-05-05 15:22:20 UTC
Created attachment 20563 [details]
gcc46-pr43983.patch

So far only lightly tested patch.
Comment 3 Jakub Jelinek 2010-05-05 19:06:00 UTC
Two issues discovered with the patch.  One is easy:
--- gcc/dwarf2out.c 2010-05-05 17:14:56.000000000 +0200
+++ gcc/dwarf2out.c 2010-05-05 20:51:40.000000000 +0200
@@ -7916,7 +7916,7 @@
                {
                  rtx piece = *piece_loc;
                  diff -= decl_piece_bitsize (piece);
-                 piece_loc = &XEXP (piece, 1);
+                 *piece_loc = XEXP (piece, 1);
                  free_EXPR_LIST_node (piece);
                }
              /* Add padding if needed.  */

The other shows on various libgcc files with -m32 - apparently SRA leaves sometimes the original decl in the IL together with SRAed variables, the patch assumed that either the SRAed variables, or the original appear, but not both.
Comment 4 Richard Biener 2010-05-05 20:02:43 UTC
(In reply to comment #3)
> Two issues discovered with the patch.  One is easy:
> --- gcc/dwarf2out.c 2010-05-05 17:14:56.000000000 +0200
> +++ gcc/dwarf2out.c 2010-05-05 20:51:40.000000000 +0200
> @@ -7916,7 +7916,7 @@
>                 {
>                   rtx piece = *piece_loc;
>                   diff -= decl_piece_bitsize (piece);
> -                 piece_loc = &XEXP (piece, 1);
> +                 *piece_loc = XEXP (piece, 1);
>                   free_EXPR_LIST_node (piece);
>                 }
>               /* Add padding if needed.  */
> 
> The other shows on various libgcc files with -m32 - apparently SRA leaves
> sometimes the original decl in the IL together with SRAed variables, the patch
> assumed that either the SRAed variables, or the original appear, but not both.

It indeed happens on purpose.  We in some cases re-build the aggregate
for aggregate uses.
Comment 5 Jakub Jelinek 2010-05-06 08:44:34 UTC
Created attachment 20578 [details]
gcc46-pr43983.patch

Updated patch that should fix both issues, currently bootstrapping/regtesting it.
Comment 6 Jakub Jelinek 2010-05-13 10:41:19 UTC
Subject: Bug 43983

Author: jakub
Date: Thu May 13 10:40:51 2010
New Revision: 159357

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159357
Log:
	PR debug/43983
	* var-tracking.c (track_expr_p): Allow tracking of variables optimized
	by SRA.
	* Makefile.in (dwarf2out.o): Depend on $(TREE_FLOW_H).
	* tree-sra.c (create_access_replacement): Call unshare_expr before
	passing expr to SET_DECL_DEBUG_EXPR, and remove any SSA_NAMEs from
	it.
	* dwarf2out.c: Include tree-flow.h.
	(struct var_loc_node): Rename var_loc_note field to loc, add comment.
	(size_of_loc_descr, output_loc_operands, output_loc_operands_raw):
	Handle DW_OP_bit_piece.
	(decl_piece_bitsize, decl_piece_varloc_ptr, decl_piece_node,
	construct_piece_list, adjust_piece_list): New functions.
	(add_var_loc_to_decl): Handle SRA optimized variables.
	Adjust for var_loc_note to loc field renaming.
	(dw_loc_list_1): For WANT_ADDRESS == 2 prefer DECL_MODE of decl
	in VAR_LOCATION note.
	(new_loc_descr_op_bit_piece): New function.
	(dw_sra_loc_expr): New function.
	(dw_loc_list): Use it.  Don't handle the last range after the
	loop, handle it inside of the loop.  Adjust for var_loc_note
	to loc field renaming.
	(add_location_or_const_value_attribute): Only special case
	single entry loc lists if loc is NOTE_P.  Adjust for
	var_loc_note to loc field renaming.
	(dwarf2out_var_location): Don't set newloc->var_loc_note
	and newloc->next here.

	* gcc.dg/guality/sra-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/guality/sra-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-sra.c
    trunk/gcc/var-tracking.c

Comment 7 Jakub Jelinek 2010-05-13 10:53:02 UTC
Fixed.