From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22681 invoked by alias); 30 Nov 2012 13:04:10 -0000 Received: (qmail 22456 invoked by uid 48); 30 Nov 2012 13:03:41 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/55541] [4.6/4.7/4.8 Regression] unable to see local variables due extra lexical block was generated Date: Fri, 30 Nov 2012 13:04:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: debug X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.6.4 X-Bugzilla-Changed-Fields: CC Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg02993.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55541 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jason at gcc dot gnu.org --- Comment #4 from Jakub Jelinek 2012-11-30 13:03:40 UTC --- I've tried to do: --- gcc/cp/decl.c.jj 2012-11-19 14:41:16.000000000 +0100 +++ gcc/cp/decl.c 2012-11-30 12:24:42.255349700 +0100 @@ -13700,7 +13700,27 @@ finish_function (int flags) { /* Make it so that `main' always returns 0 by default. */ if (DECL_MAIN_P (current_function_decl)) - finish_return_stmt (integer_zero_node); + { + /* If there is so far just a single statement, BIND_EXPR + with the whole main function body in it, push + return 0 stmt at the end of its body instead of after + the BIND_EXPR, so that variables declared in the function + scope are still in scope on the return stmt. */ + tree bind = NULL_TREE; + if (TREE_CODE (cur_stmt_list) == STATEMENT_LIST) + { + tree_stmt_iterator i = tsi_start (cur_stmt_list); + if (tsi_one_before_end_p (i) + && TREE_CODE (tsi_stmt (i)) == BIND_EXPR) + { + bind = tsi_stmt (i); + vec_safe_push (stmt_list_stack, BIND_EXPR_BODY (bind)); + } + } + finish_return_stmt (integer_zero_node); + if (bind) + BIND_EXPR_BODY (bind) = stmt_list_stack->pop (); + } if (use_eh_spec_block (current_function_decl)) finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS which makes sure that the return 0; has the right locus (for C99 similar change would be needed), unfortunately it doesn't fix this. Unlike C, the C++ FE creates an extra BLOCK around the BLOCK with BLOCK_VARS i in this case, supposedly for the argument scope, so DECL_INITIAL (current_function_decl) is in C the block with i var, but in C++ a block whose BLOCK_SUBBLOCK is block with i var. While the return stmt with the above patch still has correct block, it seems to be actually completely ignored in the end, because what matters actually is epilogue_location (in 4.7 and earlier epilogue_locator). cfgexpand.c and expand_function_end now set epilogue_location to the input_location, when outside of particular stmt expansion, which doesn't have a block, and I assume that DECL_INITIAL is then used. So the question is, can the C++ FE (when?) get rid of the outermost BLOCK and change DECL_INITIAL (perhaps during genericization or so) to the real function body scope instead.