[Bug c++/38522] -Wconversion does not handle complex bitwise expressions
manu at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sun Mar 8 03:54:00 GMT 2009
------- Comment #7 from manu at gcc dot gnu dot org 2009-03-08 03:54 -------
(In reply to comment #5)
> BTW, my comment was about the C++ frontend. IE:
> .../gcc44/bin/g++ -c -Wall -W -Wconversion test.cpp
The code of Wconversion is shared between C and C++ front-ends, so they should
produce the same output. I get:
warning: conversion to âÂÂunsigned charâ from âÂÂunsigned intâ may alter
its value
My guess is that the code in conversion_warning is not able to handle an
expression so complex as:
<bit_ior_expr 0x2aaaab65f700
type <integer_type 0x2aaaab4fc600 unsigned int public unsigned SI
size <integer_cst 0x2aaaab4e8a20 constant 32>
unit size <integer_cst 0x2aaaab4e8690 constant 4>
align 32 symtab 0 alias set -1 canonical type 0x2aaaab4fc600 precision
32 min <integer_cst 0x2aaaab4e8a50 0> max <integer_cst 0x2aaaab4e89f0
4294967295>>
arg 0 <bit_and_expr 0x2aaaab65f540 type <integer_type 0x2aaaab4fc600
unsigned int>
arg 0 <nop_expr 0x2aaaab65f500 type <integer_type 0x2aaaab4fc600
unsigned int>
arg 0 <parm_decl 0x2aaaab4f1b40 a1>>
arg 1 <integer_cst 0x2aaaab665480 constant 192>>
arg 1 <bit_and_expr 0x2aaaab65f6c0 type <integer_type 0x2aaaab4fc600
unsigned int>
arg 0 <nop_expr 0x2aaaab65f680 type <integer_type 0x2aaaab4fc600
unsigned int>
arg 0 <parm_decl 0x2aaaab4f1bd0 a2>>
arg 1 <integer_cst 0x2aaaab6654b0 constant 32>>>
The approach using get_unwidened and shorten_binary_op only works for really
simple expressions. It needs to be more powerful to handle complex expressions.
Alternatively, the expression should be simplified before reaching
conversion_warning. In fact, by the time we reach GIMPLE we have:
[pr38522.C : 8] D.2074 = a1 & 192;
[pr38522.C : 8] D.2075 = a2 & 32;
[pr38522.C : 8] local = D.2074 | D.2075;
which can be handled by current Wconversion perfectly.
I don't have time to work on this, so anyone feel free to take it.
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-03-08 03:54:27
date| |
Summary|g++ -Wconversion warnings |-Wconversion does not handle
| |complex bitwise expressions
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38522
More information about the Gcc-bugs
mailing list