From patchwork Mon Apr 25 13:22:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 614463 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qtn3b700jz9t60 for ; Mon, 25 Apr 2016 23:23:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=JZMjH9DY; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=uWmF5qWpfZx7iABMr2XlCpNTOR5cTFeUQdR44WngnX+pPhBGrb/0Q guZtNnI7Gr4uCfXvE0969wIeQie6fS/wnKhjs9CB7raMi7TxKtKTBbSaIRCWxXR6 LM8/gQYNPrn69OdlEwpPt8/vTt7viQj0tvluo2U7S8Jr8Nzv5Z9a6A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=Aybyyka0gQWXQ5vwIYhejCZ8pM8=; b=JZMjH9DYQ0EMmclsIkQ8 6DipzZV01NcST+qq43QwWtSL5JbFnj1sZPOnpIRhhbBf/cTlE59DRQS3uwGWwvZx Z9OZcq67sNKxlmSct73E9d3fHNyP9VDEN2yBdkG22jn0LPfbJxnbe+1G7SFYYqDV DDOTv4K6nV9v8GFli9JR82s= Received: (qmail 111409 invoked by alias); 25 Apr 2016 13:23:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 111380 invoked by uid 89); 25 Apr 2016 13:23:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=bases, SSA_NAME_VAR, ssa_name_var, H*F:D*suse.cz X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Mon, 25 Apr 2016 13:22:58 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BACA7AC60 for ; Mon, 25 Apr 2016 13:22:52 +0000 (UTC) Date: Mon, 25 Apr 2016 15:22:54 +0200 From: Martin Jambor To: GCC Patches Subject: [PATCH] Verify that context of local DECLs is the current function Message-ID: <20160425132254.GA25091@virgil.suse.cz> Mail-Followup-To: GCC Patches MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.0 (2016-04-01) X-IsSubscribed: yes Hi, the patch below moves an assert from expand_expr_real_1 to gimple verification. It triggers when we do a sloppy job outlining stuff from one function to another (or perhaps inlining too) and leave in the IL of a function a local declaration that belongs to a different function. Like I wrote above, such cases usually ICE in expand anyway, but I think it is worth bailing out sooner, if nothing because bugs like PR 70348 would not be assigned to me ;-) ...well, actually, I found this helpful when working on OpenMP gridification. In the process, I think that the verifier would not catch a SSA_NAME_IN_FREE_LIST when such an SSA_NAME is a base of a MEM_REF so I added that check too. Bootstrapped and tested on x86_64-linux, OK for trunk? Thanks, Martin 2016-04-21 Martin Jambor * tree-cfg.c (verify_var_parm_result_decl): New function. (verify_address): Call it on PARM_DECL bases. (verify_expr): Likewise, also verify SSA_NAME bases of MEM_REFs. --- gcc/tree-cfg.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 3385164..c917967 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -2764,6 +2764,23 @@ gimple_split_edge (edge edge_in) return new_bb; } +/* Verify that a VAR, PARM_DECL or RESULT_DECL T is from the current function, + and if not, return true. If it is, return false. */ + +static bool +verify_var_parm_result_decl (tree t) +{ + tree context = decl_function_context (t); + if (context != cfun->decl + && !SCOPE_FILE_SCOPE_P (context) + && !TREE_STATIC (t) + && !DECL_EXTERNAL (t)) + { + error ("Local declaration from a different function"); + return true; + } + return NULL; +} /* Verify properties of the address expression T with base object BASE. */ @@ -2798,6 +2815,8 @@ verify_address (tree t, tree base) || TREE_CODE (base) == RESULT_DECL)) return NULL_TREE; + if (verify_var_parm_result_decl (base)) + return base; if (DECL_GIMPLE_REG_P (base)) { error ("DECL_GIMPLE_REG_P set on a variable with address taken"); @@ -2834,6 +2853,13 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) } break; + case PARM_DECL: + case VAR_DECL: + case RESULT_DECL: + if (verify_var_parm_result_decl (t)) + return t; + break; + case INDIRECT_REF: error ("INDIRECT_REF in gimple IL"); return t; @@ -2852,9 +2878,25 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) error ("invalid offset operand of MEM_REF"); return TREE_OPERAND (t, 1); } + if (TREE_CODE (x) == SSA_NAME) + { + if (SSA_NAME_IN_FREE_LIST (x)) + { + error ("SSA name in freelist but still referenced"); + return x; + } + if (SSA_NAME_VAR (x)) + x = SSA_NAME_VAR (x);; + } + if ((TREE_CODE (x) == PARM_DECL + || TREE_CODE (x) == VAR_DECL + || TREE_CODE (x) == RESULT_DECL) + && verify_var_parm_result_decl (x)) + return x; if (TREE_CODE (x) == ADDR_EXPR && (x = verify_address (x, TREE_OPERAND (x, 0)))) return x; + *walk_subtrees = 0; break; @@ -3010,6 +3052,11 @@ verify_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) t = TREE_OPERAND (t, 0); } + if ((TREE_CODE (t) == PARM_DECL + || TREE_CODE (t) == VAR_DECL + || TREE_CODE (t) == RESULT_DECL) + && verify_var_parm_result_decl (t)) + return t; if (!is_gimple_min_invariant (t) && !is_gimple_lvalue (t)) {