diff mbox series

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

Message ID 1513562874-38507-1-git-send-email-dmalcolm@redhat.com
State New
Headers show
Series None | expand

Commit Message

David Malcolm Dec. 18, 2017, 2:07 a.m. UTC
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&regrtested 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(+)

Comments

Jakub Jelinek Dec. 18, 2017, 8 a.m. UTC | #1
On Sun, Dec 17, 2017 at 09:07:54PM -0500, David Malcolm wrote:
> What do you think?
> 
> Successfully bootstrapped&regrtested 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
Jason Merrill Dec. 19, 2017, 8:13 p.m. UTC | #2
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
Jakub Jelinek Dec. 19, 2017, 8:49 p.m. UTC | #3
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
Jason Merrill Dec. 19, 2017, 9:59 p.m. UTC | #4
On Tue, Dec 19, 2017 at 3:49 PM, Jakub Jelinek <jakub@redhat.com> 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
Jakub Jelinek Dec. 19, 2017, 10:03 p.m. UTC | #5
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
diff mbox series

Patch

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.  */