From patchwork Mon Aug 30 16:32:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Fix incorrect scope for OUT parameters From: Eric Botcazou X-Patchwork-Id: 63071 Message-Id: <201008301832.12015.ebotcazou@adacore.com> To: gcc-patches@gcc.gnu.org Date: Mon, 30 Aug 2010 18:32:11 +0200 Scalar OUT parameters aren't translated into real parameters of procedures, but rather into local variables. Yet we generate DW_TAG_formal_parameter in DWARF for them by means of a trick. Recent improvements in the debug info show that we generate them in an incorrect scope. Tested on x86-64-suse-linux, applied on the mainline and the 4.5 branch. 2010-08-30 Eric Botcazou * gcc-interface/utils.c (gnat_pushdecl): Remove test for PARM_DECLs. Attach fake PARM_DECLs to the topmost block of the function. Index: gcc-interface/utils.c =================================================================== --- gcc-interface/utils.c (revision 163646) +++ gcc-interface/utils.c (working copy) @@ -418,11 +418,8 @@ gnat_poplevel (void) void gnat_pushdecl (tree decl, Node_Id gnat_node) { - /* If this decl is public external or at toplevel, there is no context. - But PARM_DECLs always go in the level of its function. */ - if (TREE_CODE (decl) != PARM_DECL - && ((DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)) - || global_bindings_p ())) + /* If this decl is public external or at toplevel, there is no context. */ + if ((TREE_PUBLIC (decl) && DECL_EXTERNAL (decl)) || global_bindings_p ()) DECL_CONTEXT (decl) = 0; else { @@ -461,8 +458,14 @@ gnat_pushdecl (tree decl, Node_Id gnat_n } else { - DECL_CHAIN (decl) = BLOCK_VARS (current_binding_level->block); - BLOCK_VARS (current_binding_level->block) = decl; + tree block; + /* Fake PARM_DECLs go into the topmost block of the function. */ + if (TREE_CODE (decl) == PARM_DECL) + block = BLOCK_SUPERCONTEXT (current_binding_level->block); + else + block = current_binding_level->block; + DECL_CHAIN (decl) = BLOCK_VARS (block); + BLOCK_VARS (block) = decl; } } @@ -1878,9 +1881,7 @@ end_subprog_body (tree body) { tree fndecl = current_function_decl; - /* Mark the BLOCK for this level as being for this function and pop the - level. Since the vars in it are the parameters, clear them. */ - BLOCK_VARS (current_binding_level->block) = NULL_TREE; + /* Attach the BLOCK for this level to the function and pop the level. */ BLOCK_SUPERCONTEXT (current_binding_level->block) = fndecl; DECL_INITIAL (fndecl) = current_binding_level->block; gnat_poplevel ();