This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[gfortran,patch] Don't let character strings have negative length
- From: FX Coudert <fxcoudert at gmail dot com>
- To: "fortran at gcc dot gnu dot org List" <fortran at gcc dot gnu dot org>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 17 Mar 2007 22:55:19 +0100
- Subject: [gfortran,patch] Don't let character strings have negative length
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:mime-version:content-type:message-id:cc:content-transfer-encoding:from:subject:date:to:x-mailer; b=e17bC6L0OJLRl4rtioavzGHe13yYncNTitDGlXP5X6YaB5o3GyfgpMEmQ+kmDqvOKbwzoQVkt60K0qUf7PRvQSu96OIT2BKN80tnRNFLyuaADPgM8n75sTBHW9jdiHnyZbFaDxWuCF/HPLgOGxx8eQWLrwAM6HxGPCF2BRCrO9g=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:mime-version:content-type:message-id:cc:content-transfer-encoding:from:subject:date:to:x-mailer; b=OrRQPHe/gs27mtkt3PqY2HBDWC+u82gn4p/wVdxWEaZyfP2Zva8IaIic8433mzMU141WLMGoi2i/IB+vlH+RKPVNqMgnLo4ko04hh/5jANUCwkSi9RnwvnT3jEike9KV30bOPdtcpd0yPOQwofGbNm6A+v4Wc72aqxzfBkDUfF8=
Hi all,
Among the new PRs opened by Joost, most are related to a few areas:
TRANSFER, allocatable & pointers, implicit typing and symbol
resolution, and CHARACTER lengths.
PR31203 is one of the CHARACTER bugs, where we can initialize a
character length variable to be negative in code such as the following:
subroutine foo(i)
character(len=i) :: s
end subroutine foo
call foo(-2)
In fact, I think there's a single spot where this should be changed;
this leads to the 2-lines patch below. It was bootstrapped and
regtested on i686-linux. It will be commited along with the necessary
ChangeLog entry and a few testcases, both from the PR and my own
creations :)
OK for mainline and 4.2 when it unfreezes?
Thanks,
FX
PS: I intend to work (as time permit) on the other CHARACTER-length
related issues, from Joost's bug reports, another one from Thomas K.
and a few others by me. The code handling them seems to need some
serious dusting, especially the end of the match_char_spec()
function, in decl.c.
:ADDPATCH fortran:
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c (revision 123028)
+++ gcc/fortran/trans-expr.c (working copy)
@@ -227,6 +227,8 @@
gfc_init_se (&se, NULL);
gfc_conv_expr_type (&se, cl->length, gfc_charlen_type_node);
+ se.expr = fold_build2 (MAX_EXPR, gfc_charlen_type_node, se.expr,
+ build_int_cst (gfc_charlen_type_node, 0));
gfc_add_block_to_block (pblock, &se.pre);
tmp = cl->backend_decl;