public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102245] New: false  int-in-bool-context warning with shift
@ 2021-09-08 21:36 pinskia at gcc dot gnu.org
  2021-09-08 21:48 ` [Bug c/102245] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-08 21:36 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-09-18  9:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
2021-09-08 21:48 ` [Bug c/102245] " pinskia at gcc dot gnu.org
2021-09-08 21:52 ` pinskia at gcc dot gnu.org
2021-09-08 21:55 ` [Bug c/102245] [12 Regression] " pinskia at gcc dot gnu.org
2021-09-08 22:14 ` jakub at gcc dot gnu.org
2021-09-08 22:38 ` jakub at gcc dot gnu.org
2021-09-09  7:37 ` rguenth at gcc dot gnu.org
2021-09-09  9:57 ` pinskia at gcc dot gnu.org
2021-09-13 10:45 ` roger at nextmovesoftware dot com
2021-09-14  7:56 ` roger at nextmovesoftware dot com
2021-09-17 14:58 ` cvs-commit at gcc dot gnu.org
2021-09-18  9:11 ` roger at nextmovesoftware dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).