[Bug middle-end/102427] -Woverflow only works in constant expressions

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Sep 21 16:55:22 GMT 2021


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |diagnostic
          Component|c                           |middle-end
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-09-21
            Version|unknown                     |12.0
             Status|UNCONFIRMED                 |NEW
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
There is some support for issuing overflow warnings in the middle end under
-Wstrict-overflow but that option is documented to only trigger in cases when
GCC makes codegen decisions based on the absence of overflow, which it doesn't
in this case (the overflow wraps around zero).

That no warning is issued here is partly a bug/limitation of the implementation
of the folder as indicated by the FIXME in wi::mul_internal() in wide-int.cc:

          if (sgn == SIGNED)
            {
              if ((HOST_WIDE_INT) r != sext_hwi (r, prec))
                /* FIXME: Signed overflow type is not implemented yet.  */
                *overflow = OVF_UNKNOWN;

and partly also a consequence of simply discarding it when it is set above, by
calling drop_tree_overflow().  I don't know why that function is called.  But
preserving the overflow there still doesn't result in a warning.

I do agree that the constness of local variables shouldn't matter and issuing
the warning regardless would be helpful.  So confirmed as an enhancement
request.


More information about the Gcc-bugs mailing list