From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 117460 invoked by alias); 13 May 2015 20:57:29 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 117446 invoked by uid 89); 13 May 2015 20:57:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 13 May 2015 20:57:26 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1YsdiU-0002FJ-4x from Thomas_Schwinge@mentor.com ; Wed, 13 May 2015 13:57:22 -0700 Received: from feldtkeller.schwinge.homeip.net (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Wed, 13 May 2015 21:57:20 +0100 From: Thomas Schwinge To: Jakub Jelinek , CC: Cesar Philippidis Subject: [gomp4] Prohibit C++ reference types in OpenACC regions In-Reply-To: <55410685.3020603@mentor.com> References: <55410685.3020603@mentor.com> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Wed, 13 May 2015 21:01:00 -0000 Message-ID: <87sib0jivr.fsf@schwinge.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-SW-Source: 2015-05/txt/msg01275.txt.bz2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-length: 12608 Hi! On Wed, 29 Apr 2015 09:27:49 -0700, Cesar Philippidis wrote: > This patch teaches the c++ front end to error when reference typed > variables are used in openacc parallel and kernels regions. The c++ > front end changes are pretty straightforward. I did, however, have to > make omp_mappable_type langhook aware of openacc. That's because openmp > apparently supports reference types, whereas openacc does not. I guess > aliased mapping isn't a problem for non-openmp target regions. Committed to gomp-4_0-branch in r223179: commit ee20456534e0fd80333e50bab0821a0e20f065e5 Author: tschwinge Date: Wed May 13 20:56:31 2015 +0000 Prohibit C++ reference types in OpenACC regions =20=20=20=20 gcc/ * langhooks-def.h (lhd_omp_mappable_type): Add bool argument. * langhooks.c (lhd_omp_mappable_type): Likewise, for the parameter. * langhooks.h (struct lang_hooks_for_types): Add bool oacc argument. * gimplify.c (omp_notice_variable): Use it when calling the omp_mappable_type langhook. gcc/c/ * c-decl.c (c_decl_attributes): Update call to omp_mappable_type. * c-typeck.c (c_finish_omp_clauses): Likewise. gcc/cp/ * cp-tree.h (cp_omp_mappable_type): Add bool parameter. * decl2.c (cp_check_const_attributes): Likewise. Use it. (cp_omp_mappable_type): Update call to cp_omp_mappable_type. (cplus_decl_attributes): Likewise. * semantics.c (finish_omp_clauses): Likewise. gcc/testsuite/ * g++.dg/goacc/reference.C: New test. =20=20=20=20 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@2231= 79 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog.gomp | 10 ++++++++ gcc/c/ChangeLog.gomp | 5 ++++ gcc/c/c-decl.c | 3 ++- gcc/c/c-typeck.c | 6 +++-- gcc/cp/ChangeLog.gomp | 8 +++++++ gcc/cp/cp-tree.h | 2 +- gcc/cp/decl2.c | 8 ++++--- gcc/cp/semantics.c | 11 ++++++--- gcc/gimplify.c | 4 +++- gcc/langhooks-def.h | 2 +- gcc/langhooks.c | 2 +- gcc/langhooks.h | 2 +- gcc/testsuite/ChangeLog.gomp | 4 ++++ gcc/testsuite/g++.dg/goacc/reference.C | 42 ++++++++++++++++++++++++++++++= ++++ 14 files changed, 95 insertions(+), 14 deletions(-) diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp index 4901bf9..9e72962 100644 --- gcc/ChangeLog.gomp +++ gcc/ChangeLog.gomp @@ -1,3 +1,13 @@ +2015-05-13 Cesar Philippidis + + * langhooks-def.h (lhd_omp_mappable_type): Add bool argument. + * langhooks.c (lhd_omp_mappable_type): Likewise, for the + parameter. + * langhooks.h (struct lang_hooks_for_types): Add bool oacc + argument. + * gimplify.c (omp_notice_variable): Use it when calling the + omp_mappable_type langhook. + 2015-05-13 Thomas Schwinge Bernd Schmidt Cesar Philippidis diff --git gcc/c/ChangeLog.gomp gcc/c/ChangeLog.gomp index 2e3cd13..08c8ed0 100644 --- gcc/c/ChangeLog.gomp +++ gcc/c/ChangeLog.gomp @@ -1,3 +1,8 @@ +2015-05-13 Cesar Philippidis + + * c-decl.c (c_decl_attributes): Update call to omp_mappable_type. + * c-typeck.c (c_finish_omp_clauses): Likewise. + 2015-05-13 Thomas Schwinge Bernd Schmidt Cesar Philippidis diff --git gcc/c/c-decl.c gcc/c/c-decl.c index 4f6761d..bf99a45 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -4414,7 +4414,8 @@ c_decl_attributes (tree *node, tree attributes, int f= lags) error ("%q+D in block scope inside of declare target directive", *node); else if (TREE_CODE (*node) =3D=3D VAR_DECL - && !lang_hooks.types.omp_mappable_type (TREE_TYPE (*node))) + && !lang_hooks.types.omp_mappable_type (TREE_TYPE (*node), + false)) error ("%q+D in declare target directive does not have mappable type", *node); else diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index 5ec04cc..974a3fc 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -12445,7 +12445,8 @@ c_finish_omp_clauses (tree clauses, bool oacc) else { t =3D OMP_CLAUSE_DECL (c); - if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (t))) + if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (t), + oacc)) { error_at (OMP_CLAUSE_LOCATION (c), "array section does not have mappable type " @@ -12478,7 +12479,8 @@ c_finish_omp_clauses (tree clauses, bool oacc) && (OMP_CLAUSE_MAP_KIND (c) =3D=3D GOMP_MAP_POINTER || (OMP_CLAUSE_MAP_KIND (c) =3D=3D GOMP_MAP_FORCE_DEVICEPTR))) - && !lang_hooks.types.omp_mappable_type (TREE_TYPE (t))) + && !lang_hooks.types.omp_mappable_type (TREE_TYPE (t), + oacc)) { error_at (OMP_CLAUSE_LOCATION (c), "%qD does not have a mappable type in %qs clause", t, diff --git gcc/cp/ChangeLog.gomp gcc/cp/ChangeLog.gomp index 33bd97c..529206a 100644 --- gcc/cp/ChangeLog.gomp +++ gcc/cp/ChangeLog.gomp @@ -1,3 +1,11 @@ +2015-05-13 Cesar Philippidis + + * cp-tree.h (cp_omp_mappable_type): Add bool parameter. + * decl2.c (cp_check_const_attributes): Likewise. Use it. + (cp_omp_mappable_type): Update call to cp_omp_mappable_type. + (cplus_decl_attributes): Likewise. + * semantics.c (finish_omp_clauses): Likewise. + 2015-05-13 Thomas Schwinge Bernd Schmidt Cesar Philippidis diff --git gcc/cp/cp-tree.h gcc/cp/cp-tree.h index 302dfe2..0b52e8f 100644 --- gcc/cp/cp-tree.h +++ gcc/cp/cp-tree.h @@ -5501,7 +5501,7 @@ extern bool possibly_inlined_p (tree); extern int parm_index (tree); extern tree vtv_start_verification_constructor_init_function (void); extern tree vtv_finish_verification_constructor_init_function (tree); -extern bool cp_omp_mappable_type (tree); +extern bool cp_omp_mappable_type (tree, bool); =20 /* in error.c */ extern void init_error (void); diff --git gcc/cp/decl2.c gcc/cp/decl2.c index 0d47847..ff9d409 100644 --- gcc/cp/decl2.c +++ gcc/cp/decl2.c @@ -1403,7 +1403,7 @@ cp_check_const_attributes (tree attributes) =20 /* Return true if TYPE is an OpenMP mappable type. */ bool -cp_omp_mappable_type (tree type) +cp_omp_mappable_type (tree type, bool oacc) { /* Mappable type has to be complete. */ if (type =3D=3D error_mark_node || !COMPLETE_TYPE_P (type)) @@ -1423,9 +1423,11 @@ cp_omp_mappable_type (tree type) return false; /* All fields must have mappable types. */ else if (TREE_CODE (field) =3D=3D FIELD_DECL - && !cp_omp_mappable_type (TREE_TYPE (field))) + && !cp_omp_mappable_type (TREE_TYPE (field), oacc)) return false; } + if (oacc && TREE_CODE (type) =3D=3D REFERENCE_TYPE) + return false; return true; } =20 @@ -1455,7 +1457,7 @@ cplus_decl_attributes (tree *decl, tree attributes, i= nt flags) *decl); else if (!processing_template_decl && TREE_CODE (*decl) =3D=3D VAR_DECL - && !cp_omp_mappable_type (TREE_TYPE (*decl))) + && !cp_omp_mappable_type (TREE_TYPE (*decl), false)) error ("%q+D in declare target directive does not have mappable type", *decl); else diff --git gcc/cp/semantics.c gcc/cp/semantics.c index 896bae5..19b8d0b 100644 --- gcc/cp/semantics.c +++ gcc/cp/semantics.c @@ -5866,7 +5866,7 @@ finish_omp_clauses (tree clauses, bool oacc) t =3D OMP_CLAUSE_DECL (c); if (TREE_CODE (t) !=3D TREE_LIST && !type_dependent_expression_p (t) - && !cp_omp_mappable_type (TREE_TYPE (t))) + && !cp_omp_mappable_type (TREE_TYPE (t), oacc)) { error_at (OMP_CLAUSE_LOCATION (c), "array section does not have mappable type " @@ -5877,6 +5877,11 @@ finish_omp_clauses (tree clauses, bool oacc) } break; } + if (oacc && TREE_CODE (TREE_TYPE (t)) =3D=3D REFERENCE_TYPE) + { + error_at (OMP_CLAUSE_LOCATION (c), + "reference types are not supported in OpenACC"); + } if (t =3D=3D error_mark_node) remove =3D true; else if (TREE_CODE (t) !=3D VAR_DECL && TREE_CODE (t) !=3D PARM_DECL) @@ -5907,10 +5912,10 @@ finish_omp_clauses (tree clauses, bool oacc) else if (!(OMP_CLAUSE_CODE (c) =3D=3D OMP_CLAUSE_MAP && OMP_CLAUSE_MAP_KIND (c) =3D=3D GOMP_MAP_POINTER) && !type_dependent_expression_p (t) - && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t)) + && !cp_omp_mappable_type (((TREE_CODE (TREE_TYPE (t)) =3D=3D REFERENCE_TYPE) ? TREE_TYPE (TREE_TYPE (t)) - : TREE_TYPE (t))) + : TREE_TYPE (t)), oacc)) { error_at (OMP_CLAUSE_LOCATION (c), "%qD does not have a mappable type in %qs clause", t, diff --git gcc/gimplify.c gcc/gimplify.c index b7bc0c4..912b60f 100644 --- gcc/gimplify.c +++ gcc/gimplify.c @@ -5910,7 +5910,9 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tr= ee decl, bool in_code) } } =20 - if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (decl))) + if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (decl), + ctx->region_kind + =3D=3D ORK_OACC)) { error ("%qD referenced in target region does not have " "a mappable type", decl); diff --git gcc/langhooks-def.h gcc/langhooks-def.h index 303b4b6..15b9896 100644 --- gcc/langhooks-def.h +++ gcc/langhooks-def.h @@ -79,7 +79,7 @@ extern void lhd_omp_finish_clause (tree, gimple_seq *); struct gimplify_omp_ctx; extern void lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *, tree); -extern bool lhd_omp_mappable_type (tree); +extern bool lhd_omp_mappable_type (tree, bool); =20 #define LANG_HOOKS_NAME "GNU unknown" #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct lang_identifier) diff --git gcc/langhooks.c gcc/langhooks.c index 74f8351..031f158 100644 --- gcc/langhooks.c +++ gcc/langhooks.c @@ -555,7 +555,7 @@ lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_= ctx *c ATTRIBUTE_UNUSED, /* Return true if TYPE is an OpenMP mappable type. */ =20 bool -lhd_omp_mappable_type (tree type) +lhd_omp_mappable_type (tree type, bool oacc ATTRIBUTE_UNUSED) { /* Mappable type has to be complete. */ if (type =3D=3D error_mark_node || !COMPLETE_TYPE_P (type)) diff --git gcc/langhooks.h gcc/langhooks.h index 4039e8f..af02f27 100644 --- gcc/langhooks.h +++ gcc/langhooks.h @@ -112,7 +112,7 @@ struct lang_hooks_for_types void (*omp_firstprivatize_type_sizes) (struct gimplify_omp_ctx *, tree); =20 /* Return true if TYPE is a mappable type. */ - bool (*omp_mappable_type) (tree type); + bool (*omp_mappable_type) (tree type, bool oacc); =20 /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purpose= s. Called only after doing all language independent checks. diff --git gcc/testsuite/ChangeLog.gomp gcc/testsuite/ChangeLog.gomp index 9e5f114..e987031 100644 --- gcc/testsuite/ChangeLog.gomp +++ gcc/testsuite/ChangeLog.gomp @@ -1,3 +1,7 @@ +2015-05-13 Cesar Philippidis + + * g++.dg/goacc/reference.C: New test. + 2015-05-13 Thomas Schwinge Bernd Schmidt Cesar Philippidis diff --git gcc/testsuite/g++.dg/goacc/reference.C gcc/testsuite/g++.dg/goac= c/reference.C new file mode 100644 index 0000000..4a8d74a --- /dev/null +++ gcc/testsuite/g++.dg/goacc/reference.C @@ -0,0 +1,42 @@ +// { dg-do compile } +// { dg-options "-fopenacc" } + +int +test1 (int &ref) +{ +#pragma acc kernels copy (ref) // { dg-error "reference types are not supp= orted in OpenACC" } + { + ref =3D 10; + } +} + +int +test2 (int &ref) +{ + int b; +#pragma acc kernels copyout (b) + { + b =3D ref + 10; // { dg-error "referenced in target region does not ha= ve a mappable type" } + } + +#pragma acc parallel copyout (b) + { + b =3D ref + 10; // { dg-error "referenced in target region does not ha= ve a mappable type" } + } + + ref =3D b; +} + +int +main() +{ + int a =3D 0; + int &ref_a =3D a; + + #pragma acc parallel copy (a, ref_a) // { dg-error "reference types are = not supported in OpenACC" } + { + ref_a =3D 5; + } + + return a; +} Gr=C3=BC=C3=9Fe, Thomas --=-=-= Content-Type: application/pgp-signature Content-length: 472 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVU7qoAAoJEPoxNhtoi6COdgcH/Al/0JeUNZXv+riuILnCMBqj Za+76wAcsMYHnW38fAkvmPxkgtNoYG09eEQFICcXLlFAn96trNWuD0Wv3TGRaD9J sor9USCt6hbvY39YcVzBbLtHlA3gHMYFYmIaIk+7sDY+m8AtrAVgaKni3c7yxgan Ik6Xr4RVfWja0kQpL2IqHAUV+VcGfv3qQ9FzP2rsRjbrFZ/CVtOLZRKnjbTRWKWj X9axatsFJzCSOyJIaYHwkqkTeXe3EnQlVZYTkEkIXVkeKcHVy3xLrVX8iDVe/Hx0 lLyDmsO+456MAhiZjoktoHMbaJ6vARzUOuaJE8LyNIYDF2gUhGh6SYZSrlp7BZU= =rnWY -----END PGP SIGNATURE----- --=-=-=--