https://gcc.gnu.org/g:1742b699c31e3ac4dadbedb6036ee2498b569259

commit r14-10378-g1742b699c31e3ac4dadbedb6036ee2498b569259
Author: Tamar Christina <tamar.christ...@arm.com>
Date:   Thu Jul 4 11:01:55 2024 +0100

    c++ frontend: check for missing condition for novector [PR115623]
    
    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 ignoring the pragma when there's no loop condition
    the same way we do in the C frontend.
    
    gcc/cp/ChangeLog:
    
            PR c++/115623
            * semantics.cc (finish_for_cond): Add check for C++ cond.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/115623
            * g++.dg/vect/vect-novector-pragma_2.cc: New test.
    
    (cherry picked from commit 84acbfbecbdbc3fb2a395bd97e338b2b26fad374)

Diff:
---
 gcc/cp/semantics.cc                                 |  2 +-
 gcc/testsuite/g++.dg/vect/vect-novector-pragma_2.cc | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index b18fc7c61be..ec741c0b203 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -1501,7 +1501,7 @@ finish_for_cond (tree cond, tree for_stmt, bool ivdep, 
tree unroll,
                                  build_int_cst (integer_type_node,
                                                 annot_expr_unroll_kind),
                                  unroll);
-  if (novector && cond != error_mark_node)
+  if (novector && cond && cond != error_mark_node)
     FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
                                  TREE_TYPE (FOR_COND (for_stmt)),
                                  FOR_COND (for_stmt),
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 00000000000..d2a8eee8d71
--- /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;
+}
+
+

Reply via email to