From patchwork Wed Apr 15 19:44:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1271407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=sBh6ik94; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 492Xqt0sbVz9sP7 for ; Thu, 16 Apr 2020 05:44:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A8E3384B0C1; Wed, 15 Apr 2020 19:44:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A8E3384B0C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586979876; bh=giyXMSuOVGfP5U0CgwiAjZpTWQOnOM+yY1O4OBoMJI0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=sBh6ik942NmbOK4WfuPUQtP67bwJXXEyus1sGmh7uCWUkFiJj6rcDk3iMhq0i+C2O RrmkTwWE0MS9umTTFVWx95tCpKjPu+SnWqhBZ8Bffv/TorYe7hQ9rwaF+RKtUUhfIy NsZXC6hpDA/62v+L/0lsisEFqQFSND24kziRVi8I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 4324D385DC1E for ; Wed, 15 Apr 2020 19:44:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4324D385DC1E Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-117--y_6cYQkO4Gjx0Yl1uf58Q-1; Wed, 15 Apr 2020 15:44:32 -0400 X-MC-Unique: -y_6cYQkO4Gjx0Yl1uf58Q-1 Received: by mail-qt1-f198.google.com with SMTP id z8so16838637qtu.17 for ; Wed, 15 Apr 2020 12:44:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wlYNuDF49iQ3nCS5A+QVFX8m3JqBgvnP3H/bLFerNPg=; b=G+LuqvMQm0dNmMk1juDanio/tp/mIxMgmja+VpR+jSMzU0fotaIEMHR+sTlQ3b17AV cuHqDs/w+ABpu9gnbDp/tmofxFmmelyTfcbGSPSXs+BpBWv91rHv/rnjxMV47D3U+t/g g4DejMOm6hBDjlWleVuOZ356nwMcAvhHwFYks+IPyIEfFUzPVIUKp3L37bKKjQwyuoTL VbslUXls/CRhGjE6X0vkChb4h1nJQJ3AYK21oKv1CLseRdI+Ub1uIqKt6NDe6y2x6tFY JbOTfGMCn8hy9IWdcZ+Hixyzi2wiqlJAOqBS6UdhPGk/G52DE2hrtXV0AuLlr5JmPT8S o7Cw== X-Gm-Message-State: AGi0PuY0WpdJ2Btm/EWKvuTl9DlP3G0O6++y/BbJj4ToO+95Yb85K6nZ Gm3s2+sPFSBkdCotGEx1oXM/gnF5ml5Lgh4hnIx7IoF6K7EzVrn2TbW6PpPs29sQZghpliBCCkT Q4BhPnP3NjWRK+tcwrg== X-Received: by 2002:a37:7fc3:: with SMTP id a186mr28106811qkd.251.1586979871297; Wed, 15 Apr 2020 12:44:31 -0700 (PDT) X-Google-Smtp-Source: APiQypKIw3r3Rq9/opHzD+bMlwZf+717eoIstuyvfHDg1nuxxU42Jy8i7QYLSZ1xI7lYSVqR1ruAww== X-Received: by 2002:a37:7fc3:: with SMTP id a186mr28106789qkd.251.1586979871043; Wed, 15 Apr 2020 12:44:31 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id y132sm13500623qka.19.2020.04.15.12.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 12:44:30 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Error recovery with errenous DECL_INITIAL [PR94475] Date: Wed, 15 Apr 2020 15:44:27 -0400 Message-Id: <20200415194427.1815190-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.1.107.gefe3874640 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Here we're ICE'ing in do_narrow during error-recovery, because ocp_convert returns error_mark_node after it attempts to reduce a const decl to its erroneous DECL_INITIAL via scalar_constant_value, and we later pass this error_mark_node to fold_build2 which isn't prepared to handle error_mark_nodes. We could fix this ICE in do_narrow by checking if ocp_convert returns error_mark_node, but for the sake of consistency and for better error recovery it seems it'd be better if ocp_convert didn't care that a const decl's initializer is erroneous and would instead proceed as if the decl was not const, which is the approach that this patch takes. Passes 'make check-c++', does this look OK to commit after full bootstrap and regtest? gcc/cp/ChangeLog: PR c++/94475 * cvt.c (ocp_convert): If the result of scalar_constant_value is erroneous, discard it and carry on with the original expression. gcc/testsuite/ChangeLog: PR c++/94475 * g++.dg/conversion/err-recover2.C: New test. * g++.dg/diagnostic/pr84138.C: Remove now-bogus warning. * g++.dg/warn/Wsign-compare-8.C: Remove now-bogus warning. --- gcc/cp/cvt.c | 6 +++--- gcc/testsuite/g++.dg/conversion/err-recover2.C | 10 ++++++++++ gcc/testsuite/g++.dg/diagnostic/pr84138.C | 2 +- gcc/testsuite/g++.dg/warn/Wsign-compare-8.C | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/conversion/err-recover2.C diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index a3b80968b33..b94231a6d08 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -723,10 +723,10 @@ ocp_convert (tree type, tree expr, int convtype, int flags, if (!CLASS_TYPE_P (type)) { e = mark_rvalue_use (e); - e = scalar_constant_value (e); + tree v = scalar_constant_value (e); + if (!error_operand_p (v)) + e = v; } - if (error_operand_p (e)) - return error_mark_node; if (NULLPTR_TYPE_P (type) && null_ptr_cst_p (e)) { diff --git a/gcc/testsuite/g++.dg/conversion/err-recover2.C b/gcc/testsuite/g++.dg/conversion/err-recover2.C new file mode 100644 index 00000000000..437e1a919ea --- /dev/null +++ b/gcc/testsuite/g++.dg/conversion/err-recover2.C @@ -0,0 +1,10 @@ +// PR c++/94475 +// { dg-do compile } + +unsigned char +sr () +{ + const unsigned char xz = EI; // { dg-error "not declared" } + + return xz - (xz >> 1); +} diff --git a/gcc/testsuite/g++.dg/diagnostic/pr84138.C b/gcc/testsuite/g++.dg/diagnostic/pr84138.C index 5c48b9b164a..00352306a56 100644 --- a/gcc/testsuite/g++.dg/diagnostic/pr84138.C +++ b/gcc/testsuite/g++.dg/diagnostic/pr84138.C @@ -5,4 +5,4 @@ foo() { const int i = 0 = 0; // { dg-error "lvalue required as left operand" } return 1 ? 0 : (char)i; -} // { dg-warning "control reaches" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C index 237ba84d526..4d2688157fc 100644 --- a/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C +++ b/gcc/testsuite/g++.dg/warn/Wsign-compare-8.C @@ -5,4 +5,4 @@ bool foo (char c) { const int i = 0 = 0; // { dg-error "lvalue" } return c = i; -} // { dg-warning "control reaches" } +}