diff mbox series

[committed] openmp: Ensure proper diagnostics for -> in map/to/from clauses [PR104532]

Message ID Yg4WJeJI41hSgpew@tucnak
State New
Headers show
Series [committed] openmp: Ensure proper diagnostics for -> in map/to/from clauses [PR104532] | expand

Commit Message

Jakub Jelinek Feb. 17, 2022, 9:32 a.m. UTC
Hi!

The following patch uses the functions normal CPP_DEREF parsing uses,
i.e. convert_lvalue_to_rvalue and build_indirect_ref, instead of
blindly calling build_simple_mem_ref, so that if the variable does not
have correct type, we properly diagnose it instead of ICEing on it.

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

2022-02-17  Jakub Jelinek  <jakub@redhat.com>

	PR c/104532
	* c-parser.cc (c_parser_omp_variable_list): For CPP_DEREF, use
	convert_lvalue_to_rvalue and build_indirect_ref instead of
	build_simple_mem_ref.

	* gcc.dg/gomp/pr104532.c: New test.


	Jakub
diff mbox series

Patch

--- gcc/c/c-parser.cc.jj	2022-02-11 00:19:22.121067484 +0100
+++ gcc/c/c-parser.cc	2022-02-16 14:12:03.562041597 +0100
@@ -13145,7 +13145,16 @@  c_parser_omp_variable_list (c_parser *pa
 		{
 		  location_t op_loc = c_parser_peek_token (parser)->location;
 		  if (c_parser_next_token_is (parser, CPP_DEREF))
-		    t = build_simple_mem_ref (t);
+		    {
+		      c_expr t_expr;
+		      t_expr.value = t;
+		      t_expr.original_code = ERROR_MARK;
+		      t_expr.original_type = NULL;
+		      set_c_expr_source_range (&t_expr, op_loc, op_loc);
+		      t_expr = convert_lvalue_to_rvalue (op_loc, t_expr,
+							 true, false);
+		      t = build_indirect_ref (op_loc, t_expr.value, RO_ARROW);
+		    }
 		  c_parser_consume_token (parser);
 		  if (!c_parser_next_token_is (parser, CPP_NAME))
 		    {
--- gcc/testsuite/gcc.dg/gomp/pr104532.c.jj	2022-02-16 14:23:51.749180699 +0100
+++ gcc/testsuite/gcc.dg/gomp/pr104532.c	2022-02-16 14:23:31.896457132 +0100
@@ -0,0 +1,15 @@ 
+/* PR c/104532 */
+/* { dg-do compile } */
+
+void
+foo (int x)
+{
+  #pragma omp target enter data map (to: x->vectors)	/* { dg-error "invalid type argument of '->'" } */
+}							/* { dg-error "must contain at least one" "" { target *-*-* } .-1 } */
+
+void
+bar (int x)
+{
+  #pragma omp target enter data map (to: x->vectors[])	/* { dg-error "invalid type argument of '->'" } */
+}							/* { dg-error "must contain at least one" "" { target *-*-* } .-1 } */
+                                                        /* { dg-error "expected expression before" "" { target *-*-* } .-2 } */