public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-10647] c-family: -Wsequence-point and COMPONENT_REF [PR107163]
@ 2023-04-22  0:23 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2023-04-22  0:23 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9ab083eb8a96b7f8baf6fe632d03aa496017e456

commit r11-10647-g9ab083eb8a96b7f8baf6fe632d03aa496017e456
Author: Jason Merrill <jason@redhat.com>
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 16fc52302e5..9417b7fb4d1 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -2023,12 +2023,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;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-22  0:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-22  0:23 [gcc r11-10647] c-family: -Wsequence-point and COMPONENT_REF [PR107163] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).