public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17170] New: -Wdefault-bitfield-sign
@ 2004-08-24 15:50 terra at gnome dot org
  2004-08-24 16:00 ` [Bug c/17170] -Wdefault-bitfield-sign pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: terra at gnome dot org @ 2004-08-24 15:50 UTC (permalink / raw)
  To: gcc-bugs

I would like to see -Wdefault-bitfield-sign turn on warnings when bitfields
are declared in ways that are likely bugs:

struct oink {
  int foo : 5;        // warning: the signedness of foo is implementation defined
  signed int bar : 5; // no warning
  int : 5;            // no warning (since no name)
  int booze : 1;      // warning: dubious signed one-bit bitfield
  signed int baz : 1; // no warning.
};

(A signed bitfield on width one can contain {-1;0} or {0} depending on integer
representation.  The latter allows for impressive optimizations, but surely
someone meant to use unsigned.)

Adding "signed" or "unsigned" as shown would silence the warnings.  Further,
I would assume that foo's warning above would be silenced by the use of one
of

`-fsigned-bitfields'
`-funsigned-bitfields'
`-fno-signed-bitfields'
`-fno-unsigned-bitfields'

booze's warning should remain, though.

-- 
           Summary: -Wdefault-bitfield-sign
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: terra at gnome dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
@ 2004-08-24 16:00 ` pinskia at gcc dot gnu dot org
  2004-08-31  5:27 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-24 16:00 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 575 bytes --]


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-24 16:00 -------
http://gcc.gnu.org/onlinedocs/gcc/Structures-unions-enumerations-and-bit_002dfields-
implementation.html#Structures-unions-enumerations-and-bit_002dfields-implementation

"Whether a “plain” int bit-field is treated as a signed int bit-field or as an unsigned int bit-field (C90 
6.5.2, C90 6.5.2.1, C99 6.7.2, C99 6.7.2.1).
By default it is treated as signed int but this may be changed by the -funsigned-bitfields option."

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
  2004-08-24 16:00 ` [Bug c/17170] -Wdefault-bitfield-sign pinskia at gcc dot gnu dot org
@ 2004-08-31  5:27 ` pinskia at gcc dot gnu dot org
  2004-08-31 13:13 ` terra at gnome dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-31  5:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-31 05:27 -------
Since we define what is "implementation defined" in our documentation, this warning is useless.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
  2004-08-24 16:00 ` [Bug c/17170] -Wdefault-bitfield-sign pinskia at gcc dot gnu dot org
  2004-08-31  5:27 ` pinskia at gcc dot gnu dot org
@ 2004-08-31 13:13 ` terra at gnome dot org
  2004-08-31 15:26 ` jsm at polyomino dot org dot uk
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: terra at gnome dot org @ 2004-08-31 13:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From terra at gnome dot org  2004-08-31 13:13 -------
Not so fast.  That reason is nonsense.

Warnings go where they are likely to discover problems.  This is one such problem
area, notable the signed:1 case.  And the noise from misfires is going to be
minimal.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|WONTFIX                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
                   ` (2 preceding siblings ...)
  2004-08-31 13:13 ` terra at gnome dot org
@ 2004-08-31 15:26 ` jsm at polyomino dot org dot uk
  2004-08-31 15:42 ` terra at gnome dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jsm at polyomino dot org dot uk @ 2004-08-31 15:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm at polyomino dot org dot uk  2004-08-31 15:26 -------
Subject: Re:  -Wdefault-bitfield-sign

On Tue, 31 Aug 2004, terra at gnome dot org wrote:

> Warnings go where they are likely to discover problems.  This is one such problem
> area, notable the signed:1 case.  And the noise from misfires is going to be
> minimal.

We do warn for assigning a constant 1 to a signed 1-bit bit-field (in 
3.5).  But this suggested warning does make sense for code portability; 
not all 1-bit fields necessarily get constant 1 assigned to them.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
                   ` (3 preceding siblings ...)
  2004-08-31 15:26 ` jsm at polyomino dot org dot uk
@ 2004-08-31 15:42 ` terra at gnome dot org
  2004-08-31 15:50 ` jsm at polyomino dot org dot uk
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: terra at gnome dot org @ 2004-08-31 15:42 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From terra at gnome dot org  2004-08-31 15:42 -------
I did a crude grep-scan on a 2.4.x linux kernel and found ~50 1-bit bitfields
that were signed by default.  A previous scan on parts of Gnome revealed a
similar number.  In other words, that kind of code is quite common.

Virtually all of these were being used as booleans, i.e., the programmer really
intended a field that could take the values 0 and 1.  Now on a two-complement
machine the field ended up holding 0 or -1 so depending on how the values read
were actually used, things might have worked.  Or not.  Hence the need for a
warning.

I cannot think of a case where one would want a signed one-bit bitfield, but
adding the explicit "signed" would make it clear that the programmer thought
about it.

(In C99 one would use a _Bool fields, but it'll be a few years before everyone
will have compilers that handle that right.)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
                   ` (4 preceding siblings ...)
  2004-08-31 15:42 ` terra at gnome dot org
@ 2004-08-31 15:50 ` jsm at polyomino dot org dot uk
  2004-08-31 16:12 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jsm at polyomino dot org dot uk @ 2004-08-31 15:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm at polyomino dot org dot uk  2004-08-31 15:50 -------
Subject: Re:  -Wdefault-bitfield-sign

On Tue, 31 Aug 2004, terra at gnome dot org wrote:

> I did a crude grep-scan on a 2.4.x linux kernel and found ~50 1-bit bitfields
> that were signed by default.  A previous scan on parts of Gnome revealed a
> similar number.  In other words, that kind of code is quite common.

There were quite a few in GCC.  I got rid of them as preliminary to 
getting in the bit-field patch that gave them their proper 1-bit signed 
type and so caused assignments of 1 to such bit-fields to give a warning 
of overflow in the implicit conversion.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
                   ` (5 preceding siblings ...)
  2004-08-31 15:50 ` jsm at polyomino dot org dot uk
@ 2004-08-31 16:12 ` pinskia at gcc dot gnu dot org
  2004-08-31 16:15 ` jsm at polyomino dot org dot uk
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-31 16:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-31 16:12 -------
Again there is no reason to warn about the signness if we already document about it as required by the 
C standard :)

Also since we do warn about :1 were all the problems are, I am going to close this.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
                   ` (6 preceding siblings ...)
  2004-08-31 16:12 ` pinskia at gcc dot gnu dot org
@ 2004-08-31 16:15 ` jsm at polyomino dot org dot uk
  2004-08-31 16:21 ` bangerth at dealii dot org
  2004-11-30  0:48 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jsm at polyomino dot org dot uk @ 2004-08-31 16:15 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm at polyomino dot org dot uk  2004-08-31 16:15 -------
Subject: Re:  -Wdefault-bitfield-sign

On Tue, 31 Aug 2004, pinskia at gcc dot gnu dot org wrote:

> Again there is no reason to warn about the signness if we already 
> document about it as required by the C standard :)

The point of the proposed warning is to warn about *portability* issues - 
we document what GCC does but people want to know about issues that may 
arise when porting to other systems and compilers.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
                   ` (7 preceding siblings ...)
  2004-08-31 16:15 ` jsm at polyomino dot org dot uk
@ 2004-08-31 16:21 ` bangerth at dealii dot org
  2004-11-30  0:48 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-08-31 16:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-31 16:21 -------
Andrew, please respect other maintainers' wishes to keep PRs open. It is 
rude to close a PR despite the fact that Joseph thinks the request is 
valid. I, too, find that a warning would be useful. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c/17170] -Wdefault-bitfield-sign
  2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
                   ` (8 preceding siblings ...)
  2004-08-31 16:21 ` bangerth at dealii dot org
@ 2004-11-30  0:48 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-30  0:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-30 00:48 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2004-11-30 00:48:28
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17170


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-11-30  0:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-24 15:50 [Bug c/17170] New: -Wdefault-bitfield-sign terra at gnome dot org
2004-08-24 16:00 ` [Bug c/17170] -Wdefault-bitfield-sign pinskia at gcc dot gnu dot org
2004-08-31  5:27 ` pinskia at gcc dot gnu dot org
2004-08-31 13:13 ` terra at gnome dot org
2004-08-31 15:26 ` jsm at polyomino dot org dot uk
2004-08-31 15:42 ` terra at gnome dot org
2004-08-31 15:50 ` jsm at polyomino dot org dot uk
2004-08-31 16:12 ` pinskia at gcc dot gnu dot org
2004-08-31 16:15 ` jsm at polyomino dot org dot uk
2004-08-31 16:21 ` bangerth at dealii dot org
2004-11-30  0:48 ` pinskia at gcc dot gnu dot 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).