From: Kwok Cheung Yeung Date: Wed, 30 Jan 2019 19:22:08 +0000 (-0800) Subject: Calculate correct size for optional arguments used in the firstprivate clause X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9ac15279c79a2d5b63f8126b87b01bd0d82568b;p=thirdparty%2Fgcc.git Calculate correct size for optional arguments used in the firstprivate clause The lowering for firstprivate uses the pointer size rather than the size of the referenced object when passed an optional argument. This patch detects optional arguments as a special case and treats them as reference types. gcc/ * omp-general.c (omp_is_optional_argument): New. * omp-general.h (omp_is_optional_argument): New. * omp-low.c (lower_omp_target): Use size of referenced object when optional argument used as argument to firstprivate. (cherry picked from openacc-gcc-9-branch commit 57093894d563543f5fe5e2b76f974340375c5421) --- diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 5281ba66d3bd..36cabca9860e 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,10 @@ +2019-01-30 Kwok Cheung Yeung + + * omp-general.c (omp_is_optional_argument): New. + * omp-general.h (omp_is_optional_argument): New. + * omp-low.c (lower_omp_target): Use size of referenced object when + optional argument used as argument to firstprivate. + 2018-12-11 Julian Brown Chung-Lin Tang diff --git a/gcc/omp-general.c b/gcc/omp-general.c index b3cd9cb103d9..64559fa6d9f0 100644 --- a/gcc/omp-general.c +++ b/gcc/omp-general.c @@ -48,6 +48,15 @@ omp_find_clause (tree clauses, enum omp_clause_code kind) return NULL_TREE; } +/* Return true if DECL is a Fortran optional argument. */ + +bool +omp_is_optional_argument (tree decl) +{ + return TREE_CODE (decl) == PARM_DECL && DECL_BY_REFERENCE (decl) + && TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE; +} + /* Return true if DECL is a reference type. */ bool diff --git a/gcc/omp-general.h b/gcc/omp-general.h index 575d1f0c6552..0bd0ade9f9d5 100644 --- a/gcc/omp-general.h +++ b/gcc/omp-general.h @@ -72,6 +72,7 @@ struct omp_for_data #define OACC_FN_ATTRIB "oacc function" extern tree omp_find_clause (tree clauses, enum omp_clause_code kind); +extern bool omp_is_optional_argument (tree decl); extern bool omp_is_reference (tree decl); extern void omp_adjust_for_condition (location_t loc, enum tree_code *cond_code, tree *n2, tree v, tree step); diff --git a/gcc/omp-low.c b/gcc/omp-low.c index dc95d01e51a4..919ffad565b9 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -10136,7 +10136,8 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx) else { s = TREE_TYPE (ovar); - if (TREE_CODE (s) == REFERENCE_TYPE) + if (TREE_CODE (s) == REFERENCE_TYPE + || omp_is_optional_argument (ovar)) s = TREE_TYPE (s); s = TYPE_SIZE_UNIT (s); }