[PATCH] OpenMP: Use build_indirect_ref for struct deferences in C FE

Julian Brown julian@codesourcery.com
Thu May 27 13:14:25 GMT 2021


This patch fixes an ICE in the C FE (discovered by Tobias) when a user
tries to use a dereference of a non-pointer-valued base (e.g. a plain
struct) in an OpenMP clause.

This patch has been tested on a tree that already has the following patches by
Chung-Lin applied:

  (a) https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570886.html
      "[PATCH, OpenMP 5.0] Improve OpenMP target support for C++ (includes PR92120 v3)"
  (b) https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570365.html
      "[PATCH, OpenMP 5.0] Implement relaxation of implicit map vs. existing device mappings (for mainline trunk)"
  (c) https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571195.html
      "[PATCH, OpenMP 5.0] Remove array section base-pointer mapping semantics, and other front-end adjustments (mainline trunk)"

Without those patches, equivalent changes are needed in several places
in the C FE to handle INDIRECT_REFs instead of only MEM_REFs, as at
present. So this one should go in after those patches, assuming it's
otherwise OK.

The C++ FE already catches this case correctly (though the error message
is different for C/C++).

Tested with offloading to NVPTX (and bootstrapped).

Thanks,

Julian

2021-05-27  Julian Brown  <julian@codesourcery.com>

gcc/c/
	* c-parser.c (c_parser_omp_variable_list); Call build_indirect_ref
	instead of build_simple_mem_ref for struct dereferences.

gcc/testsuite/
	* c-c++-common/gomp/target-indir-struct-1.c: New test.
---
 gcc/c/c-parser.c                                |  2 +-
 .../c-c++-common/gomp/target-indir-struct-1.c   | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/target-indir-struct-1.c

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 582f86b9b35..ee21be43ed8 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -13035,7 +13035,7 @@ c_parser_omp_variable_list (c_parser *parser,
 		{
 		  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);
+		    t = build_indirect_ref (op_loc, t, RO_ARROW);
 		  c_parser_consume_token (parser);
 		  if (!c_parser_next_token_is (parser, CPP_NAME))
 		    {
diff --git a/gcc/testsuite/c-c++-common/gomp/target-indir-struct-1.c b/gcc/testsuite/c-c++-common/gomp/target-indir-struct-1.c
new file mode 100644
index 00000000000..7e5ce2a61d5
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/target-indir-struct-1.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+struct t { int *p; };
+
+void foo () {
+  struct t s;
+  #pragma omp target map(to: s->p) /* { dg-error "invalid type argument of '->' \\(have 'struct t'\\)" "" { target c } } */ 
+  /* { dg-error "base operand of '->' has non-pointer type 't'" "" { target c++ } .-1 } */
+  {
+  }
+}
+
+int main (int argc, char *argv[])
+{
+  foo ();
+  return 0;
+}
-- 
2.29.2



More information about the Gcc-patches mailing list