https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
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 = 0; tmp = 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=int-in-bool-context" and you get: <source>: In function 'f': <source>:10:53: error: '<<' in boolean context, did you mean '<'? [-Werror=int-in-bool-context] 10 | (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:17:9: note: in expansion of macro 'REG_SET_FIELD' 17 | tmp = 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.