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]

[C PATCH] Reject #pragma omp for for (unsigned int i = 10; i != 0; i--) (PR c/39495)


Hi!

My patch from yesterday caused the C FE to accept != in #pragma omp for
conditions, the C++ FE already has a special parsing routine for the
condititions.

To fix this in the C FE and avoid duplicating the whole
c_parser_binary_expression I need a small change to that routine.
Joseph, is that ok for you?  Bootstrapped/regtested on x86_64-linux.

2009-03-20  Jakub Jelinek  <jakub@redhat.com>

	PR c/39495
	* c-parser.c (c_parser_binary_expression): Add first argument, use it
	instead of initial c_parser_cast_expression call if non-NULL.
	(c_parser_conditional_expression): Adjust caller.
	(c_parser_omp_for_loop): Ensure the condition is only <, <=, >, >=.

	* gcc.dg/gomp/pr39495-2.c: Remove xfails.

--- gcc/c-parser.c.jj	2009-02-18 08:48:40.000000000 +0100
+++ gcc/c-parser.c	2009-03-20 14:21:57.000000000 +0100
@@ -903,7 +903,8 @@ static tree c_parser_asm_clobbers (c_par
 static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *);
 static struct c_expr c_parser_conditional_expression (c_parser *,
 						      struct c_expr *);
-static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *);
+static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *,
+						 struct c_expr *);
 static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *);
 static struct c_expr c_parser_unary_expression (c_parser *);
 static struct c_expr c_parser_sizeof_expression (c_parser *);
@@ -4446,7 +4447,7 @@ c_parser_conditional_expression (c_parse
   gcc_assert (!after || c_dialect_objc ());
 
   cond_loc = c_parser_peek_token (parser)->location;
-  cond = c_parser_binary_expression (parser, after);
+  cond = c_parser_binary_expression (parser, after, NULL);
   protected_set_expr_location (cond.value, cond_loc);
 
   if (c_parser_next_token_is_not (parser, CPP_QUERY))
@@ -4542,7 +4543,8 @@ c_parser_conditional_expression (c_parse
 */
 
 static struct c_expr
-c_parser_binary_expression (c_parser *parser, struct c_expr *after)
+c_parser_binary_expression (c_parser *parser, struct c_expr *after,
+			    struct c_expr *first)
 {
   /* A binary expression is parsed using operator-precedence parsing,
      with the operands being cast expressions.  All the binary
@@ -4617,7 +4619,10 @@ c_parser_binary_expression (c_parser *pa
     sp--;								      \
   } while (0)
   gcc_assert (!after || c_dialect_objc ());
-  stack[0].expr = c_parser_cast_expression (parser, after);
+  if (first)
+    stack[0].expr = *first;
+  else
+    stack[0].expr = c_parser_cast_expression (parser, after);
   stack[0].prec = PREC_NONE;
   sp = 0;
   while (true)
@@ -7652,10 +7657,22 @@ c_parser_omp_for_loop (c_parser *parser,
       if (c_parser_next_token_is_not (parser, CPP_SEMICOLON))
 	{
 	  location_t cond_loc = c_parser_peek_token (parser)->location;
-
-	  cond = c_parser_expression_conv (parser).value;
-	  cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
-	  protected_set_expr_location (cond, cond_loc);
+	  struct c_expr lhs = c_parser_cast_expression (parser, NULL);
+	  switch (c_parser_peek_token (parser)->type)
+	    {
+	    case CPP_LESS:
+	    case CPP_GREATER:
+	    case CPP_LESS_EQ:
+	    case CPP_GREATER_EQ:
+	      cond = c_parser_binary_expression (parser, NULL, &lhs).value;
+	      cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
+	      protected_set_expr_location (cond, cond_loc);
+	      break;
+	    default:
+	      c_parser_binary_expression (parser, NULL, &lhs);
+	      cond = error_mark_node;
+	      break;
+	    }
 	}
       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
 
--- gcc/testsuite/gcc.dg/gomp/pr39495-2.c.jj	2009-03-19 14:57:11.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/pr39495-2.c	2009-03-20 14:19:29.000000000 +0100
@@ -13,25 +13,25 @@ foo (void)
   unsigned int u;
 
 #pragma omp for
-  for (i = INT_MIN + 6; i != INT_MIN; i--)	/* { dg-error "invalid controlling predicate" "" { xfail *-*-* } } */
+  for (i = INT_MIN + 6; i != INT_MIN; i--)	/* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
   for (i = INT_MIN + 6; i == INT_MIN; i--)	/* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
-  for (i = INT_MAX - 6; i != INT_MAX; i++)	/* { dg-error "invalid controlling predicate" "" { xfail *-*-* }  } */
+  for (i = INT_MAX - 6; i != INT_MAX; i++)	/* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
   for (i = INT_MAX - 6; i == INT_MAX; i++)	/* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
-  for (u = 6; u != 0; u--)			/* { dg-error "invalid controlling predicate" "" { xfail *-*-* }  } */
+  for (u = 6; u != 0; u--)			/* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
   for (u = 6; u == 0; u--)			/* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
-  for (u = UINT_MAX - 6; u != UINT_MAX; u++)	/* { dg-error "invalid controlling predicate" "" { xfail *-*-* }  } */
+  for (u = UINT_MAX - 6; u != UINT_MAX; u++)	/* { dg-error "invalid controlling predicate" } */
     ;
 #pragma omp for
   for (u = UINT_MAX - 6; u == UINT_MAX; u++)	/* { dg-error "invalid controlling predicate" } */

	Jakub


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