aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-04-12 20:53:10 +0200
committerJakub Jelinek <jakub@redhat.com>2024-06-20 15:07:40 +0200
commit6ec50f5b9a8842f92d65dbd8fcc546f0f6902585 (patch)
tree2aa9a0cc5e0f4dafe45296234c6c27efa8208d34
parent043d5fc707842c9b26ba69650e15be73c57f7a1d (diff)
downloadgcc-6ec50f5b9a8842f92d65dbd8fcc546f0f6902585.zip
gcc-6ec50f5b9a8842f92d65dbd8fcc546f0f6902585.tar.gz
gcc-6ec50f5b9a8842f92d65dbd8fcc546f0f6902585.tar.bz2
c++: Fix bogus warnings about ignored annotations [PR114691]
The middle-end warns about the ANNOTATE_EXPR added for while/for loops if they declare a var inside of the loop condition. This is because the assumption is that ANNOTATE_EXPR argument is used immediately in a COND_EXPR (later GIMPLE_COND), but simplify_loop_decl_cond wraps the ANNOTATE_EXPR inside of a TRUTH_NOT_EXPR, so it no longer holds. The following patch fixes that by adding the TRUTH_NOT_EXPR inside of the ANNOTATE_EXPR argument if any. 2024-04-12 Jakub Jelinek <jakub@redhat.com> PR c++/114691 * semantics.c (simplify_loop_decl_cond): Use cp_build_unary_op with TRUTH_NOT_EXPR on ANNOTATE_EXPR argument (if any) rather than ANNOTATE_EXPR itself. * g++.dg/ext/pr114691.C: New test. (cherry picked from commit 91146346f57cc54dfeb2669347edd0eb3d13af7f)
-rw-r--r--gcc/cp/semantics.c6
-rw-r--r--gcc/testsuite/g++.dg/ext/pr114691.C22
2 files changed, 27 insertions, 1 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 57e71ec..dc0cd2e 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -775,7 +775,11 @@ simplify_loop_decl_cond (tree *cond_p, tree body)
*cond_p = boolean_true_node;
if_stmt = begin_if_stmt ();
- cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, false, tf_warning_or_error);
+ cond_p = &cond;
+ while (TREE_CODE (*cond_p) == ANNOTATE_EXPR)
+ cond_p = &TREE_OPERAND (*cond_p, 0);
+ *cond_p = cp_build_unary_op (TRUTH_NOT_EXPR, *cond_p, false,
+ tf_warning_or_error);
finish_if_stmt_cond (cond, if_stmt);
finish_break_stmt ();
finish_then_clause (if_stmt);
diff --git a/gcc/testsuite/g++.dg/ext/pr114691.C b/gcc/testsuite/g++.dg/ext/pr114691.C
new file mode 100644
index 0000000..bda8ff9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/pr114691.C
@@ -0,0 +1,22 @@
+// PR c++/114691
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+void qux (int);
+int foo (int);
+
+void
+bar (int x)
+{
+ #pragma GCC ivdep
+ while (int y = foo (x)) // { dg-bogus "ignoring loop annotation" }
+ qux (y);
+}
+
+void
+baz (int x)
+{
+ #pragma GCC ivdep
+ for (; int y = foo (x); ) // { dg-bogus "ignoring loop annotation" }
+ qux (y);
+}