From patchwork Thu May 27 13:14:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1484614 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FrSwB6770z9sRN for ; Thu, 27 May 2021 23:14:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E7FAC3839C7D; Thu, 27 May 2021 13:14:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 486C83858023 for ; Thu, 27 May 2021 13:14:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 486C83858023 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Julian_Brown@mentor.com IronPort-SDR: tfyuZv6V6S6zNDEGEkU0DaQGUCPRB4muJZENYhjdWkneqv4aOYjNQiwxY58tswrBJNkFLOnwvD +dRQro2dT0sbOwWmo1B2Kj7ff+uq9iYcZgt6VSuS93b/TJDPlKh9r8u9irm/x79/v7B8Z5jlcz QGq2o78r5gxMYfynkVOkKR6jkq9VHRVvy9DiYdOdaGUnOOd0CJW/i6Que9+0E8c0LVTpkm0ca7 YFjiTzLJAl8ga9Cm3mmG3ODF77lpIxo/+xLevY0qaybMEevkXO9dnps1yRqrW3mULRoLmZWx5l y0o= X-IronPort-AV: E=Sophos;i="5.82,334,1613462400"; d="scan'208";a="61716339" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 27 May 2021 05:14:41 -0800 IronPort-SDR: fYmMq9S4BlMubCBKM0NtBcUF4kbS7sEfQbodJ3neZ6EJ7s2UxMS6RSscQ7+fAEYyo4+JoA9roc SU0CzSLdcyhrvqgK6b88y9X6LoaEaGoSMM3OYj7x0A72BfrdH+lqMhBz/BQoVueZpo+//XBYWr j30P0949djq0TbYjuTtpaewD/0dBrF9VL5sEHAgt8qG2DY0VPx8Bdd1UVQNdZNprZr0APkqdSW IuosRWJobUrSghTE2mxXZRh5AhZeBbW+X8GkZBmIaEbEr0WOO+v3uVSd8sn4JM8OfaL38b1Xtk aHQ= From: Julian Brown To: Subject: [PATCH] OpenMP: Use build_indirect_ref for struct deferences in C FE Date: Thu, 27 May 2021 06:14:25 -0700 Message-ID: <20210527131425.18390-1-julian@codesourcery.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jakub Jelinek , Tobias Burnus , Thomas Schwinge Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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 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; +}