From patchwork Mon Aug 16 20:45:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Fix up Fortran line numbers (PR fortran/45186) Date: Mon, 16 Aug 2010 10:45:38 -0000 From: Jakub Jelinek X-Patchwork-Id: 61839 Message-Id: <20100816204538.GB702@tyan-ft48-01.lab.bos.redhat.com> To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Hi! As discussed on IRC and in the PR, this patch fixes Fortran line info by basically going back to what GCC 4.4 did. The FE doesn't pass input_location to all the various build*/fold_build*/build*_v functions/macros when it creates the trees, there are more than 1000 of such places. Ok for 4.5 (for which changing those 1000 places isn't really desirable)? What about 4.6? Bootstrapped/regtested on x86_64-linux and i686-linux. 2010-08-16 Jakub Jelinek PR fortran/45186 * trans.c (gfc_annotate_with_location): New function. (trans_code): Use it. Jakub --- gcc/fortran/trans.c.jj 2010-08-11 21:08:00.000000000 +0200 +++ gcc/fortran/trans.c 2010-08-16 12:37:45.000000000 +0200 @@ -1055,6 +1055,29 @@ gfc_set_backend_locus (locus * loc) input_location = loc->lb->location; } +/* Annotate statement or statement list T with location LOC. */ + +static void +gfc_annotate_with_location (tree t, location_t loc) +{ + if (TREE_CODE (t) == STATEMENT_LIST) + { + tree_stmt_iterator i; + + for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i)) + gfc_annotate_with_location (tsi_stmt (i), loc); + return; + } + if (TREE_CODE (t) == COMPOUND_EXPR) + { + gfc_annotate_with_location (TREE_OPERAND (t, 0), loc); + gfc_annotate_with_location (TREE_OPERAND (t, 1), loc); + } + if (TREE_CODE (t) == LABEL_EXPR || !TREE_SIDE_EFFECTS (t)) + return; + if (CAN_HAVE_LOCATION_P (t) && ! EXPR_HAS_LOCATION (t)) + SET_EXPR_LOCATION (t, loc); +} /* Translate an executable statement. The tree cond is used by gfc_trans_do. This static function is wrapped by gfc_trans_code_cond and @@ -1312,9 +1335,8 @@ trans_code (gfc_code * code, tree cond) if (res != NULL_TREE && ! IS_EMPTY_STMT (res)) { - if (TREE_CODE (res) != STATEMENT_LIST) - SET_EXPR_LOCATION (res, input_location); - + gfc_annotate_with_location (res, input_location); + /* Add the new statement to the block. */ gfc_add_expr_to_block (&block, res); }