PR 84740 Wrong string length type in bounds check

Message ID 1515583126-3205-1-git-send-email-blomqvist.janne@gmail.com
State New
Headers show
Series
  • PR 84740 Wrong string length type in bounds check
Related show

Commit Message

Janne Blomqvist Jan. 10, 2018, 11:18 a.m.
Need to convert the RHS to the type of the LHS when assigning.

Regtested on x86_64-pc-linux-gnu, committed as obvious.

gcc/fortran/ChangeLog:

2018-01-10  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/84740
	* trans-array.c (gfc_trans_array_ctor_element): Convert RHS to the
	LHS type when assigning.
---
 gcc/fortran/trans-array.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

-- 
2.7.4

Comments

Jakub Jelinek Jan. 10, 2018, 11:21 a.m. | #1
On Wed, Jan 10, 2018 at 01:18:46PM +0200, Janne Blomqvist wrote:

Thanks for fixing this PR.

> @@ -1562,7 +1562,8 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc,

>  	  if (first_len)

>  	    {

>  	      gfc_add_modify (&se->pre, first_len_val,

> -				   se->string_length);

> +			      fold_convert (TREE_TYPE (first_len_val),

> +						       se->string_length));


Wrong formatting, se->string_length should have been below TREE_TYPE.

>  	      first_len = false;

>  	    }

>  	  else

> @@ -1571,7 +1572,9 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc,

>  		 length.  */

>  	      tree cond = fold_build2_loc (input_location, NE_EXPR,

>  					   logical_type_node, first_len_val,

> -					   se->string_length);

> +					   fold_convert (TREE_TYPE

> +							 (first_len_val),

> +							 se->string_length));


And here, it might have been better to add a temporary for
TREE_TYPE (first_len_val)
to avoid the excessive line wrapping.

	Jakub
Janne Blomqvist Jan. 10, 2018, 11:36 a.m. | #2
On Wed, Jan 10, 2018 at 1:21 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Jan 10, 2018 at 01:18:46PM +0200, Janne Blomqvist wrote:

>

> Thanks for fixing this PR.

>

>> @@ -1562,7 +1562,8 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc,

>>         if (first_len)

>>           {

>>             gfc_add_modify (&se->pre, first_len_val,

>> -                                se->string_length);

>> +                           fold_convert (TREE_TYPE (first_len_val),

>> +                                                    se->string_length));

>

> Wrong formatting, se->string_length should have been below TREE_TYPE.

>

>>             first_len = false;

>>           }

>>         else

>> @@ -1571,7 +1572,9 @@ gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc,

>>                length.  */

>>             tree cond = fold_build2_loc (input_location, NE_EXPR,

>>                                          logical_type_node, first_len_val,

>> -                                        se->string_length);

>> +                                        fold_convert (TREE_TYPE

>> +                                                      (first_len_val),

>> +                                                      se->string_length));

>

> And here, it might have been better to add a temporary for

> TREE_TYPE (first_len_val)

> to avoid the excessive line wrapping.


Hmm, yes. Fixed in r256426. I also managed to get the PR number wrong
(it's 83740, not 84740, fixed the ChangeLog entry too).


-- 
Janne Blomqvist

Patch

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 474a7d1..8a0afe9 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -1562,7 +1562,8 @@  gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc,
 	  if (first_len)
 	    {
 	      gfc_add_modify (&se->pre, first_len_val,
-				   se->string_length);
+			      fold_convert (TREE_TYPE (first_len_val),
+						       se->string_length));
 	      first_len = false;
 	    }
 	  else
@@ -1571,7 +1572,9 @@  gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc,
 		 length.  */
 	      tree cond = fold_build2_loc (input_location, NE_EXPR,
 					   logical_type_node, first_len_val,
-					   se->string_length);
+					   fold_convert (TREE_TYPE
+							 (first_len_val),
+							 se->string_length));
 	      gfc_trans_runtime_check
 		(true, false, cond, &se->pre, &expr->where,
 		 "Different CHARACTER lengths (%ld/%ld) in array constructor",