Re: [v2 of PATCH 06/14] Strip location wrappers in operand_equal_p

2017-12-19 Thread Jakub Jelinek
On Tue, Dec 19, 2017 at 04:59:34PM -0500, Jason Merrill wrote:
> > Or do you mean it should strip just the special VIEW_CONVERT_EXPR
> > that has type identical to the operand's type?
> 
> That; interpreting something as the same type seems like a nop.

Ok, that makes sense.

Jakub


Re: [v2 of PATCH 06/14] Strip location wrappers in operand_equal_p

2017-12-19 Thread Jason Merrill
On Tue, Dec 19, 2017 at 3:49 PM, Jakub Jelinek  wrote:
> On Tue, Dec 19, 2017 at 03:13:13PM -0500, Jason Merrill wrote:
>> On 12/17/2017 09:07 PM, David Malcolm wrote:
>> > On Mon, 2017-12-11 at 18:37 -0500, Jason Merrill wrote:
>> > > On 11/10/2017 04:45 PM, David Malcolm wrote:
>> > > > gcc/c-family/ChangeLog:
>> > > > * c-warn.c (sizeof_pointer_memaccess_warning): Strip any
>> > > > location
>> > > > wrappers from src and dest.
>> > >
>> > > Here the existing calls to tree_strip_nop_conversions ought to
>> > > handle
>> > > the wrappers.
>> >
>> > They don't; when EXP is a VIEW_CONVERT_EXPR wrapper around a VAR_DECL...
>> >
>> > 11887   static inline bool
>> > 11888   tree_nop_conversion (const_tree exp)
>> > 11889   {
>> > 11890 tree outer_type, inner_type;
>> > 11891
>> > 11892 if (!CONVERT_EXPR_P (exp)
>> > 11893 && TREE_CODE (exp) != NON_LVALUE_EXPR)
>> > 11894   return false;
>> >
>> > ...tree_nop_conversion bails out at this "return false;", and hence
>> > tree_strip_nop_conversions simply returns the wrapper that was passed
>> > in.
>>
>> Right.  So let's change tree_nop_conversion to return true.
>
> I'd fear that would break too much stuff, VIEW_CONVERT_EXPR is not
> a normal conversion, but reinterpretation of the bits.
>
> Or do you mean it should strip just the special VIEW_CONVERT_EXPR
> that has type identical to the operand's type?

That; interpreting something as the same type seems like a nop.

Jason


Re: [v2 of PATCH 06/14] Strip location wrappers in operand_equal_p

2017-12-19 Thread Jakub Jelinek
On Tue, Dec 19, 2017 at 03:13:13PM -0500, Jason Merrill wrote:
> On 12/17/2017 09:07 PM, David Malcolm wrote:
> > On Mon, 2017-12-11 at 18:37 -0500, Jason Merrill wrote:
> > > On 11/10/2017 04:45 PM, David Malcolm wrote:
> > > > gcc/c-family/ChangeLog:
> > > > * c-warn.c (sizeof_pointer_memaccess_warning): Strip any
> > > > location
> > > > wrappers from src and dest.
> > > 
> > > Here the existing calls to tree_strip_nop_conversions ought to
> > > handle
> > > the wrappers.
> > 
> > They don't; when EXP is a VIEW_CONVERT_EXPR wrapper around a VAR_DECL...
> > 
> > 11887   static inline bool
> > 11888   tree_nop_conversion (const_tree exp)
> > 11889   {
> > 11890 tree outer_type, inner_type;
> > 11891   
> > 11892 if (!CONVERT_EXPR_P (exp)
> > 11893 && TREE_CODE (exp) != NON_LVALUE_EXPR)
> > 11894   return false;
> > 
> > ...tree_nop_conversion bails out at this "return false;", and hence
> > tree_strip_nop_conversions simply returns the wrapper that was passed
> > in.
> 
> Right.  So let's change tree_nop_conversion to return true.

I'd fear that would break too much stuff, VIEW_CONVERT_EXPR is not
a normal conversion, but reinterpretation of the bits.

Or do you mean it should strip just the special VIEW_CONVERT_EXPR
that has type identical to the operand's type?

Jakub


Re: [v2 of PATCH 06/14] Strip location wrappers in operand_equal_p

2017-12-19 Thread Jason Merrill

On 12/17/2017 09:07 PM, David Malcolm wrote:

On Mon, 2017-12-11 at 18:37 -0500, Jason Merrill wrote:

On 11/10/2017 04:45 PM, David Malcolm wrote:

gcc/c-family/ChangeLog:
* c-warn.c (sizeof_pointer_memaccess_warning): Strip any
location
wrappers from src and dest.


Here the existing calls to tree_strip_nop_conversions ought to
handle
the wrappers.


They don't; when EXP is a VIEW_CONVERT_EXPR wrapper around a VAR_DECL...

11887   static inline bool
11888   tree_nop_conversion (const_tree exp)
11889   {
11890 tree outer_type, inner_type;
11891   
11892 if (!CONVERT_EXPR_P (exp)
11893 && TREE_CODE (exp) != NON_LVALUE_EXPR)
11894   return false;

...tree_nop_conversion bails out at this "return false;", and hence
tree_strip_nop_conversions simply returns the wrapper that was passed
in.


Right.  So let's change tree_nop_conversion to return true.

Jason


Re: [v2 of PATCH 06/14] Strip location wrappers in operand_equal_p

2017-12-18 Thread Jakub Jelinek
On Sun, Dec 17, 2017 at 09:07:54PM -0500, David Malcolm wrote:
> What do you think?
> 
> Successfully bootstrapped on x86_64-pc-linux-gnu, as
> part of the kit.
> 
> gcc/ChangeLog:
>   * fold-const.c (operand_equal_p): Strip any location wrappers,
>   before computing hashes.
> ---
>  gcc/fold-const.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/gcc/fold-const.c b/gcc/fold-const.c
> index 0f11076..2b938900 100644
> --- a/gcc/fold-const.c
> +++ b/gcc/fold-const.c
> @@ -2804,6 +2804,9 @@ combine_comparisons (location_t loc,
>  int
>  operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
>  {
> +  STRIP_ANY_LOCATION_WRAPPER (arg0);
> +  STRIP_ANY_LOCATION_WRAPPER (arg1);
> +

Certainly not at this spot.
The checking that hashing ignores the location wrappers needs to be done
first.  And inchash:add_expr needs to ignore those.

Jakub


[v2 of PATCH 06/14] Strip location wrappers in operand_equal_p

2017-12-17 Thread David Malcolm
On Mon, 2017-12-11 at 18:37 -0500, Jason Merrill wrote:
> On 11/10/2017 04:45 PM, David Malcolm wrote:
> > gcc/c-family/ChangeLog:
> > * c-warn.c (sizeof_pointer_memaccess_warning): Strip any
> > location
> > wrappers from src and dest.
> 
> Here the existing calls to tree_strip_nop_conversions ought to
> handle 
> the wrappers.

They don't; when EXP is a VIEW_CONVERT_EXPR wrapper around a VAR_DECL...

11887   static inline bool
11888   tree_nop_conversion (const_tree exp)
11889   {
11890 tree outer_type, inner_type;
11891   
11892 if (!CONVERT_EXPR_P (exp)
11893 && TREE_CODE (exp) != NON_LVALUE_EXPR)
11894   return false;

...tree_nop_conversion bails out at this "return false;", and hence
tree_strip_nop_conversions simply returns the wrapper that was passed
in.

I tried adding fold_for_warn on src and dest, but it doesn't do quite
the right thing, as
  FAIL: c-c++-common/Wsizeof-pointer-memaccess2.c  -std=gnu++98  (test for 
warnings, line 482)
  FAIL: c-c++-common/Wsizeof-pointer-memaccess2.c  -std=gnu++98  (test for 
warnings, line 483)
  FAIL: c-c++-common/Wsizeof-pointer-memaccess2.c  -std=gnu++98  (test for 
warnings, line 484)
...due to "src" changing from being a VAR_DECL to being its STRING_CST
value after the fold_for_warn,

So one approach for Wsizeof-pointer-memaccess*.c is the patch I posted
("[PATCH 06/14] Fix Wsizeof-pointer-memaccess*.c"), which ensures that
any wrappers have been stripped before the call to operand_equal_p in
sizeof_pointer_memaccess_warning.

Alternatively, here's a patch which strips wrappers in operand_equal_p.
FWIW I prefer doing it in sizeof_pointer_memaccess_warning, rather than
touching operand_equal_p.

What do you think?

Successfully bootstrapped on x86_64-pc-linux-gnu, as
part of the kit.

gcc/ChangeLog:
* fold-const.c (operand_equal_p): Strip any location wrappers,
before computing hashes.
---
 gcc/fold-const.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0f11076..2b938900 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2804,6 +2804,9 @@ combine_comparisons (location_t loc,
 int
 operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 {
+  STRIP_ANY_LOCATION_WRAPPER (arg0);
+  STRIP_ANY_LOCATION_WRAPPER (arg1);
+
   /* When checking, verify at the outermost operand_equal_p call that
  if operand_equal_p returns non-zero then ARG0 and ARG1 has the same
  hash value.  */
-- 
1.8.5.3