[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 --- Comment #12 from Elizebeth Punnoose --- (In reply to kargl from comment #11) > Fixed on trunk. Closing. > > Elizebeth, Thanks for the patch. Thank you.
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 kargl at gcc dot gnu.org changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED Target Milestone|--- |7.0 --- Comment #11 from kargl at gcc dot gnu.org --- Fixed on trunk. Closing. Elizebeth, Thanks for the patch.
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 --- Comment #10 from kargl at gcc dot gnu.org --- Author: kargl Date: Thu Dec 1 23:11:35 2016 New Revision: 243143 URL: https://gcc.gnu.org/viewcvs?rev=243143&root=gcc&view=rev Log: 2016-12-01 Elizebeth Punnoose PR fortran/77505 * trans-array.c (trans_array_constructor): Treat negative character length as LEN = 0. 2016-12-01 Elizebeth Punnoose PR fortran/77505 * gfortran.dg/char_length_20.f90: New test. * gfortran.dg/char_length_21.f90: Ditto. Added: trunk/gcc/testsuite/gfortran.dg/char_length_20.f90 trunk/gcc/testsuite/gfortran.dg/char_length_21.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-array.c trunk/gcc/testsuite/ChangeLog
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 --- Comment #9 from Elizebeth Punnoose --- (In reply to Janne Blomqvist from comment #8) > (In reply to Elizebeth Punnoose from comment #6) > > Modified code with the warning message moved behind -fcheck=bounds. > > > > Index: trans-array.c > > === > > --- trans-array.c (revision 241960) > > +++ trans-array.c (working copy) > > @@ -2226,6 +2226,8 @@ > >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,27 @@ > > 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, gfc_index_zero_node, > > + 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); > > } > > > Shouldn't you have build_int_cst (gfc_charlen_type_node, 0) instead of > gfc_index_zero_node? Thank you for your comment. I will make the necessary changes and re-post.
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 Janne Blomqvist changed: What|Removed |Added CC||jb at gcc dot gnu.org --- Comment #8 from Janne Blomqvist --- (In reply to Elizebeth Punnoose from comment #6) > Modified code with the warning message moved behind -fcheck=bounds. > > Index: trans-array.c > === > --- trans-array.c (revision 241960) > +++ trans-array.c (working copy) > @@ -2226,6 +2226,8 @@ >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,27 @@ > 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, gfc_index_zero_node, > +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); > } Shouldn't you have build_int_cst (gfc_charlen_type_node, 0) instead of gfc_index_zero_node?
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 --- Comment #7 from Elizebeth Punnoose --- I plan to send the patch to gcc-patches from my official mail id, in a couple of days. Please do let me know if there are any suggestions/comments.
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 --- Comment #6 from Elizebeth Punnoose --- Modified code with the warning message moved behind -fcheck=bounds. Index: trans-array.c === --- trans-array.c (revision 241960) +++ trans-array.c (working copy) @@ -2226,6 +2226,8 @@ 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,27 @@ 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, gfc_index_zero_node, + 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); }
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 --- Comment #5 from Elizebeth Punnoose --- Hi Steve, To answer your first question, I am covered by the HPE corporate assignment. When posting the patch, I will be doing so from my corporate email id. The Fortran 2008 standards page at http://www.j3-fortran.org/doc/year/10/10-007.pdf, states the the following. 4.4.3.2 Character type specifier 5 If the character length parameter value evaluates to a negative value, the length of character entities declared is zero. I do agree with you that a negative character length does not indicate a violation of the standard, rather that it has to be considered as len=0, and hence does not warrant issuing a warning. The warning message can be hidden behind the -fcheck=bounds option.
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 --- Comment #4 from Steve Kargl --- On Fri, Nov 11, 2016 at 04:49:49AM +, elizebethp at gmail dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 > > Elizebeth Punnoose changed: > Hi Elizebeth, Just an administrative question at the moment. Do you have a copyright assignment for GCC on file with the FSF? I need to review the standards, but if the standard state a negative length should be treated as if it is len=0 then the I think the warning message should be hidden behind a -fcheck= option. Perhaps, we can overload -fcheck=bounds or introduce a new option key -fcheck=charlen. My reason is that it can be annoying for standard conforming code to issue a warning for standard conforming behavior.
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 Elizebeth Punnoose changed: What|Removed |Added CC||elizebethp at gmail dot com --- Comment #3 from Elizebeth Punnoose --- The segmentation fault is reproducible on x86 & ARM64, with the top of trunk. I have now added a check in trans-array.c:trans_array_constructor() to check for character lengths less than zero, for character arrays. If the length is found to be negative, a warning message is printed that the length will be considered as LEN=0, and the length is set to zero. Index: trans-array.c === --- trans-array.c (revision 241960) +++ trans-array.c (working copy) @@ -2226,6 +2226,8 @@ 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,19 @@ 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 length is negative, if so print a warning + and consider the length as zero. */ + neg_len = fold_build2_loc (input_location, LT_EXPR, + boolean_type_node, + ss_info->string_length, build_int_cst (gfc_charlen_type_node, 0)); + 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, gfc_index_zero_node, 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); } The test suite has run clean with the above changes merged on top of trunk. Kindly review and provide your suggestions if any. I will post the patch on the gcc-patches mail list, if there is no objection.
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 kargl at gcc dot gnu.org changed: What|Removed |Added Priority|P3 |P4 Severity|minor |normal
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 --- Comment #2 from Steve Kargl --- On Wed, Sep 07, 2016 at 07:01:40PM +, kargl at gcc dot gnu.org wrote: > --- Comment #1 from kargl at gcc dot gnu.org --- > This is going to require someone smarting than I to fix. > The problem lies in trans-array.c (get_array_ctor_strlen). > This function walks the elments of the array constructor > looking for the string length. It nave takes into account > the type spec in [character(len=ii) :: ]. s/nave/never Note, the problem may actually be in some other function that calls get_array_ctor_strlen, because this function never have been called!
[Bug fortran/77505] Negative character length not treated as LEN=0
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77505 kargl at gcc dot gnu.org changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2016-09-07 CC||kargl at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from kargl at gcc dot gnu.org --- This is going to require someone smarting than I to fix. The problem lies in trans-array.c (get_array_ctor_strlen). This function walks the elments of the array constructor looking for the string length. It nave takes into account the type spec in [character(len=ii) :: ].