https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84095

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-01-29
                 CC|                            |jakub at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This warning at least in its current shape doesn't belong into either -Wall or
-W IMNSHO.

  if (TREE_CODE (expr) == ADDR_EXPR)
    {
      poly_int64 off;
      tree op = TREE_OPERAND (expr, 0);

      /* Determine the base object or pointer of the reference
         and its constant offset from the beginning of the base.  */
      base = get_addr_base_and_unit_offset (op, &off);

      HOST_WIDE_INT const_off;
      if (base && off.is_constant (&const_off))
        {
          offrange[0] += const_off;
          offrange[1] += const_off;

          /* Stash the reference for offset validation.  */
          ref = op;

          /* Also stash the constant offset for offset validation.  */
          if (TREE_CODE (op) == COMPONENT_REF)
            refoff = const_off;
        }
      else
        {
          size = NULL_TREE;
          base = get_base_address (TREE_OPERAND (expr, 0));
        }
    }

is plain wrong.  get_addr_base_and_unit_offset is solely for computation of a
constant offset (or these days poly_int64 offset).  Here you need to do
get_inner_reference instead, and treat the poly_int64 bit offset (rather than
byte offset) as the constant part and for the variable part try to use
value ranges and handle casts/extensions in the expression too properly.
I don't see how this warning can be enabled at all at -O0/-O1/-Og, unless you
warn solely about cases where you can prove overalap, rather than warning just
in case.  And the general case of the warning should be, if I don't understand
something (such as the base = get_base_address (TREE_OPERAND (expr, 0)); above,
I punt on the warning, rather than just giving false positives.  That is only a
sure way to add the warning to the kill-list of projects that -Wno-* broken
warnings, and for some users to stop using GCC.

Reply via email to