diff options
author | Harald Anlauf <anlauf@gmx.de> | 2025-01-19 21:06:56 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2025-01-20 18:43:18 +0100 |
commit | 0d1e62b83561baa185bf080515750a89dd3ac410 (patch) | |
tree | a4dd9f658eba51b9d148b180a5b9522869dbffc3 /gcc/fortran/trans-array.cc | |
parent | 0b58219fe112c01ff335edf699c4fc69e718c75b (diff) | |
download | gcc-0d1e62b83561baa185bf080515750a89dd3ac410.zip gcc-0d1e62b83561baa185bf080515750a89dd3ac410.tar.gz gcc-0d1e62b83561baa185bf080515750a89dd3ac410.tar.bz2 |
Fortran: do not copy back for parameter actual arguments [PR81978]
When an array is packed for passing as an actual argument, and the array
has the PARAMETER attribute (i.e., it is a named constant that can reside
in read-only memory), do not copy back (unpack) from the temporary.
PR fortran/81978
gcc/fortran/ChangeLog:
* trans-array.cc (gfc_conv_array_parameter): Do not copy back data
if actual array parameter has the PARAMETER attribute.
* trans-expr.cc (gfc_conv_subref_array_arg): Likewise.
gcc/testsuite/ChangeLog:
* gfortran.dg/pr81978.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-array.cc')
-rw-r--r-- | gcc/fortran/trans-array.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 44b091a..ec627dd 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -8925,6 +8925,7 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, bool g77, bool good_allocatable; bool ultimate_ptr_comp; bool ultimate_alloc_comp; + bool readonly; gfc_symbol *sym; stmtblock_t block; gfc_ref *ref; @@ -9381,8 +9382,13 @@ gfc_conv_array_parameter (gfc_se *se, gfc_expr *expr, bool g77, gfc_start_block (&block); - /* Copy the data back. */ - if (fsym == NULL || fsym->attr.intent != INTENT_IN) + /* Copy the data back. If input expr is read-only, e.g. a PARAMETER + array, copying back modified values is undefined behavior. */ + readonly = (expr->expr_type == EXPR_VARIABLE + && expr->symtree + && expr->symtree->n.sym->attr.flavor == FL_PARAMETER); + + if ((fsym == NULL || fsym->attr.intent != INTENT_IN) && !readonly) { if (ctree) { |