diff mbox

[fortran] PR61138 Wrong code with pointer-bounds remapping

Message ID 54D8ADD5.8020408@sfr.fr
State New
Headers show

Commit Message

Mikael Morin Feb. 9, 2015, 12:53 p.m. UTC
Hello,

this is about a pointer bounds remapping regression introduced at
http://gcc.gnu.org/r190641
That revision introduced support for se.descriptor_only in
gfc_conv_expr_descriptor with this hunk:

> Index: trans-array.c
> ===================================================================
> --- trans-array.c	(révision 220514)
> +++ trans-array.c	(copie de travail)
> @@ -6574,7 +6574,7 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *ex
>  	  /* Create a new descriptor if the array doesn't have one.  */
>  	  full = 0;
>  	}
> -      else if (info->ref->u.ar.type == AR_FULL)
> +      else if (info->ref->u.ar.type == AR_FULL || se->descriptor_only)
>  	full = 1;
>        else if (se->direct_byref)
>  	full = 0;

The problem comes from gfc_trans_pointer_assign, which uses several
times the same gfc_se struct, the first time with descriptor_only set,
the other times without clearing it.
This was not a problem before the above change, because the flag wasn't
looked at.
After the change however, one should make sure that descriptor_only is
not inherited from a previous use.

The fix proposed clears the flag upon reuse, which should match exactly
the original behaviour, making it rather safe, and suitable also for the
branches.
I have to admit that I'm not completely satisfied with it however.
I would prefer no GFC_SE reuse at all, namely collect every piece of
code in a separate struct, and merge them later explicitly into a block.
 Alas, the code is not exactly straightforward to my eyes, and my
attempt in that direction to sneak some orthogonality in that madness
failed.

Anyway, regression tested on x86_64-linux, OK for trunk/4.9/4.8 ?

Mikael
2015-02-09  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/61138
	* trans-expr.c (gfc_trans_pointer_assignment): Clear DESCRIPTOR_ONLY
	field before reusing LSE.

2015-02-09  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/61138
	gfortran.dg/pointer_remapping_9.f90: New.

Comments

Mikael Morin March 12, 2015, 6:02 p.m. UTC | #1
Ping:
https://gcc.gnu.org/ml/fortran/2015-02/msg00045.html
Tobias Burnus March 13, 2015, 7:02 a.m. UTC | #2
Mikael Morin wrote:
> this is about a pointer bounds remapping regression introduced at
> http://gcc.gnu.org/r190641
> [...]
> The fix proposed clears the flag upon reuse, which should match exactly
> the original behaviour, making it rather safe, and suitable also for the
> branches.
> I have to admit that I'm not completely satisfied with it however.
> I would prefer no GFC_SE reuse at all, namely collect every piece of
> code in a separate struct, and merge them later explicitly into a block.
>   Alas, the code is not exactly straightforward to my eyes, and my
> attempt in that direction to sneak some orthogonality in that madness
> failed.
>
> Anyway, regression tested on x86_64-linux, OK for trunk/4.9/4.8 ?
>

OK. Thanks for the patch - and sorry for the belate review.

Tobias
diff mbox

Patch

Index: trans-expr.c
===================================================================
--- trans-expr.c	(révision 220514)
+++ trans-expr.c	(copie de travail)
@@ -7339,6 +7339,7 @@  gfc_trans_pointer_assignment (gfc_expr * expr1, gf
 					       bound, bound, 0,
 					       GFC_ARRAY_POINTER_CONT, false);
 	      tmp = gfc_create_var (tmp, "ptrtemp");
+	      lse.descriptor_only = 0;
 	      lse.expr = tmp;
 	      lse.direct_byref = 1;
 	      gfc_conv_expr_descriptor (&lse, expr2);
@@ -7354,6 +7355,7 @@  gfc_trans_pointer_assignment (gfc_expr * expr1, gf
       else if (expr2->expr_type == EXPR_VARIABLE)
 	{
 	  /* Assign directly to the LHS's descriptor.  */
+	  lse.descriptor_only = 0;
 	  lse.direct_byref = 1;
 	  gfc_conv_expr_descriptor (&lse, expr2);
 	  strlen_rhs = lse.string_length;
@@ -7405,6 +7407,7 @@  gfc_trans_pointer_assignment (gfc_expr * expr1, gf
 	  /* Assign to a temporary descriptor and then copy that
 	     temporary to the pointer.  */
 	  tmp = gfc_create_var (TREE_TYPE (desc), "ptrtemp");
+	  lse.descriptor_only = 0;
 	  lse.expr = tmp;
 	  lse.direct_byref = 1;
 	  gfc_conv_expr_descriptor (&lse, expr2);