diff options
author | Mikael Morin <mikael@gcc.gnu.org> | 2012-01-04 14:04:24 +0000 |
---|---|---|
committer | Mikael Morin <mikael@gcc.gnu.org> | 2012-01-04 14:04:24 +0000 |
commit | 0192ef204cbc1b80a1da59dae7b275cb7de67c81 (patch) | |
tree | 35ecccc993dae3c75c7845b088145f81382da192 /gcc/fortran/trans-array.c | |
parent | 591823cc9aba6f6943f7204df365bf2f0ca593ca (diff) | |
download | gcc-0192ef204cbc1b80a1da59dae7b275cb7de67c81.zip gcc-0192ef204cbc1b80a1da59dae7b275cb7de67c81.tar.gz gcc-0192ef204cbc1b80a1da59dae7b275cb7de67c81.tar.bz2 |
re PR fortran/50981 ([OOP] Wrong-code for scalarizing ELEMENTAL call with absent OPTIONAL argument)
PR fortran/50981
* trans.h (struct gfc_ss_info): New field data::scalar::can_be_null_ref
* trans-array.c: If the reference can be NULL, save the reference
instead of the value.
* trans-expr.c (gfc_conv_expr): If we have saved a reference,
dereference it.
From-SVN: r182874
Diffstat (limited to 'gcc/fortran/trans-array.c')
-rw-r--r-- | gcc/fortran/trans-array.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 50e1ee4..a9a060d 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -2422,10 +2422,21 @@ gfc_add_loop_ss_code (gfc_loopinfo * loop, gfc_ss * ss, bool subscript, break; case GFC_SS_REFERENCE: - /* Scalar argument to elemental procedure. Evaluate this - now. */ + /* Scalar argument to elemental procedure. */ gfc_init_se (&se, NULL); - gfc_conv_expr (&se, expr); + if (ss_info->data.scalar.can_be_null_ref) + { + /* If the actual argument can be absent (in other words, it can + be a NULL reference), don't try to evaluate it; pass instead + the reference directly. */ + gfc_conv_expr_reference (&se, expr); + } + else + { + /* Otherwise, evaluate the argument outside the loop and pass + a reference to the value. */ + gfc_conv_expr (&se, expr); + } gfc_add_block_to_block (&outer_loop->pre, &se.pre); gfc_add_block_to_block (&outer_loop->post, &se.post); if (gfc_is_class_scalar_expr (expr)) |