From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4979 invoked by alias); 7 Jan 2007 21:21:22 -0000 Received: (qmail 4971 invoked by uid 22791); 7 Jan 2007 21:21:21 -0000 X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 07 Jan 2007 21:21:13 +0000 Received: from localhost (occam.ms.mff.cuni.cz [195.113.18.121]) by nikam.ms.mff.cuni.cz (Postfix) with ESMTP id 02A365BA8D for ; Sun, 7 Jan 2007 22:21:10 +0100 (CET) Received: by localhost (Postfix, from userid 16202) id 0010B94ABE; Sun, 7 Jan 2007 22:21:09 +0100 (CET) Date: Sun, 07 Jan 2007 21:21:00 -0000 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix inliner versus nested functions and arrays of variable lengths Message-ID: <20070107212109.GD9578@kam.mff.cuni.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.9i 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 X-SW-Source: 2007-01/txt/msg00522.txt.bz2 Hi, Razya run into problem with her IPCP merge. In one of testsuite testcases there is nested function that refers variable of outer function. That vairable is declared as variably sized array. Doing this triggers interesting events leading to ICE While duplicating the type we recurse on TYPE_SIZE parameter in remap_type: walk_tree (&TYPE_SIZE (new), copy_body_r, id, NULL); walk_tree (&TYPE_SIZE_UNIT (new), copy_body_r, id, NULL); This is correct in general, since we need to replace variables in the case they are function local vairables. copy_body_r adds all variables it sees to to referenced vars: /* Global variables we didn't seen yet needs to go into referenced vars. */ if (gimple_in_ssa_p (cfun) && TREE_CODE (*tp) == VAR_DECL) add_referenced_var (*tp); This is targeted to global variables not referenced by the function we inline into as documented in the comment, however in this case tree unnesting code keeps the type of variable in nested function to refer into varibale of outer function (I think this is correct and I wasn't able to reproduce problem by sizeof or something that is properly lowered). However now inliner adds this variable as referenced. This leads to delete_ssa while compiling the clone of nested function to clear annotation of the variable of outer function and we finally die when compiling the outer function. The attached patch solve the problem by teaching copy_body_r to just add referenced vars that are either global or local to function. It is sort of symptomatic fix I would say, but I don't see how to fix it better. Except perhaps making tree inliner to simply map inner function referenced vars list into outer function referenced vars list and not doing it within copy_body_r. This in general is less friendly to the fact that we eliminate some vars during inlining. Honza Bootstrapped/regtested i686-linux :ADDPATCH tree-optimization: * tree-inline.c (copy_body_r): Do not add local variables of other functions. Index: tree-inline.c =================================================================== --- tree-inline.c (revision 120528) +++ tree-inline.c (working copy) @@ -691,7 +691,9 @@ copy_body_r (tree *tp, int *walk_subtree /* Global variables we didn't seen yet needs to go into referenced vars. */ - if (gimple_in_ssa_p (cfun) && TREE_CODE (*tp) == VAR_DECL) + if (gimple_in_ssa_p (cfun) && TREE_CODE (*tp) == VAR_DECL + && (is_global_var (*tp) + || decl_function_context (*tp) == current_function_decl)) add_referenced_var (*tp); /* If EXPR has block defined, map it to newly constructed block.