From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 65BBA385B530; Fri, 31 Mar 2023 09:18:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65BBA385B530 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680254311; bh=UdScGN/j+SacXUSj0SBw5xqoHC66cxlTXFOXukaYhos=; h=From:To:Subject:Date:In-Reply-To:References:From; b=e3VitQpaDcp1FGaF0rPULWRt8QxmUwADKMNIzY8Ibl91EheLhnqlDvm8d4wEjkOL9 VFWlAhJ8x3pMZTSmcDcruzqtk0cTVA+p1lFKRoIQcbNay2nWxpjmXmzf35KuNMtuUL taPA/QRBAJIBQcDk1EBLn6J0VxwyDof/1hhOYHHs= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/24542] potential unwanted truncation of operation overflow should be warned on assignment to wider variable Date: Fri, 31 Mar 2023 09:18:30 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.0.2 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on bug_status resolution short_desc everconfirmed Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D24542 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2023-03-31 Status|RESOLVED |NEW Resolution|WONTFIX |--- Summary|potential integer overflow |potential unwanted |should be warned on |truncation of operation |assignment to wider |overflow should be warned |variable |on assignment to wider | |variable Ever confirmed|0 |1 --- Comment #13 from Richard Biener --- Let me re-open this. I agree that it sounds useful to have a diagnostic th= at would catch these cases but I also think it might have many false positives. But that's similar to diagnosing if (a || b && c). That said, the burden is on whoever is going to prototype patch with extensive enough test coverage. The question is whether to diagnose int x1, x2; long y1; y1 =3D x1 * x2; since when x1 * x2 overflows that even invokes undefined behavior (so it's even worse than the unsigned case). The description is misleading, there's no "overflow on assignment" but the operation itself might overflow and the truncated value is then widened on assignment. The assignment is a mere hint that a wider result might have been intended (and a good enough hint IMHO).=