Re: [Patch, fortran] PR fortran/96727 - ICE with character length specified using specification function on assumed-rank array

2020-08-22 Thread Thomas Koenig via Gcc-patches

Hi Jose,

Proposed patch to PR96727 - ICE with character length specified using 
specification function on assumed-rank array.


Patch tested only on x86_64-pc-linux-gnu.

Add missing default error message for the assumed-rank array case.


Looks good with an adjusted ChangeLog/git commit message.
(If you have trouble with that, you can also send me
an e-mail).

Best regards

Thomas




[Patch, fortran] PR fortran/96727 - ICE with character length specified using specification function on assumed-rank array

2020-08-20 Thread José Rui Faustino de Sousa via Gcc-patches

Hi all!

Proposed patch to PR96727 - ICE with character length specified using 
specification function on assumed-rank array.


Patch tested only on x86_64-pc-linux-gnu.

Add missing default error message for the assumed-rank array case.

Thank you very much.

Best regards,
José Rui


2020-8-20  José Rui Faustino de Sousa  

 PR fortran/96727
 * expr.c (gfc_check_init_expr): Add default error message for the
 AS_ASSUMED_RANK case.

2020-8-20  José Rui Faustino de Sousa  

 PR fortran/96727
 * PR96727.f90: New test.
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 6707ca5..aecbe46 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -3007,6 +3007,12 @@ gfc_check_init_expr (gfc_expr *e)
 			   e->symtree->n.sym->name, >where);
 		break;
 
+	  case AS_ASSUMED_RANK:
+		gfc_error ("Assumed-rank array %qs at %L is not permitted "
+			   "in an initialization expression",
+			   e->symtree->n.sym->name, >where);
+		break;
+
 	  default:
 		gcc_unreachable();
 	  }
diff --git a/gcc/testsuite/gfortran.dg/PR96727.f90 b/gcc/testsuite/gfortran.dg/PR96727.f90
new file mode 100644
index 000..d45dbb7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR96727.f90
@@ -0,0 +1,34 @@
+! { dg-do run }
+!
+! Test the fix for PR96727
+!
+
+program cref_p
+
+  implicit none
+  
+  integer :: i
+
+  integer,  parameter :: n = 3
+  integer,  parameter :: p(*) = [(i, i=1,n*n)]
+  character(len=*), parameter :: q = repeat('a', n*n)
+  
+  integer:: a(n,n)
+  character(len=n*n) :: c
+
+  a = reshape(p, shape=[n,n])
+  call csub(a, c)
+  if (c/=q) stop 1
+  stop
+
+contains
+
+  subroutine csub(a, b)
+integer,intent(in)  :: a(..)
+character(len=size(a)), intent(out) :: b
+
+b = repeat('a', len(b))
+return
+  end subroutine csub
+  
+end program cref_p