From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29455 invoked by alias); 9 May 2014 08:24:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 29445 invoked by uid 89); 9 May 2014 08:24:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 09 May 2014 08:24:49 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id F0E3327431BD for ; Fri, 9 May 2014 10:24:45 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yVNBdu7nCrP8 for ; Fri, 9 May 2014 10:24:45 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id CED4B2743105 for ; Fri, 9 May 2014 10:24:45 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Partially fix PR debug/53927 Date: Fri, 09 May 2014 08:24:00 -0000 Message-ID: <2528882.lo01QYvzOj@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.29-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3847697.fsbY08g8xX" Content-Transfer-Encoding: 7Bit X-SW-Source: 2014-05/txt/msg00573.txt.bz2 --nextPart3847697.fsbY08g8xX Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Content-length: 700 Hi, this makes sure we always generate a static chain for nested functions at -O0 and force it onto the stack in this case so that DW_AT_static_link is always meaningful (but not necessarily fully correct, see the audit trail). FWIW this has been done for years in AdaCore's compilers. Tested on x86_64-suse-linux, OK for the mainline? 2014-05-09 Eric Botcazou PR debug/53927 * function.c (instantiate_decls): Process the saved static chain. (expand_function_start): If not optimizing, save the static chain onto the stack. * tree-nested.c (convert_all_function_calls): Always create the static chain for nested functions if not optimizing. -- Eric Botcazou --nextPart3847697.fsbY08g8xX Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="p.diff" Content-length: 2451 Index: function.c =================================================================== --- function.c (revision 210256) +++ function.c (working copy) @@ -1872,6 +1872,11 @@ instantiate_decls (tree fndecl) } } + /* Process the saved static chain if it exists. */ + decl = DECL_STRUCT_FUNCTION (fndecl)->static_chain_decl; + if (decl && DECL_HAS_VALUE_EXPR_P (decl)) + instantiate_decl_rtl (DECL_RTL (DECL_VALUE_EXPR (decl))); + /* Now process all variables defined in the function or its subblocks. */ instantiate_decls_1 (DECL_INITIAL (fndecl)); @@ -4805,6 +4810,20 @@ expand_function_start (tree subr) if (MEM_P (chain) && reg_mentioned_p (arg_pointer_rtx, XEXP (chain, 0))) set_dst_reg_note (insn, REG_EQUIV, chain, local); + + /* If we aren't optimizing, save the static chain onto the stack. */ + if (!optimize) + { + tree saved_static_chain_decl + = build_decl (DECL_SOURCE_LOCATION (parm), VAR_DECL, + DECL_NAME (parm), TREE_TYPE (parm)); + rtx saved_static_chain_rtx + = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0); + SET_DECL_RTL (saved_static_chain_decl, saved_static_chain_rtx); + emit_move_insn (saved_static_chain_rtx, chain); + SET_DECL_VALUE_EXPR (parm, saved_static_chain_decl); + DECL_HAS_VALUE_EXPR_P (parm) = 1; + } } /* If the function receives a non-local goto, then store the Index: tree-nested.c =================================================================== --- tree-nested.c (revision 210256) +++ tree-nested.c (working copy) @@ -2218,11 +2218,21 @@ convert_all_function_calls (struct nesti struct nesting_info *n; /* First, optimistically clear static_chain for all decls that haven't - used the static chain already for variable access. */ + used the static chain already for variable access. But always create + it if not optimizing. This makes it possible to reconstruct the static + nesting tree at run time and thus to resolve up-level references from + within the debugger. */ FOR_EACH_NEST_INFO (n, root) { tree decl = n->context; - if (!n->outer || (!n->chain_decl && !n->chain_field)) + if (!optimize) + { + if (n->inner) + (void) get_frame_type (n); + if (n->outer) + (void) get_chain_decl (n); + } + else if (!n->outer || (!n->chain_decl && !n->chain_field)) { DECL_STATIC_CHAIN (decl) = 0; if (dump_file && (dump_flags & TDF_DETAILS)) --nextPart3847697.fsbY08g8xX--