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.
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; }
Created attachment 20563 [details] gcc46-pr43983.patch So far only lightly tested patch.
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.
(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.
Created attachment 20578 [details] gcc46-pr43983.patch Updated patch that should fix both issues, currently bootstrapping/regtesting it.
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
Fixed.