Patchwork [fortran] Fix PR 51338 - ICE with front-end optimization and assumed character lengths

login
register
mail settings
Submitter Thomas Koenig
Date Nov. 30, 2011, 7:56 p.m.
Message ID <4ED68A6F.101@netcologne.de>
Download mbox | patch
Permalink /patch/128562/
State New
Headers show

Comments

Thomas Koenig - Nov. 30, 2011, 7:56 p.m.
Hello world,

the attached patch fixes PR 51338.  I chose a different approach
from what Bud did in the PR, because I rather wanted to fix the
specific code path when two NULL expressions were handled to
gfc_dep_compare_expr where determining the right answer is
straightforward rather than possibly introducing a (future?) logic
error.

Regression-tested. OK for trunk?

	Thomas

2011-11-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/51338
         * dependency.c (are_identical_variables):  Handle case where
         end fields of substring references are NULL.

2011-11-29  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/51338
         * gfortran.dg/assumed_charlen_substring_1.f90:  New test.
! { dg-do compile }
! { dg-options "-O -fdump-tree-original" }
! PR 51338 - this used to ICE.
! Original test case by Bud Davis.
subroutine foo(a,b)
  character(len=*) :: a
  if (a(1:) /= a(1:)) call do_not_use
end subroutine foo
! { dg-final { scan-tree-dump-times "do_not_use" 0 "original" } }
! { dg-final { cleanup-tree-dump "original" } }
Tobias Burnus - Dec. 4, 2011, 3:18 p.m.
Thomas Koenig wrote:
> Regression-tested. OK for trunk?
>
> 2011-11-29  Thomas Koenig <tkoenig@gcc.gnu.org>
>
>         PR fortran/51338
>         * dependency.c (are_identical_variables):  Handle case where
>         end fields of substring references are NULL.
>
> 2011-11-29  Thomas Koenig <tkoenig@gcc.gnu.org>
>
>         PR fortran/51338
>         * gfortran.dg/assumed_charlen_substring_1.f90:  New test.
> +	  /* This can only happen for assumed-length character arguments.
> +	     If both are NULL, the end length compares equal, because we
> +	     are looking at the same variable.  */
> +	  if (r1->u.ss.end == NULL&&  r2->u.ss.end == NULL)
> +	    break;

Well, it can also happen for deferred-length arguments; how about:

+	  /* If both are NULL, the end length compares equal, because we
+	     are looking at the same variable. This can only happen for
+	     assumed- or deferred-length character arguments.  */


OK with that change.

Thanks for the patch and sorry for the slow review.

Tobias

PS: Patches which still need to be reviewed:
- http://gcc.gnu.org/ml/fortran/2011-11/msg00250.html - no 
-fcheck=bounds for character(LEN=:) to avoid ICE
- http://gcc.gnu.org/ml/fortran/2011-11/msg00253.html - (Re)enable 
warning if a function result variable is not set [4.4-4.7 diagnostics 
regression]
- http://gcc.gnu.org/ml/fortran/2011-12/msg00018.html - fix ASSOCIATE 
with extended types

Patch

Index: dependency.c
===================================================================
--- dependency.c	(Revision 181745)
+++ dependency.c	(Arbeitskopie)
@@ -173,9 +173,18 @@  are_identical_variables (gfc_expr *e1, gfc_expr *e
 	  break;
 
 	case REF_SUBSTRING:
-	  if (gfc_dep_compare_expr (r1->u.ss.start, r2->u.ss.start) != 0
-	      || gfc_dep_compare_expr (r1->u.ss.end, r2->u.ss.end) != 0)
+	  if (gfc_dep_compare_expr (r1->u.ss.start, r2->u.ss.start) != 0)
 	    return false;
+
+	  /* This can only happen for assumed-length character arguments.
+	     If both are NULL, the end length compares equal, because we
+	     are looking at the same variable.  */
+	  if (r1->u.ss.end == NULL && r2->u.ss.end == NULL)
+	    break;
+
+	  if (gfc_dep_compare_expr (r1->u.ss.end, r2->u.ss.end) != 0)
+	    return false;
+	  
 	  break;
 
 	default: