public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113973] New: Pleas issue a warning when using plain character values in bitwise operations
@ 2024-02-17 15:23 gcc-bugzilla at mkarcher dot dialup.fu-berlin.de
2024-02-19 8:08 ` [Bug c/113973] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: gcc-bugzilla at mkarcher dot dialup.fu-berlin.de @ 2024-02-17 15:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113973
Bug ID: 113973
Summary: Pleas issue a warning when using plain character
values in bitwise operations
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc-bugzilla at mkarcher dot dialup.fu-berlin.de
Target Milestone: ---
This example program compiles without any kind of warning in gcc:
static char x = 0xD8;
int main(void)
{
return 0x1200 | x;
}
The value returned from main is 0xFFFFFFD8 on architectures with 32-bit int and
signed characters by default. After just fixing a bug that was caused by an
unexpected sign expansion when building an int from individual bytes, I'd
rather have a warning if
1) A variable of type char is promoted to int.
2) The int value is used in an bitwise expression
3) More than 8 bits of the results are actually used
4) More than 8 bits may be non-zero
Because of condition 3, this will yiels no warning on "char y = x | 0x40;" (top
bits truncated, so condition 3 fails) and no warning on "int y = x & 0x40;"
(all high bits are guaranteed to be zero, so condition 4 fails).
The real-world bug that motivates this enhancement proposal is
https://github.com/hfst/hfst-ospell/issues/43
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/113973] Pleas issue a warning when using plain character values in bitwise operations
2024-02-17 15:23 [Bug c/113973] New: Pleas issue a warning when using plain character values in bitwise operations gcc-bugzilla at mkarcher dot dialup.fu-berlin.de
@ 2024-02-19 8:08 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-02-19 8:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113973
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-02-19
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed, this looks useful (but for arithmetic as well, not just bitwise
ops).
static char x = 0xD8;
int main(void)
{
return 0x1200 + x;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-19 8:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-17 15:23 [Bug c/113973] New: Pleas issue a warning when using plain character values in bitwise operations gcc-bugzilla at mkarcher dot dialup.fu-berlin.de
2024-02-19 8:08 ` [Bug c/113973] " rguenth at gcc dot gnu.org
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).