[Fortran] PR92898 - [9/10 Regression] ICE in gfc_check_is_contiguous, at fortran/check.c:7157

Message ID 5DF0169F.8060308@gmx.de
State New
Headers show
Series
  • [Fortran] PR92898 - [9/10 Regression] ICE in gfc_check_is_contiguous, at fortran/check.c:7157
Related show

Commit Message

Harald Anlauf Dec. 10, 2019, 10:05 p.m.
The testcase in the PR exhibits a corner case in a check on invalid
code that was not handled appropriately and in turn ICEs.  The patch
below enhances that check.  Instead of adding a new testcase, I modified
the related one that came with the 'introduction' of the regression when
fixing PR91641.

Regtested on x86_64-pc-linux-gnu.

OK for trunk and 9 ?

Thanks,
Harald

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

	PR fortran/92898
	* check.c (gfc_check_is_contiguous): Adjust check to handle NULL()
	argument without an actual argument.

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

	PR fortran/92898
	* gfortran.dg/pr91641.f90: Extend to check fix for PR92898.

Index: gcc/testsuite/gfortran.dg/pr91641.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91641.f90	(Revision 279183)
+++ gcc/testsuite/gfortran.dg/pr91641.f90	(Arbeitskopie)
@@ -1,7 +1,9 @@
 ! { dg-do compile }
 ! PR fortran/91641
-! Code conyributed by Gerhard Steinmetz
+! PR fortran/92898
+! Code contributed by Gerhard Steinmetz
 program p
    real, pointer :: z(:)
    print *, is_contiguous (null(z))    ! { dg-error "shall be an associated" }
+   print *, is_contiguous (null())     ! { dg-error "shall be an associated" }
 end

Comments

Thomas Koenig Dec. 10, 2019, 10:34 p.m. | #1
Hello Harald,

> Index: gcc/fortran/check.c

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

> --- gcc/fortran/check.c	(Revision 279183)

> +++ gcc/fortran/check.c	(Arbeitskopie)

> @@ -7154,7 +7154,9 @@ bool

>   gfc_check_is_contiguous (gfc_expr *array)

>   {

>     if (array->expr_type == EXPR_NULL

> -      && array->symtree->n.sym->attr.pointer == 1)

> +      && (!array->symtree ||

> +	  (array->symtree->n.sym &&

> +	   array->symtree->n.sym->attr.pointer == 1)))


I have to admit I do not understand the original code here, nor
do I quite understand your fix.

Is there any circumstance where array->expr_type == EXPR_NULL, but
is_contiguous is valid?  What would go wrong if the other tests
were removed?


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

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

> --- gcc/testsuite/gfortran.dg/pr91641.f90	(Revision 279183)

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

> @@ -1,7 +1,9 @@

>   ! { dg-do compile }

>   ! PR fortran/91641

> -! Code conyributed by Gerhard Steinmetz

> +! PR fortran/92898

> +! Code contributed by Gerhard Steinmetz

>   program p

>      real, pointer :: z(:)

>      print *, is_contiguous (null(z))    ! { dg-error "shall be an associated" }

> +   print *, is_contiguous (null())     ! { dg-error "shall be an associated" }

>   end


Sometimes, it is necessary to change test cases, when error messages
change.  If this is not the case, it is better to add new tests to
new test cases - this makes regression hunting much easier.

Regards

	Thomas

Patch

Index: gcc/fortran/check.c
===================================================================
--- gcc/fortran/check.c	(Revision 279183)
+++ gcc/fortran/check.c	(Arbeitskopie)
@@ -7154,7 +7154,9 @@  bool
 gfc_check_is_contiguous (gfc_expr *array)
 {
   if (array->expr_type == EXPR_NULL
-      && array->symtree->n.sym->attr.pointer == 1)
+      && (!array->symtree ||
+	  (array->symtree->n.sym &&
+	   array->symtree->n.sym->attr.pointer == 1)))
     {
       gfc_error ("Actual argument at %L of %qs intrinsic shall be an "
 		 "associated pointer", &array->where, gfc_current_intrinsic);