From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id BEDC53858C3A; Sun, 21 Apr 2024 04:09:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEDC53858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713672562; bh=HVUVMxA52MKxv13zSb2d18v3AslZs7ngsd6vLtk758M=; h=From:To:Subject:Date:From; b=AeoIbAtxKUK6oep8iPQ6h/W+OKUssdYSsWPeSvEjayYxP8r2gzDDu4BGftf3G2DXj EOj3Wd8YW+0vEXZkXhq3JQACVkM7gU1TGb409KlFfkq95GPlm6N0lNBDxqa5T1ePuj gdioE+MwqQJZU5UD3jBJjZGDLLPrs9Aki0ABfryE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8632] c++: Fix bogus warnings about ignored annotations [PR114691] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 7a1a52934a2ab9ac9205a3a4d5b82a672fefba7e X-Git-Newrev: ed7be7ba6f125cfda7ad07263213cbe02b7e7ced Message-Id: <20240421040922.BEDC53858C3A@sourceware.org> Date: Sun, 21 Apr 2024 04:09:20 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ed7be7ba6f125cfda7ad07263213cbe02b7e7ced commit r13-8632-ged7be7ba6f125cfda7ad07263213cbe02b7e7ced Author: Jakub Jelinek Date: Fri Apr 12 20:53:10 2024 +0200 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 PR c++/114691 * semantics.cc (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) Diff: --- gcc/cp/semantics.cc | 6 +++++- gcc/testsuite/g++.dg/ext/pr114691.C | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index a9fabf92a2a..3bf478fd68c 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -800,7 +800,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 00000000000..bda8ff9b39f --- /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); +}