public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix bogus warnings about ignored annotations [PR114409]
@ 2024-03-22  8:08 Jakub Jelinek
  2024-04-12 18:12 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-03-22  8:08 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Note, the PR is mostly about ICE with the annotations used in a template,
this patch doesn't change anything on that and I really don't know what
should be done in that case.

2024-03-22  Jakub Jelinek  <jakub@redhat.com>

	PR c++/114409
	* 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/pr114409.C: New test.

--- gcc/cp/semantics.cc.jj	2024-03-01 17:27:58.862888609 +0100
+++ gcc/cp/semantics.cc	2024-03-21 15:24:57.296857864 +0100
@@ -799,7 +799,11 @@ simplify_loop_decl_cond (tree *cond_p, t
   *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);
--- gcc/testsuite/g++.dg/ext/pr114409.C.jj	2024-03-21 15:27:44.077661090 +0100
+++ gcc/testsuite/g++.dg/ext/pr114409.C	2024-03-21 15:27:15.331039726 +0100
@@ -0,0 +1,22 @@
+// PR c++/114409
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+void qux (int);
+int foo (int);
+
+void
+bar (int x)
+{
+  #pragma GCC novector
+  while (int y = foo (x))	// { dg-bogus "ignoring loop annotation" }
+    qux (y);
+}
+
+void
+baz (int x)
+{
+  #pragma GCC novector
+  for (; int y = foo (x); )	// { dg-bogus "ignoring loop annotation" }
+    qux (y);
+}

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: Fix bogus warnings about ignored annotations [PR114409]
  2024-03-22  8:08 [PATCH] c++: Fix bogus warnings about ignored annotations [PR114409] Jakub Jelinek
@ 2024-04-12 18:12 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-04-12 18:12 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 3/22/24 04:08, Jakub Jelinek wrote:
> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK

> Note, the PR is mostly about ICE with the annotations used in a template,
> this patch doesn't change anything on that and I really don't know what
> should be done in that case.
> 
> 2024-03-22  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/114409
> 	* 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/pr114409.C: New test.
> 
> --- gcc/cp/semantics.cc.jj	2024-03-01 17:27:58.862888609 +0100
> +++ gcc/cp/semantics.cc	2024-03-21 15:24:57.296857864 +0100
> @@ -799,7 +799,11 @@ simplify_loop_decl_cond (tree *cond_p, t
>     *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);
> --- gcc/testsuite/g++.dg/ext/pr114409.C.jj	2024-03-21 15:27:44.077661090 +0100
> +++ gcc/testsuite/g++.dg/ext/pr114409.C	2024-03-21 15:27:15.331039726 +0100
> @@ -0,0 +1,22 @@
> +// PR c++/114409
> +// { dg-do compile }
> +// { dg-options "-O2 -Wall" }
> +
> +void qux (int);
> +int foo (int);
> +
> +void
> +bar (int x)
> +{
> +  #pragma GCC novector
> +  while (int y = foo (x))	// { dg-bogus "ignoring loop annotation" }
> +    qux (y);
> +}
> +
> +void
> +baz (int x)
> +{
> +  #pragma GCC novector
> +  for (; int y = foo (x); )	// { dg-bogus "ignoring loop annotation" }
> +    qux (y);
> +}
> 
> 	Jakub
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-12 18:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22  8:08 [PATCH] c++: Fix bogus warnings about ignored annotations [PR114409] Jakub Jelinek
2024-04-12 18:12 ` 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).