From patchwork Sun Feb 20 13:55:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 83729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 8D61AB715A for ; Mon, 21 Feb 2011 00:55:32 +1100 (EST) Received: (qmail 22764 invoked by alias); 20 Feb 2011 13:55:30 -0000 Received: (qmail 22748 invoked by uid 22791); 20 Feb 2011 13:55:29 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, TW_VP X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 20 Feb 2011 13:55:24 +0000 Received: from [192.168.178.22] (port-92-204-54-176.dynamic.qsc.de [92.204.54.176]) by mx01.qsc.de (Postfix) with ESMTP id 3DFC33CB2F; Sun, 20 Feb 2011 14:55:21 +0100 (CET) Message-ID: <4D611D48.7090701@net-b.de> Date: Sun, 20 Feb 2011 14:55:20 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 47797 - Improve line number for debugging Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. 2011-02-20 Tobias Burnus 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);