diff options
author | Tobias Schlüter <tobias.schlueter@physik.uni-muenchen.de> | 2004-10-04 13:03:43 +0000 |
---|---|---|
committer | Paul Brook <pbrook@gcc.gnu.org> | 2004-10-04 13:03:43 +0000 |
commit | ca2940c3e0ca27dde0e04858d066f3eb852d8ac7 (patch) | |
tree | c2bb575fefe91c0ea361e22ef1df9305d35086c7 /gcc/fortran/trans-expr.c | |
parent | b805ea17e55a0da7424d97eb9fb252917e51445e (diff) | |
download | gcc-ca2940c3e0ca27dde0e04858d066f3eb852d8ac7.zip gcc-ca2940c3e0ca27dde0e04858d066f3eb852d8ac7.tar.gz gcc-ca2940c3e0ca27dde0e04858d066f3eb852d8ac7.tar.bz2 |
trans-array.c (gfc_conv_expr_descriptor): Check for substriungs.
2004-10-04 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
Paul Brook <paul@codesourcery.com>
* trans-array.c (gfc_conv_expr_descriptor): Check for substriungs.
Use gfc_get_expr_charlen.
* trans-expr.c (gfc_get_expr_charlen): New function.
* trans.h (gfc_get_expr_charlen): Add prototype.
testsuite/
* gfortran.dg/pr17612.f90: New test.
Co-Authored-By: Paul Brook <paul@codesourcery.com>
From-SVN: r88483
Diffstat (limited to 'gcc/fortran/trans-expr.c')
-rw-r--r-- | gcc/fortran/trans-expr.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index fc5b41b..45f3acf 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -140,6 +140,53 @@ gfc_conv_expr_present (gfc_symbol * sym) } +/* Get the character length of an expression, looking through gfc_refs + if necessary. */ + +tree +gfc_get_expr_charlen (gfc_expr *e) +{ + gfc_ref *r; + tree length; + + gcc_assert (e->expr_type == EXPR_VARIABLE + && e->ts.type == BT_CHARACTER); + + length = NULL; /* To silence compiler warning. */ + + /* First candidate: if the variable is of type CHARACTER, the + expression's length could be the length of the character + variable. */ + if (e->symtree->n.sym->ts.type == BT_CHARACTER) + length = e->symtree->n.sym->ts.cl->backend_decl; + + /* Look through the reference chain for component references. */ + for (r = e->ref; r; r = r->next) + { + switch (r->type) + { + case REF_COMPONENT: + if (r->u.c.component->ts.type == BT_CHARACTER) + length = r->u.c.component->ts.cl->backend_decl; + break; + + case REF_ARRAY: + /* Do nothing. */ + break; + + default: + /* We should never got substring references here. These will be + broken down by the scalarizer. */ + gcc_unreachable (); + } + } + + gcc_assert (length != NULL); + return length; +} + + + /* Generate code to initialize a string length variable. Returns the value. */ |