From patchwork Mon Mar 25 09:28:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1064014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498363-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ERQiUPLT"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="gEej3P/D"; dkim-atps=neutral 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 44STTQ3JHmz9sPg for ; Mon, 25 Mar 2019 20:28:21 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=sY2iuwE5OIVOkokgH354UTMJ+2OopVr8va/UIFZqkDmshPhbma 9IsZp3txz5+QsXkrTtdGb7ek2oFG1bYzKX8frPvaTr47njRs0XuOjInh1zJzpq+Z fVVu6UHxpeCiIQ2RLChpHwWs9gOM2HcTO6KzlzUzsJLTK2FW/EpbIrFNw= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=C3C6GYUU7tAmkO1iac+0QTBqZTE=; b=ERQiUPLTcznAlUhY/lY2 rOnMJGnf+9bNqKqZQzy8GCpEdf9JiiXIJGXzPJ/NJ+N7s/f+D0ljgY4zD5NSvwNZ n9oO3Z9/jZ0JQryEEDLcLFdNSqiHg8ucya5+Q7/wR6IFHtfABVFkmdHgTZZvVgtg 3AT2LbeJHGMm0ys4lBC8Y1E= Received: (qmail 102823 invoked by alias); 25 Mar 2019 09:28:11 -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 102813 invoked by uid 89); 25 Mar 2019 09:28:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=investigate, 269881, H*Ad:D*oracle.com, H*r:Gateway X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 25 Mar 2019 09:28:09 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2P9NuYD002542; Mon, 25 Mar 2019 09:28:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=JesvBlsJOjuZc2uKIFLctGSp+LDzzq2v+plv5HX4LqU=; b=gEej3P/DgQG1Qm/Q+S7DndV26Ni5HlSgQvkW7y/QfWCNkGYX2Lv5u0LgpvYRx2ZlYoMG GqoJMMBdwPS11MZiX0VPomnL+95SxQKj87//zYNXX7N9TL00/OaA6XbT7PGh72hPmQZ2 qQIHzV352puwDJU4NcqZ4piYj/iTy3qDbcAy/acdQ+pMUg1RS6lK7X55B0b/Gf3lvL82 6XMImLsYnds4gurJXxplgK7SjoqGODWXw/K0r4YTfLVJ6vi7Vf1HQ8UQE9WkEqPBQZIn l4ot/RvcUFCKEBDSHWSwuoVw7FzEXZhW+qd1XosMXUFZ//VIqip+haWfDPU36PX4jek6 Hw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2re6dj2wq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 25 Mar 2019 09:28:07 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x2P9S6AA031612 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 25 Mar 2019 09:28:06 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x2P9S4FH004418; Mon, 25 Mar 2019 09:28:04 GMT Received: from [192.168.1.4] (/87.9.44.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 25 Mar 2019 02:28:03 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Fix c++/84661, c++/85013, and other recovery regressions in cp_parser_binary_expression Message-ID: <8898d175-7a24-d9a5-9391-d1830f7fb2b0@oracle.com> Date: Mon, 25 Mar 2019 10:28:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, a while ago I noticed that in cp_parser_binary_expression we were calling cp_fully_fold first to disable the warnings for not executed expressions, and then, seemingly in a very redundant and inconsistent with other situations way, to re-enable the warnings (*). Thus, I meant to investigate opportunities for a mini optimization / clean-up during the next Stage 1. However, over the last couple of weeks I noticed that we had in Bugzilla a number of error-recovery regressions happening starting from the *second* cp_fully_fold calls, those which likely could be completely avoided. Note, not only we were calling again cp_fully_fold, we were also doing that for expressions which could not be folded to true/false the first time we tried, error-prone and wasteful too. Then the below which seems rather straightforward to me. To be super-safe I carried out a number of additional checks and instrumented testsuite runs: that we exercise the code enough; that when we set disable_warnings_sp = sp we find it NULL, etc. Everything went well.. Tested x86_64-linux. Thanks, Paolo. (*) Historically, we used not to have this disabling code at all, then a very basic version not folding. ///////////////// /cp 2019-03-25 Paolo Carlini PR c++/84661 PR c++/85013 * parser.c (cp_parser_binary_expression): Don't call cp_fully_fold to undo the disabling of warnings. /testsuite 2019-03-25 Paolo Carlini PR c++/84661 PR c++/85013 * g++.dg/concepts/pr84661.C: New. * g++.dg/torture/pr85013.C: Likewise. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 269881) +++ cp/parser.c (working copy) @@ -9443,6 +9443,7 @@ cp_parser_binary_expression (cp_parser* parser, bo { cp_parser_expression_stack stack; cp_parser_expression_stack_entry *sp = &stack[0]; + cp_parser_expression_stack_entry *disable_warnings_sp = NULL; cp_parser_expression_stack_entry current; cp_expr rhs; cp_token *token; @@ -9506,12 +9507,14 @@ cp_parser_binary_expression (cp_parser* parser, bo /* For "false && x" or "true || x", x will never be executed; disable warnings while evaluating it. */ - if (current.tree_type == TRUTH_ANDIF_EXPR) - c_inhibit_evaluation_warnings += - cp_fully_fold (current.lhs) == truthvalue_false_node; - else if (current.tree_type == TRUTH_ORIF_EXPR) - c_inhibit_evaluation_warnings += - cp_fully_fold (current.lhs) == truthvalue_true_node; + if ((current.tree_type == TRUTH_ANDIF_EXPR + && cp_fully_fold (current.lhs) == truthvalue_false_node) + || (current.tree_type == TRUTH_ORIF_EXPR + && cp_fully_fold (current.lhs) == truthvalue_true_node)) + { + disable_warnings_sp = sp; + ++c_inhibit_evaluation_warnings; + } /* Extract another operand. It may be the RHS of this expression or the LHS of a new, higher priority expression. */ @@ -9557,12 +9560,11 @@ cp_parser_binary_expression (cp_parser* parser, bo } /* Undo the disabling of warnings done above. */ - if (current.tree_type == TRUTH_ANDIF_EXPR) - c_inhibit_evaluation_warnings -= - cp_fully_fold (current.lhs) == truthvalue_false_node; - else if (current.tree_type == TRUTH_ORIF_EXPR) - c_inhibit_evaluation_warnings -= - cp_fully_fold (current.lhs) == truthvalue_true_node; + if (sp == disable_warnings_sp) + { + disable_warnings_sp = NULL; + --c_inhibit_evaluation_warnings; + } if (warn_logical_not_paren && TREE_CODE_CLASS (current.tree_type) == tcc_comparison Index: testsuite/g++.dg/concepts/pr84661.C =================================================================== --- testsuite/g++.dg/concepts/pr84661.C (nonexistent) +++ testsuite/g++.dg/concepts/pr84661.C (working copy) @@ -0,0 +1,7 @@ +// { dg-do compile { target c++14 } } +// { dg-additional-options "-fconcepts" } + +struct S { + int &a; + void foo (decltype(((a = 0) || ((auto))))); // { dg-error "expected" } +}; Index: testsuite/g++.dg/torture/pr85013.C =================================================================== --- testsuite/g++.dg/torture/pr85013.C (nonexistent) +++ testsuite/g++.dg/torture/pr85013.C (working copy) @@ -0,0 +1,3 @@ +// { dg-additional-options "-std=c++14 -fconcepts" } + +a(decltype((0 > 1e91 && 1e31 && (auto)))); // { dg-error "expected" }