This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c/10040: Incorrect warning message for bit fields
- From: peterson at austin dot ibm dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 12 Mar 2003 16:21:42 -0000
- Subject: c/10040: Incorrect warning message for bit fields
- Reply-to: peterson at austin dot ibm dot com
>Number: 10040
>Category: c
>Synopsis: Incorrect warning message for bit fields
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Wed Mar 12 16:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: James Peterson, IBM Austin Research Lab
>Release: 3.2.2
>Organization:
>Environment:
RedHat Linux 7.1 on AMD Athlon
>Description:
warning: comparison is always 0 due to width of bit-field
message is generated because a 1 bit field is tested against
one:
int _v: 1;
if ((*tlb)._hi._v == 1)
This message comes from around line 3132 in fold-const.c
where a comment says "the constant shifted right by the
field length should be all zero", and then proceeds to
create trees for (1 >> (lbitsize-1)) and see if the result
is zero (or all ones). But lbitsize is 1, so lbitsize-1
is zero and this quantity is then (1 >> 0) which is still
1, and hence non-zero (but is all one's to the size of the
bit field, so maybe the problem is integer_all_onesp).
This code is followed by explicit code dealing with
"single-bit compares".
In trying to explain the problem, I'm beginning to see
that this error message is a result of the bit field
being an "int" (signed) rather than "unsigned int".
In which case, maybe the problem is best addressed by
a different warning message -- "bit field too small for
value and sign bit; consider unsigned type for field"
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: