Bug 2511 - -pedantic not warning about bitfield overflow
Summary: -pedantic not warning about bitfield overflow
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.1
: P3 enhancement
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2001-04-08 18:56 UTC by Dan Nicolaescu
Modified: 2004-07-08 08:59 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-04-15 05:09:11


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Nicolaescu 2001-04-08 18:56:00 UTC
gcc -pedantic does not warn about bitfield overflow.
For example:

struct test
{
  signed int a:16;
  signed int b:8;
  int pad:8;
};

struct test c = {32768, 256, 0};

signed short int d = 32768;
signed char  e = 256;

compile with gcc -pedantic 
and it will warn aboud d and e: 

t.c:10: warning: overflow in implicit constant conversion
t.c:11: warning: overflow in implicit constant conversion

but nothing about the initialization of struct test c;
IMHO it should warn about those too.

Release:
gcc version 3.1 20010314 (experimental)

Environment:
i386-pc-linux-gnu

How-To-Repeat:
compile the example with gcc -pedantic and see that there are no 
warnings generated for struc test c

Unformatted:
 but present in all releases
Comment 1 Neil Booth 2002-01-29 09:24:51 UTC
Responsible-Changed-From-To: unassigned->neil
Responsible-Changed-Why: Mine.
Comment 2 Neil Booth 2002-01-29 09:24:51 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Fixed for 3.1 with
    
    http://gcc.gnu.org/ml/gcc-cvs/2002-01/msg00876.html
Comment 3 Neil Booth 2002-02-01 20:56:47 UTC
State-Changed-From-To: closed->analyzed
State-Changed-Why: Patch haad to be reverted.  Might be fixed before 3.1, otherwise 3.2.
Comment 4 Andrew Pinski 2003-06-02 00:22:44 UTC
Still does not warn on the mainline (20030601):
tin:~/src/gnu/gcctest>gcc -pedantic pr2511.c -c
pr2511.c:12: warning: overflow in implicit constant conversion
pr2511.c:13: warning: overflow in implicit constant conversion
/tmp/ccr2U7Ho.s: Assembler messages:
/tmp/ccr2U7Ho.s:9: Warning: value 0x100 truncated to 0x0
Comment 5 CVS Commits 2004-07-08 08:44:36 UTC
Subject: Bug 2511

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2004-07-08 08:44:24

Modified files:
	gcc            : c-common.c c-decl.c c-lang.c expr.c 
	                 langhooks-def.h langhooks.h tree-ssa.c tree.c 
	                 tree.h 
	gcc/objc       : objc-act.c objc-lang.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg: bitfld-2.c 
Added files:
	gcc/testsuite/gcc.c-torture/execute: bitfld-3.c 
Removed files:
	gcc/testsuite/gcc.c-torture/execute: bitfld-1.x 

Log message:
	2004-07-08  Joseph S. Myers  <jsm@polyomino.org.uk>
	Neil Booth  <neil@daikokuya.co.uk>
	
	PR c/2511
	PR c/3325
	* c-decl.c (finish_struct): Ensure bit-fields are given the
	correct type.
	* c-common.c (c_common_signed_or_unsigned_type): For C, require
	the precision to match as well as the mode.
	* expr.c (reduce_to_bit_field_precision): New function.
	(expand_expr_real_1): Reduce expressions of bit-field type to
	proper precision.
	* langhooks.h (reduce_bit_field_operations): New hook.
	* langhooks-def.h (LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS):
	Define.
	* c-lang.c, objc/objc-lang.c
	(LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS): Define.
	* objc/objc-act.c (check_ivars): Convert types to bit-field types
	before checking.
	* tree.c (build_nonstandard_integer_type): New function.
	* tree.h (build_nonstandard_integer_type): New prototype.
	* tree-ssa.c (tree_ssa_useless_type_conversion_1): Don't treat
	conversions between integer and boolean types as useless.
	
	testsuite:
	* gcc.c-torture/execute/bitfld-1.x: Remove.
	* gcc.c-torture/execute/bitfld-3.c: New test.
	* gcc.dg/bitfld-2.c: Remove XFAILs.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&r1=1.527&r2=1.528
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.528&r2=1.529
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-lang.c.diff?cvsroot=gcc&r1=1.129&r2=1.130
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expr.c.diff?cvsroot=gcc&r1=1.673&r2=1.674
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/langhooks-def.h.diff?cvsroot=gcc&r1=1.83&r2=1.84
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/langhooks.h.diff?cvsroot=gcc&r1=1.89&r2=1.90
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa.c.diff?cvsroot=gcc&r1=2.19&r2=2.20
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.c.diff?cvsroot=gcc&r1=1.391&r2=1.392
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.h.diff?cvsroot=gcc&r1=1.546&r2=1.547
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/objc/objc-act.c.diff?cvsroot=gcc&r1=1.229&r2=1.230
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/objc/objc-lang.c.diff?cvsroot=gcc&r1=1.47&r2=1.48
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3950&r2=1.3951
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/bitfld-3.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/bitfld-1.x.diff?cvsroot=gcc&r1=1.1&r2=NONE
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/bitfld-2.c.diff?cvsroot=gcc&r1=1.2&r2=1.3

Comment 6 CVS Commits 2004-07-08 08:46:03 UTC
Subject: Bug 2511

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jsm28@gcc.gnu.org	2004-07-08 08:45:55

Modified files:
	gcc            : ChangeLog 

Log message:
	2004-07-08  Joseph S. Myers  <jsm@polyomino.org.uk>
	Neil Booth  <neil@daikokuya.co.uk>
	
	PR c/2511
	PR c/3325
	* c-decl.c (finish_struct): Ensure bit-fields are given the
	correct type.
	* c-common.c (c_common_signed_or_unsigned_type): For C, require
	the precision to match as well as the mode.
	* expr.c (reduce_to_bit_field_precision): New function.
	(expand_expr_real_1): Reduce expressions of bit-field type to
	proper precision.
	* langhooks.h (reduce_bit_field_operations): New hook.
	* langhooks-def.h (LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS):
	Define.
	* c-lang.c, objc/objc-lang.c
	(LANG_HOOKS_REDUCE_BIT_FIELD_OPERATIONS): Define.
	* objc/objc-act.c (check_ivars): Convert types to bit-field types
	before checking.
	* tree.c (build_nonstandard_integer_type): New function.
	* tree.h (build_nonstandard_integer_type): New prototype.
	* tree-ssa.c (tree_ssa_useless_type_conversion_1): Don't treat
	conversions between integer and boolean types as useless.
	
	testsuite:
	* gcc.c-torture/execute/bitfld-1.x: Remove.
	* gcc.c-torture/execute/bitfld-3.c: New test.
	* gcc.dg/bitfld-2.c: Remove XFAILs.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.4372&r2=2.4373

Comment 7 Andrew Pinski 2004-07-08 08:59:26 UTC
Fixed.