Patchwork [v2] : handle size_t /= ptr size in tree-ssa-strlen.c

login
register
mail settings
Submitter Tristan Gingold
Date May 15, 2012, 8:55 a.m.
Message ID <3C82CE15-00FB-4DEF-8AE8-C210D61E50FF@adacore.com>
Download mbox | patch
Permalink /patch/159259/
State New
Headers show

Comments

Tristan Gingold - May 15, 2012, 8:55 a.m.
On May 4, 2012, at 2:34 PM, Richard Guenther wrote:

> On Fri, May 4, 2012 at 2:27 PM, Tristan Gingold <gingold@adacore.com> wrote:
>> Hi,
>> 
>> get_string_length assumes that precision of size_t is the same as precision of a pointer, which isn't always true at least on VMS.
>> This patch simply add a conversion in case of mismatch.
>> 
>> Tested on ia64/VMS by cross-bootstrapping.
>> Bootstrapped and regtested on i386/GNU Linux.
>> 
>> Ok for trunk ?
> 
> Hmm, isn't the issue that size_t precision is not the same precision as
> sizetype?  You probably should use ptrofftype_p (TREE_TYPE (lhs))
> instead of spelling out 'sizetype' here.

So, second submission after bootstrapping and reg-testing on x86-64 GNU/Linux.

Ok for trunk ?

Tristan.

2012-05-04  Tristan Gingold  <gingold@adacore.com>

       * tree-ssa-strlen.c (get_string_length): Convert lhs if needed.
Richard Guenther - May 15, 2012, 9:13 a.m.
On Tue, May 15, 2012 at 10:55 AM, Tristan Gingold <gingold@adacore.com> wrote:
>
> On May 4, 2012, at 2:34 PM, Richard Guenther wrote:
>
>> On Fri, May 4, 2012 at 2:27 PM, Tristan Gingold <gingold@adacore.com> wrote:
>>> Hi,
>>>
>>> get_string_length assumes that precision of size_t is the same as precision of a pointer, which isn't always true at least on VMS.
>>> This patch simply add a conversion in case of mismatch.
>>>
>>> Tested on ia64/VMS by cross-bootstrapping.
>>> Bootstrapped and regtested on i386/GNU Linux.
>>>
>>> Ok for trunk ?
>>
>> Hmm, isn't the issue that size_t precision is not the same precision as
>> sizetype?  You probably should use ptrofftype_p (TREE_TYPE (lhs))
>> instead of spelling out 'sizetype' here.
>
> So, second submission after bootstrapping and reg-testing on x86-64 GNU/Linux.
>
> Ok for trunk ?

Ok.

Thanks,
Richard.

> Tristan.
>
> 2012-05-04  Tristan Gingold  <gingold@adacore.com>
>
>       * tree-ssa-strlen.c (get_string_length): Convert lhs if needed.
>
> diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
> index a37633a..05fd10d 100644
> --- a/gcc/tree-ssa-strlen.c
> +++ b/gcc/tree-ssa-strlen.c
> @@ -427,6 +427,12 @@ get_string_length (strinfo si)
>                                    NULL);
>          add_referenced_var (lhs_var);
>          tem = gimple_call_arg (stmt, 0);
> +          if (!ptrofftype_p (TREE_TYPE (lhs)))
> +            {
> +              lhs = convert_to_ptrofftype (lhs);
> +              lhs = force_gimple_operand_gsi (&gsi, lhs, true, NULL_TREE,
> +                                              true, GSI_SAME_STMT);
> +            }
>          lenstmt
>            = gimple_build_assign_with_ops (POINTER_PLUS_EXPR,
>                                            make_ssa_name (lhs_var, NULL),
>
Tristan Gingold - May 15, 2012, 9:32 a.m.
On May 15, 2012, at 11:13 AM, Richard Guenther wrote:

> On Tue, May 15, 2012 at 10:55 AM, Tristan Gingold <gingold@adacore.com> wrote:
>> 
>> On May 4, 2012, at 2:34 PM, Richard Guenther wrote:
>> 
>>> On Fri, May 4, 2012 at 2:27 PM, Tristan Gingold <gingold@adacore.com> wrote:
>>>> Hi,
>>>> 
>>>> get_string_length assumes that precision of size_t is the same as precision of a pointer, which isn't always true at least on VMS.
>>>> This patch simply add a conversion in case of mismatch.
>>>> 
>>>> Tested on ia64/VMS by cross-bootstrapping.
>>>> Bootstrapped and regtested on i386/GNU Linux.
>>>> 
>>>> Ok for trunk ?
>>> 
>>> Hmm, isn't the issue that size_t precision is not the same precision as
>>> sizetype?  You probably should use ptrofftype_p (TREE_TYPE (lhs))
>>> instead of spelling out 'sizetype' here.
>> 
>> So, second submission after bootstrapping and reg-testing on x86-64 GNU/Linux.
>> 
>> Ok for trunk ?
> 
> Ok.

Thanks, now committed.

Tristan.

> 
> Thanks,
> Richard.
> 
>> Tristan.
>> 
>> 2012-05-04  Tristan Gingold  <gingold@adacore.com>
>> 
>>       * tree-ssa-strlen.c (get_string_length): Convert lhs if needed.
>> 
>> diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
>> index a37633a..05fd10d 100644
>> --- a/gcc/tree-ssa-strlen.c
>> +++ b/gcc/tree-ssa-strlen.c
>> @@ -427,6 +427,12 @@ get_string_length (strinfo si)
>>                                    NULL);
>>          add_referenced_var (lhs_var);
>>          tem = gimple_call_arg (stmt, 0);
>> +          if (!ptrofftype_p (TREE_TYPE (lhs)))
>> +            {
>> +              lhs = convert_to_ptrofftype (lhs);
>> +              lhs = force_gimple_operand_gsi (&gsi, lhs, true, NULL_TREE,
>> +                                              true, GSI_SAME_STMT);
>> +            }
>>          lenstmt
>>            = gimple_build_assign_with_ops (POINTER_PLUS_EXPR,
>>                                            make_ssa_name (lhs_var, NULL),
>>

Patch

diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
index a37633a..05fd10d 100644
--- a/gcc/tree-ssa-strlen.c
+++ b/gcc/tree-ssa-strlen.c
@@ -427,6 +427,12 @@  get_string_length (strinfo si)
                                    NULL);
          add_referenced_var (lhs_var);
          tem = gimple_call_arg (stmt, 0);
+          if (!ptrofftype_p (TREE_TYPE (lhs)))
+            {
+              lhs = convert_to_ptrofftype (lhs);
+              lhs = force_gimple_operand_gsi (&gsi, lhs, true, NULL_TREE,
+                                              true, GSI_SAME_STMT);
+            }
          lenstmt
            = gimple_build_assign_with_ops (POINTER_PLUS_EXPR,
                                            make_ssa_name (lhs_var, NULL),