OSDN Git Service

PR fortran/25681
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 29 Apr 2006 16:31:26 +0000 (16:31 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 29 Apr 2006 16:31:26 +0000 (16:31 +0000)
* simplify.c (simplify_len): Character variables with constant
length can be simplified.

* gfortran.df/char_type_len.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113376 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/char_type_len.f90 [new file with mode: 0644]

index dcb7393..f275c5f 100644 (file)
@@ -1,3 +1,9 @@
+2006-04-29  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR fortran/25681
+       * simplify.c (simplify_len): Character variables with constant
+       length can be simplified.
+
 2006-04-29  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR fortran/27351
index d5dfb34..403f9c7 100644 (file)
@@ -1930,14 +1930,24 @@ gfc_simplify_len (gfc_expr * e)
 {
   gfc_expr *result;
 
-  if (e->expr_type != EXPR_CONSTANT)
-    return NULL;
-
-  result = gfc_constant_result (BT_INTEGER, gfc_default_integer_kind,
-                               &e->where);
+  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");
+    }
 
-  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 9907037..7bd203e 100644 (file)
@@ -1,3 +1,8 @@
+2006-04-29  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
+
+       PR fortran/25681
+       * gfortran.df/char_type_len.f90: New test.
+
 2006-04-28  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/27304
diff --git a/gcc/testsuite/gfortran.dg/char_type_len.f90 b/gcc/testsuite/gfortran.dg/char_type_len.f90
new file mode 100644 (file)
index 0000000..706f934
--- /dev/null
@@ -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