re PR fortran/57553 ([F08] Valid use of STORAGE_SIZE rejected, bad error message...
authorTobias Burnus <burnus@net-b.de>
Sat, 8 Jun 2013 12:21:58 +0000 (14:21 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Sat, 8 Jun 2013 12:21:58 +0000 (14:21 +0200)
2013-06-08  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57553
        * simplify.c (gfc_simplify_storage_size): Handle literal
        strings.
        * trans-intrinsic.c (gfc_conv_intrinsic_storage_size):
        Add missing fold_convert.

2013-06-08  Tobias Burnus  <burnus@net-b.de>

        PR fortran/57553
        * gfortran.dg/storage_size_4.f90: New.

From-SVN: r199850

gcc/fortran/ChangeLog
gcc/fortran/simplify.c
gcc/fortran/trans-intrinsic.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/storage_size_4.f90 [new file with mode: 0644]

index 9e577d8..1009c95 100644 (file)
@@ -1,3 +1,11 @@
+2013-06-08  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/57553
+       * simplify.c (gfc_simplify_storage_size): Handle literal
+       strings.
+       * trans-intrinsic.c (gfc_conv_intrinsic_storage_size):
+       Add missing fold_convert.
+
 2013-06-07  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/57549
index 815043b..683d58b 100644 (file)
@@ -5717,7 +5717,7 @@ gfc_simplify_storage_size (gfc_expr *x,
   if (x->ts.type == BT_CLASS || x->ts.deferred)
     return NULL;
 
-  if (x->ts.type == BT_CHARACTER
+  if (x->ts.type == BT_CHARACTER && x->expr_type != EXPR_CONSTANT
       && (!x->ts.u.cl || !x->ts.u.cl->length
          || x->ts.u.cl->length->expr_type != EXPR_CONSTANT))
     return NULL;
index eca907e..3fbf193 100644 (file)
@@ -5249,12 +5249,10 @@ static void
 gfc_conv_intrinsic_storage_size (gfc_se *se, gfc_expr *expr)
 {
   gfc_expr *arg;
-  gfc_se argse,eight;
+  gfc_se argse;
   tree type, result_type, tmp;
 
   arg = expr->value.function.actual->expr;
-  gfc_init_se (&eight, NULL);
-  gfc_conv_expr (&eight, gfc_get_int_expr (expr->ts.kind, NULL, 8));
   
   gfc_init_se (&argse, NULL);
   result_type = gfc_get_int_type (expr->ts.kind);
@@ -5285,11 +5283,12 @@ gfc_conv_intrinsic_storage_size (gfc_se *se, gfc_expr *expr)
   if (arg->ts.type == BT_CHARACTER)
     tmp = size_of_string_in_bytes (arg->ts.kind, argse.string_length);
   else
-    tmp = fold_convert (result_type, size_in_bytes (type)); 
+    tmp = size_in_bytes (type); 
+  tmp = fold_convert (result_type, tmp);
 
 done:
   se->expr = fold_build2_loc (input_location, MULT_EXPR, result_type, tmp,
-                             eight.expr);
+                             build_int_cst (result_type, BITS_PER_UNIT));
   gfc_add_block_to_block (&se->pre, &argse.pre);
 }
 
index 65c0770..f42861b 100644 (file)
@@ -1,3 +1,8 @@
+2013-06-08  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/57553
+       * gfortran.dg/storage_size_4.f90: New.
+
 2013-06-07  Sriraman Tallam  <tmsriram@google.com>
 
        PR c++/57548
diff --git a/gcc/testsuite/gfortran.dg/storage_size_4.f90 b/gcc/testsuite/gfortran.dg/storage_size_4.f90
new file mode 100644 (file)
index 0000000..bcfd5c3
--- /dev/null
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+!
+! PR fortran/57553
+!
+! Ensure that there is no ICE and that compile-time simplication works.
+!
+  use iso_fortran_env
+  implicit none
+  integer, parameter :: ESize = storage_size('a')
+  integer, parameter :: ESize2 = storage_size('aa')
+  if ( ESize/CHARACTER_STORAGE_SIZE /= 1) call abort()
+  if ( ESize2/CHARACTER_STORAGE_SIZE /= 2) call abort()
+end
+
+subroutine S ( A )
+  character(len=*), intent(in) :: A
+  integer :: ESize = 4
+  esize = ( storage_size(a) + 7 ) / 8
+end
+
+! { dg-final { scan-tree-dump-not "abort" "original" } }
+! { dg-final { cleanup-tree-dump "original" } }