public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] OpenMP: Use build_indirect_ref for struct deferences in C FE
@ 2021-05-27 13:14 Julian Brown
  0 siblings, 0 replies; only message in thread
From: Julian Brown @ 2021-05-27 13:14 UTC (permalink / raw)
  To: gcc-patches; +Cc: Chung-Lin Tang, Tobias Burnus, Jakub Jelinek, Thomas Schwinge

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-27 13:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 13:14 [PATCH] OpenMP: Use build_indirect_ref for struct deferences in C FE Julian Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).