[PATCH] Don't track useless expressions in -Wsequence-point (PR c++/46401)
Jakub Jelinek
jakub@redhat.com
Mon Nov 15 20:54:00 GMT 2010
Hi!
-Wsequence-point algorithm is quadratic (both in memory and compile time),
so the fewer things that can't be usefully warned about we track the better.
CALL_EXPRs that aren't ECF_CONST will never pass operand_equal_p, so
it doesn't make sense to track them - they will not be warned about
(lvalue_p returns true if the CALL_EXPR returns REFERENCE_TYPE).
Similarly, STRING_CSTs, while they are lvalues, can't be written into
and thus will not be ever reported by -Wsequence-point.
With these two changes the testcase compiles instantly (as opposed
after several minutes).
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2010-11-15 Jakub Jelinek <jakub@redhat.com>
PR c++/46401
* c-common.c (warning_candidate_p): Don't track non-const calls
or STRING_CSTs.
* g++.dg/warn/Wsequence-point-3.C: New test.
--- gcc/c-family/c-common.c.jj 2010-11-15 09:27:54.000000000 +0100
+++ gcc/c-family/c-common.c 2010-11-15 16:16:07.000000000 +0100
@@ -2324,10 +2324,26 @@ warn_for_collisions (struct tlist *list)
static int
warning_candidate_p (tree x)
{
- /* !VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
+ if (DECL_P (x) && DECL_ARTIFICIAL (x))
+ return 0;
+
+ /* VOID_TYPE_P (TREE_TYPE (x)) is workaround for cp/tree.c
(lvalue_p) crash on TRY/CATCH. */
- return !(DECL_P (x) && DECL_ARTIFICIAL (x))
- && TREE_TYPE (x) && !VOID_TYPE_P (TREE_TYPE (x)) && lvalue_p (x);
+ if (TREE_TYPE (x) == NULL_TREE || VOID_TYPE_P (TREE_TYPE (x)))
+ return 0;
+
+ if (!lvalue_p (x))
+ return 0;
+
+ /* No point to track non-const calls, they will never satisfy
+ operand_equal_p. */
+ if (TREE_CODE (x) == CALL_EXPR && (call_expr_flags (x) & ECF_CONST) == 0)
+ return 0;
+
+ if (TREE_CODE (x) == STRING_CST)
+ return 0;
+
+ return 1;
}
/* Return nonzero if X and Y appear to be the same candidate (or NULL) */
--- gcc/testsuite/g++.dg/warn/Wsequence-point-3.C.jj 2010-11-15 17:15:42.000000000 +0100
+++ gcc/testsuite/g++.dg/warn/Wsequence-point-3.C 2010-11-15 16:35:35.000000000 +0100
@@ -0,0 +1,20 @@
+// PR c++/46401
+// { dg-do compile }
+// { dg-options "-Wsequence-point" }
+
+struct S
+{
+ S ();
+ S &operator<< (const char *);
+ S (const S &);
+};
+
+#define N1(n) << #n
+#define N2(n) N1(n)
+#define N3(n) N2(n##0) N2(n##1) N2(n##2) N2(n##3) N2(n##4) \
+ N2(n##5) N2(n##6) N2(n##7) N2(n##8) N2(n##9)
+#define N4(n) N3(n##0) N3(n##1) N3(n##2) N3(n##3) N3(n##4) \
+ N3(n##5) N3(n##6) N3(n##7) N3(n##8) N3(n##9)
+#define N5(n) N4(n##0) N4(n##1) N4(n##2) N4(n##3) N4(n##4) \
+ N4(n##5) N4(n##6) N4(n##7) N4(n##8) N4(n##9)
+S s = S () N5(a) N5(b);
Jakub
More information about the Gcc-patches
mailing list