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®rtested 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