diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-01-11 19:11:51 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-01-11 19:11:51 +0100 |
commit | 20e4a5e573e76f4379b353cc736215a5f10cdb84 (patch) | |
tree | 5be1205aa8335ac1918920a00c4ec85587f2838e /COPYING | |
parent | 0378f563b0321c44c4a9c98cf46d2a22b9160f76 (diff) | |
download | gcc-20e4a5e573e76f4379b353cc736215a5f10cdb84.zip gcc-20e4a5e573e76f4379b353cc736215a5f10cdb84.tar.gz gcc-20e4a5e573e76f4379b353cc736215a5f10cdb84.tar.bz2 |
c-family: Fix up -W*conversion on bitwise &/|/^ [PR101537]
The following testcases emit a bogus -Wconversion warning. This is because
conversion_warning function doesn't handle BIT_*_EXPR (only unsafe_conversion_p
that is called during the default: case, and that one doesn't handle
SAVE_EXPRs added because the unsigned char & or | operands promoted to int
have side-effects and =| or =& is used.
The patch handles BIT_IOR_EXPR/BIT_XOR_EXPR like the last 2 operands of
COND_EXPR by recursing on the two operands, if either of them doesn't fit
into the narrower type, complain. BIT_AND_EXPR too, but first it needs to
handle some special cases that unsafe_conversion_p does, namely when one
of the two operands is a constant.
This fixes completely the pr101537.c test and for C also pr103881.c
and doesn't regress anything in the testsuite, for C++ pr103881.c still
emits the bogus warnings.
This is because while the C FE emits in that case a SAVE_EXPR that
conversion_warning can handle already, C++ FE emits
TARGET_EXPR <D.whatever, ...>, something | D.whatever
etc. and conversion_warning handles COMPOUND_EXPR by "recursing" on the
rhs. To handle that case, we'd need for TARGET_EXPR on the lhs remember
in some hash map the mapping from D.whatever to the TARGET_EXPR and when
we see D.whatever, use corresponding TARGET_EXPR initializer instead.
2022-01-11 Jakub Jelinek <jakub@redhat.com>
PR c/101537
PR c/103881
gcc/c-family/
* c-warn.c (conversion_warning): Handle BIT_AND_EXPR, BIT_IOR_EXPR
and BIT_XOR_EXPR.
gcc/testsuite/
* c-c++-common/pr101537.c: New test.
* c-c++-common/pr103881.c: New test.
Diffstat (limited to 'COPYING')
0 files changed, 0 insertions, 0 deletions