diff mbox

[Fortran] PRs - fix TRANSFER checks

Message ID 4FDC6EE9.5060800@net-b.de
State New
Headers show

Commit Message

Tobias Burnus June 16, 2012, 11:32 a.m. UTC
Two rather simple patches.

Build and regtested on x86-64-linux.
As one of the issues is a 4.7/4.8 regression:
OK for the trunk and 4.7?

Tobias

Comments

Janus Weil June 17, 2012, 4:58 p.m. UTC | #1
Hi Tobias,

> Two rather simple patches.
>
> Build and regtested on x86-64-linux.
> As one of the issues is a 4.7/4.8 regression:
> OK for the trunk and 4.7?

l'd say ok for both trunk and 4.7.

Thanks for the patches,
Janus
diff mbox

Patch

2012-06-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/53691
	PR fortran/53685
	* check.c (gfc_calculate_transfer_sizes): Return if
	SIZE= is not constant or source-size cannot be determined.

2012-06-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/53691
	PR fortran/53685
	* gfortran.dg/transfer_check_3.f90: New.

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 9926f05..9be8f66 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -3986,7 +3986,6 @@  gfc_try
 gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
 			      size_t *source_size, size_t *result_size,
 			      size_t *result_length_p)
-
 {
   size_t result_elt_size;
   mpz_t tmp;
@@ -3995,12 +3994,17 @@  gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size,
   if (source->expr_type == EXPR_FUNCTION)
     return FAILURE;
 
-    /* Calculate the size of the source.  */
+  if (size && size->expr_type != EXPR_CONSTANT)
+    return FAILURE;
+
+  /* Calculate the size of the source.  */
   if (source->expr_type == EXPR_ARRAY
       && gfc_array_size (source, &tmp) == FAILURE)
     return FAILURE;
 
   *source_size = gfc_target_expr_size (source);
+  if (*source_size == 0)
+    return FAILURE;
 
   mold_element = mold->expr_type == EXPR_ARRAY
 		 ? gfc_constructor_first (mold->value.constructor)->expr
--- /dev/null	2012-06-16 07:44:03.623809858 +0200
+++ gcc/gcc/testsuite/gfortran.dg/transfer_check_3.f90	2012-06-16 13:28:12.000000000 +0200
@@ -0,0 +1,33 @@ 
+! { dg-do compile }
+! { dg-options "-Wsurprising" }
+!
+! PR fortran/53691
+! PR fortran/53685
+!
+! TRANSFER checks
+
+
+! (a) PR 53691
+! Failed for -Wsurprising with an ICE as SIZE was assumed to be constant
+
+       SUBROUTINE CGBRFSX(N, RWORK)
+         INTEGER N
+         REAL RWORK(*)
+         REAL ZERO
+         PARAMETER (ZERO = 0.0E+0)
+         call foo(TRANSFER (RWORK(1:2*N), (/ (ZERO, ZERO) /), N))
+       end
+
+! (b) PR 53685
+! Failed with a bogus size warning if the source's size is not known at compile
+! time (for substrings, the length wasn't set)
+
+      subroutine test(j)
+        implicit none
+        character(len=4) :: record_type
+        integer          :: i, j
+
+        i = transfer (record_type, i)      ! no warning
+        i = transfer (record_type(1:4), i) ! gave a warning
+        i = transfer (record_type(1:j), i) ! gave a warning
+      end