This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/57503] Missing warning for signed overflow
- From: "gjl at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 16 Jan 2018 09:51:57 +0000
- Subject: [Bug tree-optimization/57503] Missing warning for signed overflow
- Auto-submitted: auto-generated
- References: <bug-57503-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57503
Georg-Johann Lay <gjl at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|wrong-code |diagnostic
Summary|[6/7/8 Regression] Wrong |Missing warning for signed
|extension of multiply |overflow
|operand |
--- Comment #20 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #18)
> (In reply to Georg-Johann Lay from comment #17)
> > Observation that -fno-wrapv also leads to correct code, hence there is
> > somewhere a wrong assumption that signed overflow occurs (which doesn't).
>
> (you probably meant -fwrapv instead of -fno-wrapv?)
Yes.
> Why do you say wrong?
> unsigned ab = a * b;
> in C, that means:
> unsigned ab = (int)a * (int)b;
Thanks, I stared too much at the 2nd multiplication.
> Since a is in [0, 255], so is (int)a. Multiplication may not overflow for a
> signed type, so (int)a*(int)b must be nonnegative. Converting it to long
> directly or through unsigned int is thus equivalent.
-Wstrict-overflow=<N> used to issue a warning like "assuming signed overflow
might not occur", and maybe I was misguidid by the missing warning.
Hence this is just a "missing warning" type of PR, if at all.