From patchwork Thu Dec 31 15:40:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 561900 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 AAA8D140BA5 for ; Fri, 1 Jan 2016 02:41:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=jUP64YEQ; 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:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=TUyi8oKxzbBNZ+bkgAPKQK5NyChXnxUrqSM38+nQj5CNpK9GYCxD3 ob8Ui15ART+F3MawkRxnVCBb3aH5g/LN93PHUsD1H4z0U48rX68Iz5zFwQmxNYnB k5wLNcSNCeJL9yzcjEN3q35lqisNsDzw40xhhCkvNWEOl4EGXne9Hk= 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:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=WiatgfcNE9NsTvEOyIsNzUVg3vQ=; b=jUP64YEQsejDijP34RTA Cmtm8Es2UwzI/vXq1uCAmq4x/HtCV1m2ME/6Rri/WkPT8m+HbMQSeNWEC3EvDsT9 +mQkCGCUwcPajRy7YachJ2LkZMViXBC/YCzV4ou3F7P/mPyzAwhCIeLO8JSsjmTb qMn6JtEcaES5dMHyeXpw7aU= Received: (qmail 18679 invoked by alias); 31 Dec 2015 15:40:36 -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 18570 invoked by uid 89); 31 Dec 2015 15:40:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=During, sk:generic X-HELO: mail-qg0-f44.google.com Received: from mail-qg0-f44.google.com (HELO mail-qg0-f44.google.com) (209.85.192.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 31 Dec 2015 15:40:31 +0000 Received: by mail-qg0-f44.google.com with SMTP id 6so125090904qgy.1 for ; Thu, 31 Dec 2015 07:40:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EKn8gG8i2ZoaCRmW8byXPcqrT7UqSkh/ReNJcnck7IY=; b=Yl6nvmA94ZkQeKOlkf/EVoccKratGNaRdzdE7nvzs4X+RT81jFipOOwVHwCDpLhIWu hGCasOx4+Mll8Rr7zu1iVpjbcd8HurM9zgK6ifvJbk1vIvcdevf9GdKpDlzhV+NDmPQc 67eFjXSUXcuOUwtvYQp8jEUoTtNs9m7bxqW6aUFX1FROIGcnbpmqU56KUS6rr5N7fsvh vWxd6GGTbc4LA/W+gmt95+y5tiMXd4zltMwABcrsSqkt6SVDT2ewSP/+pF+1yBjNu3L0 Tmn4pwzq5WiKVcHg58nZ6inTayCm+Nxge2sug9yO6KEW02NMEOk9yvRFSoN9hKu1Mrd8 6fmg== X-Gm-Message-State: ALoCoQm1nzvMNQcX4sGP5ydzQj4RgBT31bSEwGQaeMKZEAZ+3dVVtNXOPNSzH3qTdSwjGzkPfaQxzBCa0wN8qLVQLojUtbUf5Q== X-Received: by 10.140.102.228 with SMTP id w91mr84021854qge.21.1451576429082; Thu, 31 Dec 2015 07:40:29 -0800 (PST) Received: from localhost.localdomain (ool-4353a98f.dyn.optonline.net. [67.83.169.143]) by smtp.gmail.com with ESMTPSA id i136sm10861236qhc.42.2015.12.31.07.40.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Dec 2015 07:40:28 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com, jason@redhat.com, Patrick Palka Subject: [PATCH 3/3] [RFC] Treat a gimplification failure as an internal error Date: Thu, 31 Dec 2015 10:40:17 -0500 Message-Id: <1451576417-8710-3-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1451576417-8710-1-git-send-email-patrick@parcs.ath.cx> References: <1451576417-8710-1-git-send-email-patrick@parcs.ath.cx> This patch makes it so that a gimplification failure is considered to be an internal error under normal circumstances, so that we otherwise avoid silently generating wrong code if e.g. a buggy frontend fed us a malformed tree. The rationale for this change is that it's better to abort compilation than to silently generate wrong code. During gimplification we should only see e.g. an error_mark_node if the frontend has already issued an error. Otherwise it is likely a bug in frontend. This patch, for example, turns the PR c++/68948 wrong-code bug into an ICE on invalid bug. During testing it also caught two latent "bugs" (patches 1 and 2 in this series). This series was tested on x86_64-pc-linux-gnu, with --enable-languages=all,ada,go, no new regressions. Does this seem like a reasonable invariant to add to the gimplifier? gcc/cp/ChangeLog: * cp-gimplify.c (gimplify_expr_stmt): Don't convert an error_mark_node to an empty statement. gcc/ChangeLog: * gimplify.c (gimplify_return_expr): Remove a redundant test for error_mark_node. (gimplify_decl_expr): Return GS_ERROR if an initializer is an error_mark_node. (gimplify_expr): Treat a gimplification failure as an internal error. Remove now-redundant GIMPLE_CHECKING checking code. --- gcc/cp/cp-gimplify.c | 5 +---- gcc/gimplify.c | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 373c9e1..2b0aaaf 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -424,16 +424,13 @@ gimplify_expr_stmt (tree *stmt_p) { tree stmt = EXPR_STMT_EXPR (*stmt_p); - if (stmt == error_mark_node) - stmt = NULL; - /* Gimplification of a statement expression will nullify the statement if all its side effects are moved to *PRE_P and *POST_P. In this case we will not want to emit the gimplified statement. However, we may still want to emit a warning, so we do that before gimplification. */ - if (stmt && warn_unused_value) + if (stmt && stmt != error_mark_node && warn_unused_value) { if (!TREE_SIDE_EFFECTS (stmt)) { diff --git a/gcc/gimplify.c b/gcc/gimplify.c index bc90401..9a1d723 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1288,8 +1288,7 @@ gimplify_return_expr (tree stmt, gimple_seq *pre_p) } if (!ret_expr - || TREE_CODE (ret_expr) == RESULT_DECL - || ret_expr == error_mark_node) + || TREE_CODE (ret_expr) == RESULT_DECL) { greturn *ret = gimple_build_return (ret_expr); gimple_set_no_warning (ret, TREE_NO_WARNING (stmt)); @@ -1449,6 +1448,9 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) { tree init = DECL_INITIAL (decl); + if (init == error_mark_node) + return GS_ERROR; + if (TREE_CODE (DECL_SIZE_UNIT (decl)) != INTEGER_CST || (!TREE_STATIC (decl) && flag_stack_check == GENERIC_STACK_CHECK @@ -1464,7 +1466,7 @@ gimplify_decl_expr (tree *stmt_p, gimple_seq *seq_p) && DECL_ARTIFICIAL (decl) && DECL_NAME (decl) == NULL_TREE) gimple_add_tmp_var (decl); - if (init && init != error_mark_node) + if (init) { if (!TREE_STATIC (decl)) { @@ -11036,17 +11038,6 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, } else { -#ifdef ENABLE_GIMPLE_CHECKING - if (!(fallback & fb_mayfail)) - { - fprintf (stderr, "gimplification failed:\n"); - print_generic_expr (stderr, *expr_p, 0); - debug_tree (*expr_p); - internal_error ("gimplification failed"); - } -#endif - gcc_assert (fallback & fb_mayfail); - /* If this is an asm statement, and the user asked for the impossible, don't die. Fail and let gimplify_asm_expr issue an error. */ @@ -11064,6 +11055,14 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, } out: + /* If gimplification failed, then either such failure was explicitly permitted + (via the FB_MAYFAIL flag) or the frontend fed us a malformed tree, e.g. one + containing an ERROR_MARK node -- for which the FE should have already issued an + error diagnostic. Otherwise it is likely that an FE bug was triggered, in + which case it is better to abort than to risk silently generating wrong + code. */ + if (ret == GS_ERROR) + gcc_assert ((fallback & fb_mayfail) || seen_error ()); input_location = saved_location; return ret; }