This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, Fortran] Honour parentheses expressions for characters
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 18 Jul 2008 17:36:26 +0200
- Subject: [Patch, Fortran] Honour parentheses expressions for characters
Hello all,
the following patch is simple: It just removes a work around and fixes
thus a real-world problem. However, I would not be surprised if some
hidden character-related problems will show up due to this change.
Build on x86-64-linux and checked (-m64) with check-gfortran and with
libgomp "check".
OK for the trunk?
Tobias
2008-07-18 Tobias Burnus <burnus@net-b.de>
PR fortran/36795
* matchexp.c (gfc_get_parentheses): Remove obsolete workaround,
which caused the generation of wrong code.
2008-07-18 Tobias Burnus <burnus@net-b.de>
PR fortran/36795
* char_expr_1.f90: New.
* char_expr_2.f90: New.
Index: gcc/fortran/matchexp.c
===================================================================
--- gcc/fortran/matchexp.c (Revision 137952)
+++ gcc/fortran/matchexp.c (Arbeitskopie)
@@ -130,13 +130,6 @@ gfc_get_parentheses (gfc_expr *e)
{
gfc_expr *e2;
- /* This is a temporary fix, awaiting the patch for various
- other character problems. The resolution and translation
- of substrings and concatenations are so kludged up that
- putting parentheses around them breaks everything. */
- if (e->ts.type == BT_CHARACTER && e->ref)
- return e;
-
e2 = gfc_get_expr();
e2->expr_type = EXPR_OP;
e2->ts = e->ts;
Index: gcc/testsuite/gfortran.dg/char_expr_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_expr_1.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/char_expr_1.f90 (Revision 0)
@@ -0,0 +1,20 @@
+! { dg-do "run" }
+! PR fortran/36795
+! "(str)" (= an expression) was regarded as "str" (= a variable)
+! and thus when yy was deallocated so was xx. Result: An invalid
+! memory access.
+!
+program main
+ implicit none
+ character (len=10), allocatable :: str(:)
+ allocate (str(1))
+ str(1) = "dog"
+ if (size(str) /= 1 .or. str(1) /= "dog") call abort()
+contains
+ subroutine foo(xx,yy)
+ character (len=*), intent(in) :: xx(:)
+ character (len=*), intent(out), allocatable :: yy(:)
+ allocate (yy(size(xx)))
+ yy = xx
+ end subroutine foo
+end program main
Index: gcc/testsuite/gfortran.dg/char_expr_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_expr_2.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/char_expr_2.f90 (Revision 0)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! PR fortran/36803
+! PR fortran/36795
+!
+! "(n)" was simplified to the EXPR_VARIABLE "n"
+! and thus "(n)" was judged as definable.
+!
+interface
+ subroutine foo(x)
+ character, intent(out) :: x(:) ! or INTENT(INOUT)
+ end subroutine foo
+end interface
+character :: n(5)
+call foo( (n) ) ! { dg-error "must be definable" }
+end