From patchwork Mon Aug 12 14:48:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1145778 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-506698-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mOQiFWU5"; 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 466dyR6klrz9sDQ for ; Tue, 13 Aug 2019 00:48:46 +1000 (AEST) 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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=O2MSsHp0gHddZHySp5JfVtqaPdd17 IsX+f1SlYQ47cv8dP1PwS76j7vE1xS2lzKRcKyCBe9x7vhWKxOUODAjoPJTN8IBO ONEBWePKdZKzVb1v9iMZKJcc0knpbqvD8YytQVt8Nuj43uwRBaQ7C2OJS+otjqBU dlcybAz5XdyfGg= 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:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=9eA4EuHEOMAGvx/Xv8OupDkpCIc=; b=mOQ iFWU5z0voz8xroY16oaeYEeVdgDVBHQWDG8+w56/IuTC+aLU7XwCPsyS7Gio1xtN iIVLP33Qh3gH+W9aW51D+qdfb5pvdwtIoIJqYMLWy7tZ0fCk5Lcvdrd1KmJ8Uqd4 3vdwdqmYwg/g66WjQwOAGmQ+9bSA9yuYlF2wElJQ= Received: (qmail 69909 invoked by alias); 12 Aug 2019 14:48:38 -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 69896 invoked by uid 89); 12 Aug 2019 14:48:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Aug 2019 14:48:36 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D80873B74C for ; Mon, 12 Aug 2019 14:48:35 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-200.ams2.redhat.com [10.36.116.200]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 804A871C9B; Mon, 12 Aug 2019 14:48:35 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x7CEmXEq029790; Mon, 12 Aug 2019 16:48:33 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x7CEmVMV029789; Mon, 12 Aug 2019 16:48:31 +0200 Date: Mon, 12 Aug 2019 16:48:31 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Adjust -Wsequence-point for C++17 changes (PR c++/91415) Message-ID: <20190812144831.GP2726@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes Hi! The following patch adds some tweaks for -Wsequence-point warning for C++17 and later. In particular, stop warning about no sequence point in between <<, >>, ., -> and [] expressions, where E1 is in C++17 sequenced before E2. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? As mentioned in the PR, this is just part of the needed changes, I've tried to adjust handling of MODIFY_EXPR, but didn't figure out exactly what needs to be done, and .* / ->* aren't handled either, and CALL_EXPR needs probably some verification too. 2019-08-12 Jakub Jelinek PR c++/91415 * c-common.c (verify_tree): For LSHIFT_EXPR, RSHIFT_EXPR, COMPONENT_REF and ARRAY_REF in cxx_dialect >= cxx17 mode handle it like COMPOUND_EXPR rather than normal expression. * g++.dg/warn/sequence-pt-4.C: New test. Jakub --- gcc/c-family/c-common.c.jj 2019-08-12 09:45:54.463491950 +0200 +++ gcc/c-family/c-common.c 2019-08-12 12:01:32.783135654 +0200 @@ -1889,6 +1889,7 @@ verify_tree (tree x, struct tlist **pbef case COMPOUND_EXPR: case TRUTH_ANDIF_EXPR: case TRUTH_ORIF_EXPR: + sequenced_binary: tmp_before = tmp_nosp = tmp_list2 = tmp_list3 = 0; verify_tree (TREE_OPERAND (x, 0), &tmp_before, &tmp_nosp, NULL_TREE); warn_for_collisions (tmp_nosp); @@ -2031,8 +2035,18 @@ verify_tree (tree x, struct tlist **pbef x = TREE_OPERAND (x, 0); goto restart; } - gcc_fallthrough (); + goto do_default; + + case LSHIFT_EXPR: + case RSHIFT_EXPR: + case COMPONENT_REF: + case ARRAY_REF: + if (cxx_dialect >= cxx17) + goto sequenced_binary; + goto do_default; + default: + do_default: /* For other expressions, simply recurse on their operands. Manual tail recursion for unary expressions. Other non-expressions need not be processed. */ --- gcc/testsuite/g++.dg/warn/sequence-pt-4.C.jj 2019-08-12 12:16:27.205660149 +0200 +++ gcc/testsuite/g++.dg/warn/sequence-pt-4.C 2019-08-12 12:22:07.540530959 +0200 @@ -0,0 +1,21 @@ +/* More sequence point warning tests */ +/* { dg-do compile } */ +/* { dg-options "-Wsequence-point" } */ + +struct S { int a[10]; }; +void bar (int, int, int, int, int, int, int, int); + +int +foo (int i, int x[10][10], int y[10], struct S z[10], struct S *w[10]) +{ + int b = x[i++][i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */ + int c = i++ << i++; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */ + int d = i++ >> i++; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */ + int e = i++ && i++; + int f = i++ ? i++ : i++; + int g = (i++, i++); + int h = z[i++].a[i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */ + int j = w[i++]->a[i++]; /* { dg-warning "undefined" "sequence point warning" { target c++14_down } } */ + bar (b, c, d, e, f,g, h, j); + return i; +}