diff mbox series

Fortran: reject module variable as character length in PARAMETER [PR104349]

Message ID trinity-ae251df8-8c79-4a58-bf78-ffb1daa7cdfe-1680551148829@3c-app-gmx-bs28
State New
Headers show
Series Fortran: reject module variable as character length in PARAMETER [PR104349] | expand

Commit Message

Harald Anlauf April 3, 2023, 7:45 p.m. UTC
Dear all,

the attached patch fixes an ICE-on-invalid for a PARAMETER expression
where the character length was a MODULE variable.  The ICE seemed
strange, as we were catching related erroneous code for declarations in
programs or subroutines.  Removing a seemingly bogus check of restricted
expressions is the simplest way to fix this.  (We could also catch this
differently in decl.cc).

Besides, this also fixes an accepts-invalid, see testcase. :-)

Regtested on x86_64-pc-linux-gnu.  OK for mainline (13) or rather wait?

Thanks,
Harald

Comments

Paul Richard Thomas April 4, 2023, 5:33 a.m. UTC | #1
Hi Harald,

OK for mainline. It is sufficiently small that, if there is any fallout in
the next weeks, it can easily be reverted without great impact.

Thanks for the patch.

Paul


On Mon, 3 Apr 2023 at 20:46, Harald Anlauf via Fortran <fortran@gcc.gnu.org>
wrote:

> Dear all,
>
> the attached patch fixes an ICE-on-invalid for a PARAMETER expression
> where the character length was a MODULE variable.  The ICE seemed
> strange, as we were catching related erroneous code for declarations in
> programs or subroutines.  Removing a seemingly bogus check of restricted
> expressions is the simplest way to fix this.  (We could also catch this
> differently in decl.cc).
>
> Besides, this also fixes an accepts-invalid, see testcase. :-)
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline (13) or rather wait?
>
> Thanks,
> Harald
>
>
diff mbox series

Patch

From 37136ce94b44149dd013b3d7fed7adba769241e6 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 3 Apr 2023 21:34:01 +0200
Subject: [PATCH] Fortran: reject module variable as character length in
 PARAMETER [PR104349]

gcc/fortran/ChangeLog:

	PR fortran/104349
	* expr.cc (check_restricted): Adjust check for valid variables in
	restricted expressions: make no exception for module variables.

gcc/testsuite/ChangeLog:

	PR fortran/104349
	* gfortran.dg/der_charlen_1.f90: Adjust dg-patterns.
	* gfortran.dg/pr104349.f90: New test.
---
 gcc/fortran/expr.cc                         | 2 --
 gcc/testsuite/gfortran.dg/der_charlen_1.f90 | 2 ++
 gcc/testsuite/gfortran.dg/pr104349.f90      | 8 ++++++++
 3 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr104349.f90

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 7fb33f81788..02028f993fd 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -3504,8 +3504,6 @@  check_restricted (gfc_expr *e)
 	    || sym->attr.implied_index
 	    || sym->attr.flavor == FL_PARAMETER
 	    || is_parent_of_current_ns (sym->ns)
-	    || (sym->ns->proc_name != NULL
-		  && sym->ns->proc_name->attr.flavor == FL_MODULE)
 	    || (gfc_is_formal_arg () && (sym->ns == gfc_current_ns)))
 	{
 	  t = true;
diff --git a/gcc/testsuite/gfortran.dg/der_charlen_1.f90 b/gcc/testsuite/gfortran.dg/der_charlen_1.f90
index 9f394c73f25..1246522d516 100644
--- a/gcc/testsuite/gfortran.dg/der_charlen_1.f90
+++ b/gcc/testsuite/gfortran.dg/der_charlen_1.f90
@@ -22,3 +22,5 @@  CONTAINS
     type(T), intent(in)          :: X
   end subroutine
 end module another_core
+
+! { dg-prune-output "cannot appear in the expression" }
diff --git a/gcc/testsuite/gfortran.dg/pr104349.f90 b/gcc/testsuite/gfortran.dg/pr104349.f90
new file mode 100644
index 00000000000..2bea4a37214
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104349.f90
@@ -0,0 +1,8 @@ 
+! { dg-do compile }
+! PR fortran/104349 - reject module variable as character length in PARAMETER
+! Contributed by G.Steinmetz
+
+module m
+  character(n), parameter :: a(1) = 'b' ! { dg-error "cannot appear" }
+  character(n), parameter :: c    = 'b' ! { dg-error "cannot appear" }
+end
--
2.35.3