From: Tamar Christina <tamar.christina@arm.com>
To: gcc-patches@gcc.gnu.org
Cc: nd@arm.com, jason@redhat.com, nathan@acm.org
Subject: [PATCH][c++ frontend]: check for missing condition for novector [PR115623]
Date: Tue, 25 Jun 2024 09:01:27 +0100 [thread overview]
Message-ID: <patch-18582-tamar@arm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1841 bytes --]
Hi All,
It looks like I forgot to check in the C++ frontend if a condition exist for the
loop being adorned with novector. This causes a segfault because cond isn't
expected to be null.
This fixes it by issuing the same kind of diagnostics we issue for the other
pragmas.
Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
Ok for master? and backport to GCC-14?
Thanks,
Tamar
gcc/cp/ChangeLog:
PR c++/115623
* parser.cc (cp_parser_c_for): Add check for C++ cond.
gcc/testsuite/ChangeLog:
PR c++/115623
* g++.dg/vect/vect-novector-pragma_2.cc: New test.
---
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index e7409b856f1127e303c6515a3bb2d61a10e7c378..24d7b0e4992fdff69951ac5955f304e473f53374 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -14107,6 +14107,12 @@ cp_parser_c_for (cp_parser *parser, tree scope, tree init, bool ivdep,
"%<GCC unroll%> pragma");
condition = error_mark_node;
}
+ else if (novector)
+ {
+ cp_parser_error (parser, "missing loop condition in loop with "
+ "%<GCC novector%> pragma");
+ condition = error_mark_node;
+ }
finish_for_cond (condition, stmt, ivdep, unroll, novector);
/* Look for the `;'. */
cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
diff --git a/gcc/testsuite/g++.dg/vect/vect-novector-pragma_2.cc b/gcc/testsuite/g++.dg/vect/vect-novector-pragma_2.cc
new file mode 100644
index 0000000000000000000000000000000000000000..05dba4db1c6544bc53cd05482d1b2e767052cf43
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/vect-novector-pragma_2.cc
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+void f (char *a, int i)
+{
+#pragma GCC novector
+ for (;;i++)
+ a[i] *= 2;
+}
+
+/* { dg-error "missing loop condition in loop with 'GCC novector' pragma before ';' token" "" { target *-*-* } 6 } */
--
[-- Attachment #2: rb18582.patch --]
[-- Type: text/x-diff, Size: 1251 bytes --]
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index e7409b856f1127e303c6515a3bb2d61a10e7c378..24d7b0e4992fdff69951ac5955f304e473f53374 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -14107,6 +14107,12 @@ cp_parser_c_for (cp_parser *parser, tree scope, tree init, bool ivdep,
"%<GCC unroll%> pragma");
condition = error_mark_node;
}
+ else if (novector)
+ {
+ cp_parser_error (parser, "missing loop condition in loop with "
+ "%<GCC novector%> pragma");
+ condition = error_mark_node;
+ }
finish_for_cond (condition, stmt, ivdep, unroll, novector);
/* Look for the `;'. */
cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
diff --git a/gcc/testsuite/g++.dg/vect/vect-novector-pragma_2.cc b/gcc/testsuite/g++.dg/vect/vect-novector-pragma_2.cc
new file mode 100644
index 0000000000000000000000000000000000000000..05dba4db1c6544bc53cd05482d1b2e767052cf43
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/vect-novector-pragma_2.cc
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+void f (char *a, int i)
+{
+#pragma GCC novector
+ for (;;i++)
+ a[i] *= 2;
+}
+
+/* { dg-error "missing loop condition in loop with 'GCC novector' pragma before ';' token" "" { target *-*-* } 6 } */
next reply other threads:[~2024-06-25 8:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-25 8:01 Tamar Christina [this message]
2024-06-25 16:10 ` Jason Merrill
2024-06-25 16:52 ` Tamar Christina
2024-06-25 21:23 ` Jason Merrill
2024-06-27 15:25 ` Tamar Christina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-18582-tamar@arm.com \
--to=tamar.christina@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=nathan@acm.org \
--cc=nd@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).