public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR 84740 Wrong string length type in bounds check
@ 2018-01-10 11:18 Janne Blomqvist
  2018-01-10 11:21 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Janne Blomqvist @ 2018-01-10 11:18 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: Janne Blomqvist

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(-)

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",
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR 84740 Wrong string length type in bounds check
  2018-01-10 11:18 [PATCH] PR 84740 Wrong string length type in bounds check Janne Blomqvist
@ 2018-01-10 11:21 ` Jakub Jelinek
  2018-01-10 11:36   ` Janne Blomqvist
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2018-01-10 11:21 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: fortran, gcc-patches

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PR 84740 Wrong string length type in bounds check
  2018-01-10 11:21 ` Jakub Jelinek
@ 2018-01-10 11:36   ` Janne Blomqvist
  0 siblings, 0 replies; 3+ messages in thread
From: Janne Blomqvist @ 2018-01-10 11:36 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Fortran List, GCC Patches

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-10 11:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-10 11:18 [PATCH] PR 84740 Wrong string length type in bounds check Janne Blomqvist
2018-01-10 11:21 ` Jakub Jelinek
2018-01-10 11:36   ` Janne Blomqvist

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).