* RE: [PATCH] PR fortran/77505 -- Treat negative character length as LEN=0
@ 2016-11-30 5:13 Punnoose, Elizebeth
2016-12-01 23:23 ` Steve Kargl
0 siblings, 1 reply; 4+ messages in thread
From: Punnoose, Elizebeth @ 2016-11-30 5:13 UTC (permalink / raw)
To: fortran, gcc-patches
Please excuse the messy formatting in my initial mail. Resending with proper formatting.
This patch checks for negative character length in the array constructor, and treats it as LEN=0.
A warning message is also printed if bounds checking is enabled.
Bootstrapped and regression tested the patch on x86_64-linux-gnu and aarch64-linux-gnu.
Index: ChangeLog
===================================================================
--- ChangeLog (revision 242906)
+++ ChangeLog (working copy)
@@ -1,3 +1,9 @@
+2016-11-30 Elizebeth Punnoose <elizebeth.punnoose@hpe.com>
+
+ PR fortran/77505
+ * trans-array.c (trans_array_constructor): Treat negative character
+ length as LEN=0.
+
2016-11-27 Paul Thomas <pault@gcc.gnu.org>
PR fortran/78474
Index: trans-array.c
===================================================================
--- trans-array.c (revision 242906)
+++ trans-array.c (working copy)
@@ -2226,6 +2226,8 @@ trans_array_constructor (gfc_ss * ss, lo
gfc_ss_info *ss_info;
gfc_expr *expr;
gfc_ss *s;
+ tree neg_len;
+ char *msg;
/* Save the old values for nested checking. */
old_first_len = first_len;
@@ -2271,6 +2273,28 @@ trans_array_constructor (gfc_ss * ss, lo
gfc_conv_expr_type (&length_se, expr->ts.u.cl->length,
gfc_charlen_type_node);
ss_info->string_length = length_se.expr;
+
+ /* Check if the character length is negative,
+ if so consider it as LEN=0. */
+ neg_len = fold_build2_loc (input_location, LT_EXPR,
+ boolean_type_node, ss_info->string_length,
+ build_int_cst (gfc_charlen_type_node, 0));
+ /* Print a warning if bounds checking is enabled. */
+ if (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS)
+ {
+ msg = xasprintf ("Negative character length will be treated"
+ " as LEN=0");
+ gfc_trans_runtime_check (false, true, neg_len, &length_se.pre,
+ where, msg);
+ free (msg);
+ }
+ ss_info->string_length = fold_build3_loc (input_location, COND_EXPR,
+ gfc_charlen_type_node, neg_len,
+ build_int_cst (gfc_charlen_type_node, 0),
+ ss_info->string_length);
+ ss_info->string_length = gfc_evaluate_now (ss_info->string_length,
+ &length_se.pre);
+
gfc_add_block_to_block (&outer_loop->pre, &length_se.pre);
gfc_add_block_to_block (&outer_loop->post, &length_se.post);
}
Index: ChangeLog
===================================================================
--- ChangeLog (revision 242906)
+++ ChangeLog (working copy)
@@ -1,3 +1,9 @@
+2016-11-30 Elizebeth Punnoose <elizebeth.punnoose@hpe.com>
+
+ PR fortran/77505
+ * gfortran.dg/pr77505_1.f90: New test.
+ * gfortran.dg/pr77505_2.f90: New test.
+
2016-11-27 Paul Thomas <pault@gcc.gnu.org>
PR fortran/78474
Index: pr77505_1.f90
===================================================================
--- pr77505_1.f90 (nonexistent)
+++ pr77505_1.f90 (working copy)
@@ -0,0 +1,13 @@
+! { dg-do run }
+program rabbithole
+implicit none
+character(len=:),allocatable :: text_block(:) integer
+:: i integer :: ii
+character(len=10) :: cten='abcdefghij'
+character(len=20) :: ctwenty='abcdefghijabcdefghij'
+ii=-6
+text_block=[ character(len=ii) :: cten, ctwenty ] write(*,*)'WRITE IT'
+write(*,'(a)')(trim(text_block(i)),i=1,size(text_block))
+end program rabbithole
Index: pr77505_2.f90
===================================================================
--- pr77505_2.f90 (nonexistent)
+++ pr77505_2.f90 (working copy)
@@ -0,0 +1,14 @@
+! { dg-options "-fcheck=bounds" }
+! { dg-do run }
+program rabbithole
+implicit none
+character(len=:),allocatable :: text_block(:)
+integer :: i
+integer :: ii
+character(len=10) :: cten='abcdefghij'
+character(len=20) :: ctwenty='abcdefghijabcdefghij'
+ii=-6
+text_block=[ character(len=ii) :: cten, ctwenty ]
+write(*,*)'WRITE IT'
+write(*,'(a)')(trim(text_block(i)),i=1,size(text_block))
+end program rabbithole
Thanks,
Elizebeth
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PR fortran/77505 -- Treat negative character length as LEN=0
2016-11-30 5:13 [PATCH] PR fortran/77505 -- Treat negative character length as LEN=0 Punnoose, Elizebeth
@ 2016-12-01 23:23 ` Steve Kargl
2016-12-02 9:15 ` Punnoose, Elizebeth
0 siblings, 1 reply; 4+ messages in thread
From: Steve Kargl @ 2016-12-01 23:23 UTC (permalink / raw)
To: Punnoose, Elizebeth; +Cc: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1458 bytes --]
On Wed, Nov 30, 2016 at 05:13:28AM +0000, Punnoose, Elizebeth wrote:
> Please excuse the messy formatting in my initial mail. Resending
> with proper formatting.
>
> This patch checks for negative character length in the array
> constructor, and treats it as LEN=0.
>
> A warning message is also printed if bounds checking is enabled.
>
> Bootstrapped and regression tested the patch on x86_64-linux-gnu
> and aarch64-linux-gnu.
>
Thanks. After regression testing on x86_64-*-freebsd, I committed
the attached patch. Not sure if the whitespace got messed up by
my email agent, but I needed to reformat your testcases. I took the
opportunity to rename and improve the testcases. The improvements
check that in fact len=0 and that a warning is issued.
Hopefully, you're inclined to submit additional patches in the future.
A few recommendations are to include the text of your ChangeLog
entry in body of the email, for example,
2016-12-01 Elizebeth Punnoose <elizebeth.punnoose@hpe.com>
PR fortran/77505
* trans-array.c (trans_array_constructor): Treat negative character
length as LEN = 0.
2016-12-01 Elizebeth Punnoose <elizebeth.punnoose@hpe.com>
PR fortran/77505
* gfortran.dg/char_length_20.f90: New test.
* gfortran.dg/char_length_21.f90: Ditto.
(Note, 2 spaces before and after your name.) Then attach the
patch to the email. This hopefully will prevent formatting
issues with various email clients/servers.
--
Steve
[-- Attachment #2: pr77505.diff --]
[-- Type: text/x-diff, Size: 3066 bytes --]
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c (revision 243134)
+++ gcc/fortran/trans-array.c (working copy)
@@ -2226,6 +2226,8 @@ trans_array_constructor (gfc_ss * ss, lo
gfc_ss_info *ss_info;
gfc_expr *expr;
gfc_ss *s;
+ tree neg_len;
+ char *msg;
/* Save the old values for nested checking. */
old_first_len = first_len;
@@ -2271,6 +2273,29 @@ trans_array_constructor (gfc_ss * ss, lo
gfc_conv_expr_type (&length_se, expr->ts.u.cl->length,
gfc_charlen_type_node);
ss_info->string_length = length_se.expr;
+
+ /* Check if the character length is negative. If it is, then
+ set LEN = 0. */
+ neg_len = fold_build2_loc (input_location, LT_EXPR,
+ boolean_type_node, ss_info->string_length,
+ build_int_cst (gfc_charlen_type_node, 0));
+ /* Print a warning if bounds checking is enabled. */
+ if (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS)
+ {
+ msg = xasprintf ("Negative character length treated as LEN = 0");
+ gfc_trans_runtime_check (false, true, neg_len, &length_se.pre,
+ where, msg);
+ free (msg);
+ }
+
+ ss_info->string_length
+ = fold_build3_loc (input_location, COND_EXPR,
+ gfc_charlen_type_node, neg_len,
+ build_int_cst (gfc_charlen_type_node, 0),
+ ss_info->string_length);
+ ss_info->string_length = gfc_evaluate_now (ss_info->string_length,
+ &length_se.pre);
+
gfc_add_block_to_block (&outer_loop->pre, &length_se.pre);
gfc_add_block_to_block (&outer_loop->post, &length_se.post);
}
Index: gcc/testsuite/gfortran.dg/char_length_20.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_length_20.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/char_length_20.f90 (working copy)
@@ -0,0 +1,13 @@
+! { dg-do run }
+! { dg-options "-fcheck=bounds" }
+program rabbithole
+ implicit none
+ character(len=:), allocatable :: text_block(:)
+ integer i, ii
+ character(len=10) :: cten='abcdefghij'
+ character(len=20) :: ctwenty='abcdefghijabcdefghij'
+ ii = -6
+ text_block=[ character(len=ii) :: cten, ctwenty ]
+ if (any(len_trim(text_block) /= 0)) call abort
+end program rabbithole
+! { dg-output "At line 10 of file .*char_length_20.f90.*Fortran runtime warning: Negative character length treated as LEN = 0" }
Index: gcc/testsuite/gfortran.dg/char_length_21.f90
===================================================================
--- gcc/testsuite/gfortran.dg/char_length_21.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/char_length_21.f90 (working copy)
@@ -0,0 +1,11 @@
+! { dg-do run }
+program rabbithole
+ implicit none
+ character(len=:), allocatable :: text_block(:)
+ integer i, ii
+ character(len=10) :: cten='abcdefghij'
+ character(len=20) :: ctwenty='abcdefghijabcdefghij'
+ ii = -6
+ text_block = [character(len=ii) :: cten, ctwenty]
+ if (any(len_trim(text_block) /= 0)) call abort
+end program rabbithole
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] PR fortran/77505 -- Treat negative character length as LEN=0
2016-12-01 23:23 ` Steve Kargl
@ 2016-12-02 9:15 ` Punnoose, Elizebeth
0 siblings, 0 replies; 4+ messages in thread
From: Punnoose, Elizebeth @ 2016-12-02 9:15 UTC (permalink / raw)
To: kargl; +Cc: fortran, gcc-patches
Thank you Steve.
Thanks,
Elizebeth
-----Original Message-----
From: Steve Kargl [mailto:sgk@troutmask.apl.washington.edu]
Sent: 02 December 2016 04:54
To: Punnoose, Elizebeth <elizebeth.punnoose@hpe.com>
Cc: fortran@gcc.gnu.org; gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] PR fortran/77505 -- Treat negative character length as LEN=0
On Wed, Nov 30, 2016 at 05:13:28AM +0000, Punnoose, Elizebeth wrote:
> Please excuse the messy formatting in my initial mail. Resending with
> proper formatting.
>
> This patch checks for negative character length in the array
> constructor, and treats it as LEN=0.
>
> A warning message is also printed if bounds checking is enabled.
>
> Bootstrapped and regression tested the patch on x86_64-linux-gnu and
> aarch64-linux-gnu.
>
Thanks. After regression testing on x86_64-*-freebsd, I committed the attached patch. Not sure if the whitespace got messed up by my email agent, but I needed to reformat your testcases. I took the opportunity to rename and improve the testcases. The improvements check that in fact len=0 and that a warning is issued.
Hopefully, you're inclined to submit additional patches in the future.
A few recommendations are to include the text of your ChangeLog entry in body of the email, for example,
2016-12-01 Elizebeth Punnoose <elizebeth.punnoose@hpe.com>
PR fortran/77505
* trans-array.c (trans_array_constructor): Treat negative character
length as LEN = 0.
2016-12-01 Elizebeth Punnoose <elizebeth.punnoose@hpe.com>
PR fortran/77505
* gfortran.dg/char_length_20.f90: New test.
* gfortran.dg/char_length_21.f90: Ditto.
(Note, 2 spaces before and after your name.) Then attach the patch to the email. This hopefully will prevent formatting issues with various email clients/servers.
--
Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] PR fortran/77505 -- Treat negative character length as LEN=0
@ 2016-11-30 4:52 Punnoose, Elizebeth
0 siblings, 0 replies; 4+ messages in thread
From: Punnoose, Elizebeth @ 2016-11-30 4:52 UTC (permalink / raw)
To: fortran, gcc-patches
This patch checks for negative character length in the array constructor,
and treats it as LEN=0. A warning message is also printed if bounds checking is enabled.
Bootstrapped and regression tested the patch on x86_64-linux-gnu and aarch64-linux-gnu.
Index: ChangeLog
===================================================================
--- ChangeLog (revision 242906)
+++ ChangeLog (working copy)
@@ -1,3 +1,9 @@
+2016-11-30 Elizebeth Punnoose <elizebeth.punnoose@hpe.com>
+
+ PR fortran/77505
+ * trans-array.c (trans_array_constructor): Treat negative character
+ length as LEN=0.
+
2016-11-27 Paul Thomas <pault@gcc.gnu.org>
PR fortran/78474
Index: trans-array.c
===================================================================
--- trans-array.c (revision 242906)
+++ trans-array.c (working copy)
@@ -2226,6 +2226,8 @@ trans_array_constructor (gfc_ss * ss, lo
gfc_ss_info *ss_info;
gfc_expr *expr;
gfc_ss *s;
+ tree neg_len;
+ char *msg;
/* Save the old values for nested checking. */
old_first_len = first_len;
@@ -2271,6 +2273,28 @@ trans_array_constructor (gfc_ss * ss, lo
gfc_conv_expr_type (&length_se, expr->ts.u.cl->length,
gfc_charlen_type_node);
ss_info->string_length = length_se.expr;
+
+ /* Check if the character length is negative,
+ if so consider it as LEN=0. */
+ neg_len = fold_build2_loc (input_location, LT_EXPR,
+ boolean_type_node, ss_info->string_length,
+ build_int_cst (gfc_charlen_type_node, 0));
+ /* Print a warning if bounds checking is enabled. */
+ if (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS)
+ {
+ msg = xasprintf ("Negative character length will be treated"
+ " as LEN=0");
+ gfc_trans_runtime_check (false, true, neg_len, &length_se.pre,
+ where, msg);
+ free (msg);
+ }
+ ss_info->string_length = fold_build3_loc (input_location, COND_EXPR,
+ gfc_charlen_type_node, neg_len,
+ build_int_cst (gfc_charlen_type_node, 0),
+ ss_info->string_length);
+ ss_info->string_length = gfc_evaluate_now (ss_info->string_length,
+ &length_se.pre);
+
gfc_add_block_to_block (&outer_loop->pre, &length_se.pre);
gfc_add_block_to_block (&outer_loop->post, &length_se.post);
}
Index: ChangeLog
===================================================================
--- ChangeLog (revision 242906)
+++ ChangeLog (working copy)
@@ -1,3 +1,9 @@
+2016-11-30 Elizebeth Punnoose <elizebeth.punnoose@hpe.com>
+
+ PR fortran/77505
+ * gfortran.dg/pr77505_1.f90: New test.
+ * gfortran.dg/pr77505_2.f90: New test.
+
2016-11-27 Paul Thomas <pault@gcc.gnu.org>
PR fortran/78474
Index: pr77505_1.f90
===================================================================
--- pr77505_1.f90 (nonexistent)
+++ pr77505_1.f90 (working copy)
@@ -0,0 +1,13 @@
+! { dg-do run }
+program rabbithole
+implicit none
+character(len=:),allocatable :: text_block(:)
+integer :: i
+integer :: ii
+character(len=10) :: cten='abcdefghij'
+character(len=20) :: ctwenty='abcdefghijabcdefghij'
+ii=-6
+text_block=[ character(len=ii) :: cten, ctwenty ]
+write(*,*)'WRITE IT'
+write(*,'(a)')(trim(text_block(i)),i=1,size(text_block))
+end program rabbithole
Index: pr77505_2.f90
===================================================================
--- pr77505_2.f90 (nonexistent)
+++ pr77505_2.f90 (working copy)
@@ -0,0 +1,14 @@
+! { dg-options "-fcheck=bounds" }
+! { dg-do run }
+program rabbithole
+implicit none
+character(len=:),allocatable :: text_block(:)
+integer :: i
+integer :: ii
+character(len=10) :: cten='abcdefghij'
+character(len=20) :: ctwenty='abcdefghijabcdefghij'
+ii=-6
+text_block=[ character(len=ii) :: cten, ctwenty ]
+write(*,*)'WRITE IT'
+write(*,'(a)')(trim(text_block(i)),i=1,size(text_block))
+end program rabbithole
Thanks,
Elizebeth
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-12-02 9:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-30 5:13 [PATCH] PR fortran/77505 -- Treat negative character length as LEN=0 Punnoose, Elizebeth
2016-12-01 23:23 ` Steve Kargl
2016-12-02 9:15 ` Punnoose, Elizebeth
-- strict thread matches above, loose matches on Subject: below --
2016-11-30 4:52 Punnoose, Elizebeth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).