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
* [Bug c/102245] false int-in-bool-context warning with shift
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 ` pinskia at gcc dot gnu.org
2021-09-08 21:52 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-08 21:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I should mention this was reduced from drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c in
the Linux kernel compiling for arm-linux-gnueabi but can reproduce the warning
on x86_64 with -m32 option.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] false int-in-bool-context warning with shift
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
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-08 21:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So this is a regression only on the trunk.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
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 ` pinskia at gcc dot gnu.org
2021-09-08 22:14 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-08 21:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
Summary|false int-in-bool-context |[12 Regression] false
|warning with shift |int-in-bool-context warning
| |with shift
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
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
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-08 22:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-09-08
Status|UNCONFIRMED |NEW
CC| |jakub at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r12-3073-g1d244020246cb155e4de62ca3b302b920a1f513f
Deobfuscated testcase:
int
foo (_Bool x)
{
int v = 0;
return (v & ~1L) | (1L & (x << 0));
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
` (3 preceding siblings ...)
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
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-08 22:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, seems the binary context is result of shorten_binary_op, we see the
1L and (((int)x) << 0) operands of BIT_AND_EXPR, result_type is therefore long
int and shorten_binary_op uses convert to convert that (((int)x) << 0) to long
int and triggers the match.pd rule and folds it into (long int)x (where x has
_Bool type).
shorten_binary_op then decides to return _Bool type, which is why we have the
bool context.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
` (4 preceding siblings ...)
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
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-09 7:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think the warning should work on unfolded (un-narrowed) trees or
shorten_binary_op should from a INTEGER_TYPEd operation not create a
BOOLEAN_TYPEd one (but maybe simply build a unsigned int:1 for it)?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
` (5 preceding siblings ...)
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
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-09 9:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a testcase which will hit the warning on all targets and not just ILP32
specific ones:
int
foo (_Bool x)
{
int v = 0;
return (v & ~1u) | (1u & (x << 0));
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
` (6 preceding siblings ...)
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
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: roger at nextmovesoftware dot com @ 2021-09-13 10:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |roger at nextmovesoftware dot com
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |roger at nextmovesoftware dot com
--- Comment #7 from Roger Sayle <roger at nextmovesoftware dot com> ---
Patch proposed:
https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579293.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
` (7 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: roger at nextmovesoftware dot com @ 2021-09-14 7:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
--- Comment #8 from Roger Sayle <roger at nextmovesoftware dot com> ---
Alternate patch proposed:
https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579378.html
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
` (8 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-17 14:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:
https://gcc.gnu.org/g:2578a3870ef849dc77e98796600181b64ae4fd61
commit r12-3623-g2578a3870ef849dc77e98796600181b64ae4fd61
Author: Roger Sayle <roger@nextmovesoftware.com>
Date: Fri Sep 17 15:57:34 2021 +0100
PR c/102245: Disable sign-changing optimization for shifts by zero.
Respecting Jakub's suggestion that it may be better to warn-on-valid for
"if (x << 0)" as the author might have intended "if (x < 0)" [which will
also warn when x is _Bool], the simplest way to resolve this regression
is to disable the recently added fold transformation for shifts by zero;
these will be optimized later (elsewhere). Guarding against integer_zerop
is the simplest of three alternatives; the second being to only apply
this transformation to GIMPLE and not GENERIC, and the third (potentially)
being to explicitly handle shifts by zero here, with an (if cond then
else),
optimizing the expression to a convert, but awkwardly duplicating a
more general transformation earlier in match.pd's shift simplifications.
2021-09-17 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR c/102245
* match.pd (shift optimizations): Disable recent sign-changing
optimization for shifts by zero, these will be folded later.
gcc/testsuite/ChangeLog
PR c/102245
* gcc.dg/Wint-in-bool-context-4.c: New test case.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/102245] [12 Regression] false int-in-bool-context warning with shift
2021-09-08 21:36 [Bug c/102245] New: false int-in-bool-context warning with shift pinskia at gcc dot gnu.org
` (9 preceding siblings ...)
2021-09-17 14:58 ` cvs-commit at gcc dot gnu.org
@ 2021-09-18 9:11 ` roger at nextmovesoftware dot com
10 siblings, 0 replies; 12+ messages in thread
From: roger at nextmovesoftware dot com @ 2021-09-18 9:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102245
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #10 from Roger Sayle <roger at nextmovesoftware dot com> ---
Fixed on mainline.
^ 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).