This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Attached patch is a very simple fix for PR 25681 "ICE with len of array of derived type". gfc_simplify_len was able to simplify LEN(s) where s is a constant, but not LEN(s) where s is a variable with constant length.
I'm not sure this is a complete fix of PR 25681: I tried to think of examples where the length of the character variable inside the derived type was not a constant, but couldn't devise one. If someone can propose such an example, I will then leave PR 25681 open, waiting for a complete fix.
Patch is regtested on i686-linux as well as all the PR testcases. It also enables gfortran to compile CP2K, a very large chemistry simulation code (it was the last bug preventing compilation).
OK for mainline and 4.1?
Attachment:
char_type_len.ChangeLog
Description: Binary data
Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c (revision 113296)
+++ gcc/fortran/simplify.c (working copy)
@@ -1930,14 +1930,24 @@
{
gfc_expr *result;
- if (e->expr_type != EXPR_CONSTANT)
- return NULL;
+ if (e->expr_type == EXPR_CONSTANT)
+ {
+ result = gfc_constant_result (BT_INTEGER, gfc_default_integer_kind,
+ &e->where);
+ mpz_set_si (result->value.integer, e->value.character.length);
+ return range_check (result, "LEN");
+ }
- result = gfc_constant_result (BT_INTEGER, gfc_default_integer_kind,
- &e->where);
-
- mpz_set_si (result->value.integer, e->value.character.length);
- return range_check (result, "LEN");
+ if (e->ts.cl != NULL && e->ts.cl->length != NULL
+ && e->ts.cl->length->expr_type == EXPR_CONSTANT)
+ {
+ result = gfc_constant_result (BT_INTEGER, gfc_default_integer_kind,
+ &e->where);
+ mpz_set (result->value.integer, e->ts.cl->length->value.integer);
+ return range_check (result, "LEN");
+ }
+
+ return NULL;
}
Index: gcc/testsuite/gfortran.dg/char_type_len.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_type_len.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/char_type_len.f90 (revision 0)
@@ -0,0 +1,12 @@
+! { dg-do run }
+! Testcase for PR fortran/25681
+program char_type_len
+ integer,parameter :: n = 9
+ type foo_t
+ character (len = 80) :: bar (1)
+ character (len = 75) :: gee (n)
+ end type foo_t
+ type(foo_t) :: foo
+
+ if (len(foo%bar) /= 80 .or. len(foo%gee) /= 75) call abort
+end program char_type_len
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |