From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id D31723856DC3; Fri, 21 Apr 2023 20:28:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D31723856DC3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682108899; bh=mWfVXQLKjd0hSPCuPcWO/TKUH8T+EQx40ppRN2d2ZrE=; h=From:To:Subject:Date:From; b=DcF2cNSfoohxwVYj//2QFv1V1lHKgPcFegOXo5mW/opi9HeDe/CHyxjBdRAz+ds0r xPcIHDHKHi/DO3G3C7bs0kF/9/gtE5To71VOPRAuc8krlrdRY8uY3JUFE60GKPlG2a Qs9XpXpkF6/LWugAjoFBy//2xI93/7WaWeGqWCH8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-11307] c-family: -Wsequence-point and COMPONENT_REF [PR107163] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: da17a9049ee0a8ca9f93edf137df92e824a7593e X-Git-Newrev: e81e393cd864abcd2de02602bd51e435dc28f418 Message-Id: <20230421202819.D31723856DC3@sourceware.org> Date: Fri, 21 Apr 2023 20:28:19 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e81e393cd864abcd2de02602bd51e435dc28f418 commit r10-11307-ge81e393cd864abcd2de02602bd51e435dc28f418 Author: Jason Merrill Date: Thu Mar 23 15:57:39 2023 -0400 c-family: -Wsequence-point and COMPONENT_REF [PR107163] The patch for PR91415 fixed -Wsequence-point to treat shifts and ARRAY_REF as sequenced in C++17, and COMPONENT_REF as well. But this is unnecessary for COMPONENT_REF, since the RHS is just a FIELD_DECL with no actual evaluation, and in this testcase handling COMPONENT_REF as sequenced blows up fast in a deep inheritance tree. Instead, look through it. PR c++/107163 gcc/c-family/ChangeLog: * c-common.c (verify_tree): Don't use sequenced handling for COMPONENT_REF. gcc/testsuite/ChangeLog: * g++.dg/warn/Wsequence-point-5.C: New test. Diff: --- gcc/c-family/c-common.c | 7 ++++- gcc/testsuite/g++.dg/warn/Wsequence-point-5.C | 37 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 8105a27ab56..409dbfeec09 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -2006,12 +2006,17 @@ verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp, case LSHIFT_EXPR: case RSHIFT_EXPR: - case COMPONENT_REF: case ARRAY_REF: if (cxx_dialect >= cxx17) goto sequenced_binary; goto do_default; + case COMPONENT_REF: + /* Treat as unary, the other operands aren't evaluated. */ + x = TREE_OPERAND (x, 0); + writer = 0; + goto restart; + default: do_default: /* For other expressions, simply recurse on their operands. diff --git a/gcc/testsuite/g++.dg/warn/Wsequence-point-5.C b/gcc/testsuite/g++.dg/warn/Wsequence-point-5.C new file mode 100644 index 00000000000..0354ab09f53 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsequence-point-5.C @@ -0,0 +1,37 @@ +// PR c++/107163 +// { dg-additional-options "-Wsequence-point" } + +struct BaseType { + int i; +}; + +template< int Seq > +class DerivedType : public DerivedType< Seq - 1 > { }; + +template<> +class DerivedType< -1 > : public BaseType { }; + +int main() { + DerivedType< 400 > d; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + return d.i; +}