From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5C0713858D39; Tue, 26 Oct 2021 16:45:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C0713858D39 From: "segher at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/102440] Uinteger Opt/Param but the underlying type is signed Date: Tue, 26 Oct 2021 16:45:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: internal-improvement X-Bugzilla-Severity: enhancement X-Bugzilla-Who: segher at gcc dot gnu.org X-Bugzilla-Status: NEW 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: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Oct 2021 16:45:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102440 --- Comment #9 from Segher Boessenkool --- (In reply to Martin Li=C5=A1ka from comment #8) > > We could make the "UInteger" type mean it is implemented with an "unsig= ned > > int" > > C type (or some other unsigned integer type). >=20 > This would lead to the following list of -Wsign-compare warnings: >=20 > /home/marxin/Programming/gcc/gcc/c-family/c-opts.c:934:27: warning: > comparison of integer expressions of different signedness: =E2=80=98unsig= ned int=E2=80=99 > and =E2=80=98int=E2=80=99 [-Wsign-compare] That line is if (warn_shift_overflow =3D=3D -1) The documentation for that warning flag says '-Wsign-compare' Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. In C++, this warning is also enabled by '-Wall'. In C, it is also enabled by '-Wextra'. I don't see how this could produce an incorrect result. Writing the code as if (warn_shift_overflow =3D=3D -1U) means exactly the same thing, except it assumes the size of the variable so it is a bad habit. Plain "-1" is easier to read anyway. It is idiom to use -1 for all-bits-set for unsigned vars. It works correct= ly whatever the size of the variable is. It is silly if if (warn_shift_overflow =3D=3D -1) warns, but if (warn_shift_overflow + 1 =3D=3D 0) is just dandy (and that is the current situation :-( ) > One would need to verify/adjust all these places (plus many more for other > targets). Or fix the bloody warning ;-) But not something you want on your plate, I fully understand :-)=