[fortran] PR70853 - ICE on pointing to null, in gfc_add_block_to_block, at fortran/trans.c:1599

Message ID 5DFA4EB4.4040805@gmx.de
State New
Headers show
Series
  • [fortran] PR70853 - ICE on pointing to null, in gfc_add_block_to_block, at fortran/trans.c:1599
Related show

Commit Message

Harald Anlauf Dec. 18, 2019, 4:07 p.m.
The patch is self-explaining and practically obvious: pointer bounds
remapping to NULL is not allowed, thus we shall reject it.  I hope the
error message is fine.  If somebody prefers a formulation as in the
standard ("data target", also used by the Intel compiler), please
speak now.

Regtested on x86_64-pc-linux-gnu.

OK for trunk?

Thanks,
Harald



2019-12-18  Harald Anlauf  <anlauf@gmx.de>

        PR fortran/92898
        * trans-expr.c (gfc_trans_pointer_assignment): Reject bounds
        remapping if pointer target is NULL().


2019-12-18  Harald Anlauf  <anlauf@gmx.de>

        PR fortran/70853
        * gfortran.dg/pr70853.f90: New test.

Comments

Tobias Burnus Dec. 18, 2019, 4:17 p.m. | #1
LGTM. Thanks for the patch!

Tobias

PS: I assume, your patch also fixes the following test case, which also 
ICEs in gfc_trans_pointer_assignment:
integer, pointer, contiguous :: x(:)
nullify(x(1:1))
end

On 12/18/19 5:07 PM, Harald Anlauf wrote:
> The patch is self-explaining and practically obvious: pointer bounds

> remapping to NULL is not allowed, thus we shall reject it.  I hope the

> error message is fine.  If somebody prefers a formulation as in the

> standard ("data target", also used by the Intel compiler), please

> speak now.

>

> Regtested on x86_64-pc-linux-gnu.

>

> OK for trunk?

>

> Thanks,

> Harald

>

> Index: gcc/fortran/trans-expr.c

> ===================================================================

> --- gcc/fortran/trans-expr.c    (Revision 279405)

> +++ gcc/fortran/trans-expr.c    (Arbeitskopie)

> @@ -9218,6 +9218,13 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, gf

>            break;

>         rank_remap = (remap && remap->u.ar.end[0]);

>

> +      if (remap && expr2->expr_type == EXPR_NULL)

> +       {

> +         gfc_error ("If bounds remapping is specified at %L, "

> +                    "the pointer target shall not be NULL", &expr1->where);

> +         return NULL_TREE;

> +       }

> +

>         gfc_init_se (&lse, NULL);

>         if (remap)

>          lse.descriptor_only = 1;

>

>

> Index: gcc/testsuite/gfortran.dg/pr70853.f90

> ===================================================================

> --- gcc/testsuite/gfortran.dg/pr70853.f90       (nicht existent)

> +++ gcc/testsuite/gfortran.dg/pr70853.f90       (Arbeitskopie)

> @@ -0,0 +1,8 @@

> +! { dg-do compile }

> +! PR fortran/70853

> +! Contributed by Gerhard Steinmetz

> +program p

> +   real, pointer :: z(:)

> +   z(1:2) => null() ! { dg-error "pointer target shall not be NULL" }

> +   z(2:1) => null() ! { dg-error "pointer target shall not be NULL" }

> +end

>

>

> 2019-12-18  Harald Anlauf  <anlauf@gmx.de>

>

>          PR fortran/92898

>          * trans-expr.c (gfc_trans_pointer_assignment): Reject bounds

>          remapping if pointer target is NULL().

>

>

> 2019-12-18  Harald Anlauf  <anlauf@gmx.de>

>

>          PR fortran/70853

>          * gfortran.dg/pr70853.f90: New test.
Harald Anlauf Dec. 18, 2019, 4:40 p.m. | #2
On 12/18/19 17:17, Tobias Burnus wrote:
> LGTM. Thanks for the patch!


Thanks, committed as r279527.

> Tobias

>

> PS: I assume, your patch also fixes the following test case, which also

> ICEs in gfc_trans_pointer_assignment:

> integer, pointer, contiguous :: x(:)

> nullify(x(1:1))

> end


Well, that depends on your interpretation of "fix".  The ICE is now
replaced by a somewhat incorrect error message:

xxxxx.f90:2:8:

    2 | nullify(x(1:1))
      |        1
Error: If bounds remapping is specified at (1), the pointer target shall
not be NULL

For a better error message, we'd need to know that we come here from
a NULLIFY statement.  Can you file a PR?

Thanks,
Harald

> On 12/18/19 5:07 PM, Harald Anlauf wrote:

>> The patch is self-explaining and practically obvious: pointer bounds

>> remapping to NULL is not allowed, thus we shall reject it.  I hope the

>> error message is fine.  If somebody prefers a formulation as in the

>> standard ("data target", also used by the Intel compiler), please

>> speak now.

>>

>> Regtested on x86_64-pc-linux-gnu.

>>

>> OK for trunk?

>>

>> Thanks,

>> Harald

>>

>> Index: gcc/fortran/trans-expr.c

>> ===================================================================

>> --- gcc/fortran/trans-expr.c    (Revision 279405)

>> +++ gcc/fortran/trans-expr.c    (Arbeitskopie)

>> @@ -9218,6 +9218,13 @@ gfc_trans_pointer_assignment (gfc_expr * expr1, gf

>>            break;

>>         rank_remap = (remap && remap->u.ar.end[0]);

>>

>> +      if (remap && expr2->expr_type == EXPR_NULL)

>> +       {

>> +         gfc_error ("If bounds remapping is specified at %L, "

>> +                    "the pointer target shall not be NULL",

>> &expr1->where);

>> +         return NULL_TREE;

>> +       }

>> +

>>         gfc_init_se (&lse, NULL);

>>         if (remap)

>>          lse.descriptor_only = 1;

>>

>>

>> Index: gcc/testsuite/gfortran.dg/pr70853.f90

>> ===================================================================

>> --- gcc/testsuite/gfortran.dg/pr70853.f90       (nicht existent)

>> +++ gcc/testsuite/gfortran.dg/pr70853.f90       (Arbeitskopie)

>> @@ -0,0 +1,8 @@

>> +! { dg-do compile }

>> +! PR fortran/70853

>> +! Contributed by Gerhard Steinmetz

>> +program p

>> +   real, pointer :: z(:)

>> +   z(1:2) => null() ! { dg-error "pointer target shall not be NULL" }

>> +   z(2:1) => null() ! { dg-error "pointer target shall not be NULL" }

>> +end

>>

>>

>> 2019-12-18  Harald Anlauf  <anlauf@gmx.de>

>>

>>          PR fortran/92898

>>          * trans-expr.c (gfc_trans_pointer_assignment): Reject bounds

>>          remapping if pointer target is NULL().

>>

>>

>> 2019-12-18  Harald Anlauf  <anlauf@gmx.de>

>>

>>          PR fortran/70853

>>          * gfortran.dg/pr70853.f90: New test.

>

Patch

Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c    (Revision 279405)
+++ gcc/fortran/trans-expr.c    (Arbeitskopie)
@@ -9218,6 +9218,13 @@  gfc_trans_pointer_assignment (gfc_expr * expr1, gf
          break;
       rank_remap = (remap && remap->u.ar.end[0]);

+      if (remap && expr2->expr_type == EXPR_NULL)
+       {
+         gfc_error ("If bounds remapping is specified at %L, "
+                    "the pointer target shall not be NULL", &expr1->where);
+         return NULL_TREE;
+       }
+
       gfc_init_se (&lse, NULL);
       if (remap)
        lse.descriptor_only = 1;


Index: gcc/testsuite/gfortran.dg/pr70853.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr70853.f90       (nicht existent)
+++ gcc/testsuite/gfortran.dg/pr70853.f90       (Arbeitskopie)
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+! PR fortran/70853
+! Contributed by Gerhard Steinmetz
+program p
+   real, pointer :: z(:)
+   z(1:2) => null() ! { dg-error "pointer target shall not be NULL" }
+   z(2:1) => null() ! { dg-error "pointer target shall not be NULL" }
+end