]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Calculate correct size for optional arguments used in the firstprivate clause
authorKwok Cheung Yeung <kcy@codesourcery.com>
Wed, 30 Jan 2019 19:22:08 +0000 (11:22 -0800)
committerThomas Schwinge <thomas@codesourcery.com>
Tue, 3 Mar 2020 11:15:06 +0000 (12:15 +0100)
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)

gcc/ChangeLog.omp
gcc/omp-general.c
gcc/omp-general.h
gcc/omp-low.c

index 5281ba66d3bdf042e203a9c130f907d8052baa37..36cabca9860ec828e39b1f432d27498c8ed8761a 100644 (file)
@@ -1,3 +1,10 @@
+2019-01-30  Kwok Cheung Yeung <kcy@codesourcery.com>
+
+       * 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  <julian@codesourcery.com>
            Chung-Lin Tang  <cltang@codesourcery.com>
 
index b3cd9cb103d99adda415c92cd4eef886e55bd3ea..64559fa6d9f0b56c969fe0c910fb0b6d37db2cc9 100644 (file)
@@ -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
index 575d1f0c655242aaa95267457b441e615b74b91c..0bd0ade9f9d56d6a9a9e5d6c1e74a8d37ad34199 100644 (file)
@@ -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);
index dc95d01e51a40319c42a3ad4e730da9126dc8bb5..919ffad565b92c108d509297a66740426fa6516c 100644 (file)
@@ -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);
                  }