From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 138E03858420; Sun, 30 Oct 2022 17:59:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 138E03858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667152767; bh=GbQAzBJLv5n6Fx0JJ2Ubokaa9/0WofwZFQ5AUCoQg2E=; h=From:To:Subject:Date:From; b=Hd4VHjTVTP0SY5BwbDmLRAB3ADkPJA9PeL4NZfDGzm6wcMio42+o49Q1l/Z55Immc 97ItT/LbiuD7KKiKTPanVf4vHmx+uoJfueW545/VTp2LqjM7ASWIHa4Fjn1GLMo23Q 2dDUENw3Xhj+ioAQa2X5SOmdXfwVfKGNLOynDcKA= From: "lavr at ncbi dot nlm.nih.gov" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107465] New: Bogus warning: promoted bitwise complement of an unsigned value is always nonzero Date: Sun, 30 Oct 2022 17:59:24 +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: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lavr at ncbi dot nlm.nih.gov 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 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=3D107465 Bug ID: 107465 Summary: Bogus warning: promoted bitwise complement of an unsigned value is always nonzero Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: lavr at ncbi dot nlm.nih.gov Target Milestone: --- Tried on both Ubuntu and Cygwin, the same gcc-11.3.0 -- and the same proble= m: $ gcc --version gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gcc --version gcc (GCC) 11.3.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. The code: $ cat test.c extern void fun2(void); #ifdef BOGUS_WARNING typedef unsigned short uint2; #else #define uint2 unsigned short #endif static void fun(uint2 x) { if (!(x ^ 0xFFFF)) fun2(); } int main(void) { fun(0); } The compilation: $ gcc -Wall -Wextra -O6 -c test.c (clean) BUT: $ gcc -Wall -Wextra -O6 -c -DBOGUS_WARNING test.c test.c: In function =E2=80=98fun=E2=80=99: test.c:11:9: warning: promoted bitwise complement of an unsigned value is always nonzero [-Wsign-compare] 11 | if (!(x ^ 0xFFFF)) | ^ The variable "x" is an unsigned short, so it gets promoted to int without t= he sign extension; the second argument to XOR is a 32-bit int with only 16 bits set to 1. The result of XOR is not necessarily non-0 because it does not f= lip all the bits in an int, but only the lower 16 (so there's no promotion of a= ny sort, IMO). Also, it's weird that the warning is only issued with a typedef for the type of "x".=