This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix ICE on omp for with type dependent pointer iterator (PR c++/48632)


Hi!

When the omp for iterator is known to be a pointer, even when it is type
dependent there is no point in assuming it might be a class iterator,
and by not calling cp_parser_omp_for_incr we can avoid troubles with
using PLUS_EXPR when POINTER_PLUS_EXPR ought to be used (similarly for
MINUS_EXPR when we'd have to negate and for invalid MULT_EXPR we'd just
ICE without any replacement).

Bootstrapped/regtested on x86_64-linux and i686-linux, will commit tomorrow.

2011-04-18  Jakub Jelinek  <jakub@redhat.com>

	PR c++/48632
	* parser.c (cp_parser_omp_for_loop): Don't use cp_parser_omp_for_incr
	for type dependent pointers.

	* g++.dg/gomp/pr48632.C: New test.

--- gcc/cp/parser.c.jj	2011-04-18 11:28:02.000000000 +0200
+++ gcc/cp/parser.c	2011-04-18 11:53:56.000000000 +0200
@@ -24496,7 +24496,8 @@ cp_parser_omp_for_loop (cp_parser *parse
 	  /* If decl is an iterator, preserve the operator on decl
 	     until finish_omp_for.  */
 	  if (decl
-	      && (type_dependent_expression_p (decl)
+	      && ((type_dependent_expression_p (decl)
+		   && !POINTER_TYPE_P (TREE_TYPE (decl)))
 		  || CLASS_TYPE_P (TREE_TYPE (decl))))
 	    incr = cp_parser_omp_for_incr (parser, decl);
 	  else
--- gcc/testsuite/g++.dg/gomp/pr48632.C.jj	2011-04-18 12:01:36.000000000 +0200
+++ gcc/testsuite/g++.dg/gomp/pr48632.C	2011-04-18 12:00:51.000000000 +0200
@@ -0,0 +1,22 @@
+// PR c++/48632
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+template<typename T>
+void
+foo (T *x, T *y, unsigned z)
+{
+#pragma omp parallel for
+  for (T *p = x; p < y; p += z)
+    ;
+#pragma omp parallel for
+  for (T *p = y; p > x; p -= z)
+    ;
+}
+
+int
+main ()
+{
+  char buf[10];
+  foo (&buf[0], &buf[9], 1);
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]