From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8D8823857817; Wed, 8 Sep 2021 21:36:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D8823857817 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/102245] New: false int-in-bool-context warning with shift Date: Wed, 08 Sep 2021 21:36:36 +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: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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 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: Wed, 08 Sep 2021 21:36:36 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102245 Bug ID: 102245 Summary: false int-in-bool-context warning with shift Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: #define shiftCB_DISABLE_FAULT_ON_UNMAPPED_ACCESS1 0 #define maskCB_DISABLE_FAULT_ON_UNMAPPED_ACCESS1 1L #define REG_FIELD_MASK(a,b) (mask##b) #define REG_FIELD_SHIFT(a,b) (shift##b) #define REG_SET_FIELD(orig_val, reg, field, field_val) \ (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \ (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) int f(_Bool enable) { int tmp =3D 0; tmp =3D REG_SET_FIELD(tmp, VM_PRT_CNTL, CB_DISABLE_FAULT_ON_UNMAPPED_ACCESS1, enable); return tmp; } ------ CUT ---- Compile this on an ILP32 target with "-W -Wall -O2 -Werror -Werror=3Dint-in-bool-context" and you get: : In function 'f': :10:53: error: '<<' in boolean context, did you mean '<'? [-Werror=3Dint-in-bool-context] 10 | (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :17:9: note: in expansion of macro 'REG_SET_FIELD' 17 | tmp =3D REG_SET_FIELD(tmp, VM_PRT_CNTL, | ^~~~~~~~~~~~~ cc1: all warnings being treated as errors This is not correct as the shift is correct, I want to do a shift by 0 here= and there is no boolean context at all. And it does not warn with LP64 targets either.=