public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][frontend]: don't ice with pragma NOVECTOR if loop in C has no condition [PR113267]
@ 2024-01-08 12:56 Tamar Christina
  2024-01-08 22:02 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Tamar Christina @ 2024-01-08 12:56 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, jsm

[-- Attachment #1: Type: text/plain, Size: 1919 bytes --]

Hi All,

In C you can have loops without a condition, the original version of the patch
was rejecting the use of #pragma GCC novector, however during review it was
changed to not due this with the reason that we didn't want to give a compile
error with such cases.

However because annotations seem to be only be allowed on conditions (unless
I'm mistaken?) the attached example ICEs because there's no condition.

This will have it ignore the pragma instead of ICEing.  I don't know if this is
the best solution,  but as far as I can tell we can't attach the annotation to
anything else.

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Ok for master?

Thanks,
Tamar

gcc/c/ChangeLog:

	PR c/113267
	* c-parser.cc (c_parser_for_statement): Skip the pragma is no cond.

gcc/testsuite/ChangeLog:

	PR c/113267
	* gcc.dg/pr113267.c: New test.

--- inline copy of patch -- 
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index c3724304580cf54f52655e10d2697c68966b9a17..e8300cea8ef7cedead5871e40c2a9ba5333bf839 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -8442,7 +8442,7 @@ c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll,
  			   build_int_cst (integer_type_node,
 					  annot_expr_unroll_kind),
 			   build_int_cst (integer_type_node, unroll));
-	  if (novector && cond != error_mark_node)
+	  if (novector && cond && cond != error_mark_node)
 	    cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
 			   build_int_cst (integer_type_node,
 					  annot_expr_no_vector_kind),
diff --git a/gcc/testsuite/gcc.dg/pr113267.c b/gcc/testsuite/gcc.dg/pr113267.c
new file mode 100644
index 0000000000000000000000000000000000000000..8b6fa08324eb12ad6493291cca8e80bd3a072ba8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113267.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+
+void f (char *a, int i)
+{
+#pragma GCC novector
+  for (;;i++)
+    a[i] *= 2;
+}




-- 

[-- Attachment #2: rb18133.patch --]
[-- Type: text/plain, Size: 1026 bytes --]

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index c3724304580cf54f52655e10d2697c68966b9a17..e8300cea8ef7cedead5871e40c2a9ba5333bf839 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -8442,7 +8442,7 @@ c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll,
  			   build_int_cst (integer_type_node,
 					  annot_expr_unroll_kind),
 			   build_int_cst (integer_type_node, unroll));
-	  if (novector && cond != error_mark_node)
+	  if (novector && cond && cond != error_mark_node)
 	    cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
 			   build_int_cst (integer_type_node,
 					  annot_expr_no_vector_kind),
diff --git a/gcc/testsuite/gcc.dg/pr113267.c b/gcc/testsuite/gcc.dg/pr113267.c
new file mode 100644
index 0000000000000000000000000000000000000000..8b6fa08324eb12ad6493291cca8e80bd3a072ba8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113267.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+
+void f (char *a, int i)
+{
+#pragma GCC novector
+  for (;;i++)
+    a[i] *= 2;
+}




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

* Re: [PATCH][frontend]: don't ice with pragma NOVECTOR if loop in C has no condition [PR113267]
  2024-01-08 12:56 [PATCH][frontend]: don't ice with pragma NOVECTOR if loop in C has no condition [PR113267] Tamar Christina
@ 2024-01-08 22:02 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2024-01-08 22:02 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd

On Mon, 8 Jan 2024, Tamar Christina wrote:

> Hi All,
> 
> In C you can have loops without a condition, the original version of the patch
> was rejecting the use of #pragma GCC novector, however during review it was
> changed to not due this with the reason that we didn't want to give a compile
> error with such cases.
> 
> However because annotations seem to be only be allowed on conditions (unless
> I'm mistaken?) the attached example ICEs because there's no condition.
> 
> This will have it ignore the pragma instead of ICEing.  I don't know if this is
> the best solution,  but as far as I can tell we can't attach the annotation to
> anything else.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Ok for master?

OK.

-- 
Joseph S. Myers
josmyers@redhat.com


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

end of thread, other threads:[~2024-01-08 22:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-08 12:56 [PATCH][frontend]: don't ice with pragma NOVECTOR if loop in C has no condition [PR113267] Tamar Christina
2024-01-08 22:02 ` Joseph Myers

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).