From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B53393858D3C; Fri, 10 Nov 2023 18:41:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B53393858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1699641663; bh=VssPmP0mou5N18O3STYpbezCLY25T03wspkWc5fWaU0=; h=From:To:Subject:Date:From; b=BOXYomP1fIVyqmdfDwkJA8uNK0eY3EJ6QdGm6GbIrg0ARdMsAL5LbJ3ZbUSA8yICV HRdQxA5jNa3omaHNys4s03gU4dMFV1ocPcwoHKLAnfoAw7LYU2Ik6KdgV4DTIpZrZt r+oG90M1XGh67m+oyJGj5T8WRA20ttRqZZuyQaLA= From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/112479] New: Missing -Woverflow warnings with bit fields with assignment of a constant Date: Fri, 10 Nov 2023 18:41:03 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D112479 Bug ID: 112479 Summary: Missing -Woverflow warnings with bit fields with assignment of a constant Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org Target Milestone: --- I noticed that -Woverflow misses some cases of -Woverflow. DISCLAIMER: It might be that some sign/unsigned promotion makes it desirably that no warning is shown. Still, as a mere user, I find it odd to see no warning. * * * I did notice that Clang's -Wbitfield-constant-conversion warning (also on by default) shows a rather similar pattern of warning vs. no warning. However, Clang does warn for the following two assignments: s.b =3D 2; // MISSING diagnostic for 2 -> -2 s.b =3D 3; // MISSING diagnostic for 3 -> -1 Thus, there is at least some inconsistency with regards to the warning betw= een GCC and Clang * * * /* Either of the following warning is shown by GCC, if any: warning: overflow in conversion from =E2=80=98int=E2=80=99 to =E2=80=98sign= ed char:1=E2=80=99 changes value from =E2=80=981=E2=80=99 to =E2=80=98-0=E2=80=99 [-Woverflow] warning: unsigned conversion from =E2=80=98int=E2=80=99 to =E2=80=98unsigne= d char:1=E2=80=99 changes value from =E2=80=98-3=E2=80=99 to =E2=80=981=E2=80=99 [-Woverflow] */ void my_signed() { struct { int a:1, b:2; } s; s.a =3D -3; // Diagnosed: from =E2=80=98-3=E2=80=99 to =E2=80=98-1=E2=80= =99 s.a =3D -2; // Diagnosed: from =E2=80=98-2=E2=80=99 to =E2=80=980=E2=80=99 s.a =3D -1; // valid s.a =3D 0; // valid s.a =3D 1; // MISSING diagnostic for 1 -> -1 s.a =3D 2; // Diagnosed: from =E2=80=982=E2=80=99 to =E2=80=980=E2=80=99 s.a =3D 3; // Diagnosed: from =E2=80=983=E2=80=99 to =E2=80=98-1=E2=80=99 s.b =3D -3; // Diagnosed: from =E2=80=98-3=E2=80=99 to =E2=80=981=E2=80=99 s.b =3D -2; // valid s.b =3D -1; // valid s.b =3D 0; // valid s.b =3D 1; // valid s.b =3D 2; // MISSING diagnostic for 2 -> -2 s.b =3D 3; // MISSING diagnostic for 3 -> -1 s.b =3D 4; // Diagnosed: from =E2=80=984=E2=80=99 to =E2=80=980=E2=80=99 } void my_unsigned() { struct { unsigned a:1, b:2; } u; u.a =3D -3; // Diagnosed: from =E2=80=98-3=E2=80=99 to =E2=80=981=E2=80=99 u.a =3D -2; // Diagnosed: from =E2=80=98-2=E2=80=99 to =E2=80=980=E2=80=99 u.a =3D -1; // MISSING diagnostic for -1 -> 1 u.a =3D 0; // valid u.a =3D 1; // valid u.a =3D 2; // Diagnosed: from =E2=80=982=E2=80=99 to =E2=80=980=E2=80=99 u.a =3D 3; // Diagnosed: from =E2=80=983=E2=80=99 to =E2=80=981=E2=80=99 u.b =3D -3; // Diagnosed: from =E2=80=98-3=E2=80=99 to =E2=80=981=E2=80=99 u.b =3D -2; // MISSING diagnostic for -2 -> 2 u.b =3D -1; // MISSING diagnostic for -1 -> 3 u.b =3D 0; // valid u.b =3D 1; // valid u.b =3D 2; // valid u.b =3D 3; // valid u.b =3D 4; // Diagnosed: from =E2=80=984=E2=80=99 to =E2=80=980=E2=80=99 }=