[committed] Fix OpenMP atomic and for condition C++ parsing (PR c++/84341)

Message ID 20180212222814.GM5867@tucnak
State New
Headers show
Series
  • [committed] Fix OpenMP atomic and for condition C++ parsing (PR c++/84341)
Related show

Commit Message

Jakub Jelinek Feb. 12, 2018, 10:28 p.m.
Hi!

In these cases, we want the tree to be just a placeholder for the operation
plus 2 operands, we are going to take it appart later; by using build_min
we can avoid the asserts build2_loc does, because the operands might not
have the same type etc.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2018-02-12  Jakub Jelinek  <jakub@redhat.com>

	PR c++/84341
	* parser.c (cp_parser_binary_expression): Use build_min instead of
	build2_loc to build the no_toplevel_fold_p toplevel binary expression.

	* c-c++-common/gomp/pr84341.c: New test.


	Jakub

Patch

--- gcc/cp/parser.c.jj	2018-02-12 19:17:37.939216029 +0100
+++ gcc/cp/parser.c	2018-02-12 20:05:55.287322491 +0100
@@ -9330,12 +9330,14 @@  cp_parser_binary_expression (cp_parser*
       if (no_toplevel_fold_p
 	  && lookahead_prec <= current.prec
 	  && sp == stack)
-	current.lhs = build2_loc (combined_loc,
-				  current.tree_type,
-				  TREE_CODE_CLASS (current.tree_type)
-				  == tcc_comparison
-				  ? boolean_type_node : TREE_TYPE (current.lhs),
-				  current.lhs, rhs);
+	{
+	  current.lhs
+	    = build_min (current.tree_type,
+			 TREE_CODE_CLASS (current.tree_type) == tcc_comparison
+			 ? boolean_type_node : TREE_TYPE (current.lhs),
+			 current.lhs.get_value (), rhs.get_value ());
+	  SET_EXPR_LOCATION (current.lhs, combined_loc);
+	}
       else
         {
           current.lhs = build_x_binary_op (combined_loc, current.tree_type,
--- gcc/testsuite/c-c++-common/gomp/pr84341.c.jj	2018-02-12 20:08:20.500327702 +0100
+++ gcc/testsuite/c-c++-common/gomp/pr84341.c	2018-02-12 20:08:00.290326972 +0100
@@ -0,0 +1,10 @@ 
+/* PR c++/84341 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+void
+foo (int i)
+{
+  #pragma omp atomic
+    i = &i + 1;		/* { dg-error "invalid form of" } */
+}