modulo operator with bitfields and signed / unsigned fails same operation with variables succeeds Release: gcc-3.0 Environment: sun-sparc-solaris2.8 How-To-Repeat: gcc bug3.c && ./a.out
Responsible-Changed-From-To: unassigned->neil Responsible-Changed-Why: I fixed it.
State-Changed-From-To: open->closed State-Changed-Why: Fixed for 3.1.
From: neil@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c/3325 Date: 29 Jan 2002 17:19:59 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: neil@gcc.gnu.org 2002-01-29 09:19:58 Modified files: gcc : ChangeLog c-decl.c tree.c tree.h gcc/objc : objc-act.c gcc/testsuite/gcc.dg: uninit-A.c gcc/testsuite/gcc.c-torture/compile: 20000224-1.c Added files: gcc/testsuite/gcc.dg: bitfld-1.c bitfld-2.c gcc/testsuite/gcc.c-torture/execute: bitfld-1.c Log message: PR c/3325 * c-decl.c (enum_decl_context): Remove BITFIELD. (grokdeclarator): Take bitfield width as an input. Ensure bitfields are given the correct type. Perform bitfield width validation with build_bitfield_integer_type rather than waiting for finish_struct. (grok_typename, grok_typename_in_parm_context, start_decl, push_parmdecl, grokfield, start_function): Update calls to grokdeclarator. (build_bitfield_integer_type): New function. (finish_struct): Move bitfield validation to grokdeclarator and build_bitfield_integer_type. * tree.c (build_nonstandard_integer_type): New function. * tree.h (build_nonstandard_integer_type): New prototype. objc: * objc-act.c (objc_copy_list): Remove DECL_INITIAL kludge. testsuite: * gcc.c-torture/compile/20000224-1.c: Update. * gcc.c-torture/execute/bitfld-1.c: New tests. * gcc.dg/bitfld-1.c, bitfld-2.c: Diagnostic tests. * gcc.dg/uninit-A.c: Update. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.12866&r2=1.12867 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.290&r2=1.291 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.c.diff?cvsroot=gcc&r1=1.233&r2=1.234 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.h.diff?cvsroot=gcc&r1=1.300&r2=1.301 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/objc/objc-act.c.diff?cvsroot=gcc&r1=1.123&r2=1.124 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/bitfld-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/bitfld-2.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/uninit-A.c.diff?cvsroot=gcc&r1=1.2&r2=1.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/bitfld-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/20000224-1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
State-Changed-From-To: closed->analyzed State-Changed-Why: Patch haad to be reverted. Might be fixed before 3.1, otherwise 3.2.
*** Bug 3326 has been marked as a duplicate of this bug. ***
note that this also happens with division operator (e.g. bug 3326)
*** Bug 6346 has been marked as a duplicate of this bug. ***
*** Bug 6515 has been marked as a duplicate of this bug. ***
*** Bug 7696 has been marked as a duplicate of this bug. ***
*** Bug 9620 has been marked as a duplicate of this bug. ***
Neil, any hope of getting this one into 3.4? I don't know why the patch was reverted, so I'm not sure how fundamental the issues were...
Can this be fixed in 3.4?
Subject: Re: cast of bit-field to same type gets discarded On Wed, 21 Jan 2004, schwab at suse dot de wrote: > Can this be fixed in 3.4? I very much doubt a patch for it could fail to be too destabilising for a release branch; in any case, this isn't a regression. I attempted a resurrection of the patch and found it needed changes to expand_expr <http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00651.html> (though no experts thereon commented on the proper approach); I didn't get a patch to expand_expr as far as passing both bootstrap/regression tests and all of the tests below. I didn't get as far as looking at the debug info problems with the original patch (the ABI issues were, however, fixed, by using the declared type when layout was done and adjusting the type to the bit-field type later). Note: I don't suppose the original patch passed all the tests below either, given the need for middle-end support for the bit-field types. But presumably it didn't fail the existing regression tests which showed up the need for middle-end changes, and subsequent C front end changes may have caused this issue to show up now. Note: We should also look again at how bool bit-fields work in the light of the recent dicussion on the WG14 reflector, though I don't think that reached a clear consensus. /* Test that operations on bit-fields yield results reduced to bit-field type. */ /* Origin: Joseph Myers <jsm@polyomino.org.uk> */ extern void exit (int); extern void abort (void); struct s { unsigned long long u33: 33; unsigned long long u40: 40; unsigned long long u41: 41; }; struct s a = { 0x100000, 0x100000, 0x100000 }; struct s b = { 0x100000000ULL, 0x100000000ULL, 0x100000000ULL }; struct s c = { 0x1FFFFFFFFULL, 0, 0 }; int main (void) { if (a.u33 * a.u33 != 0 || a.u33 * a.u40 != 0 || a.u40 * a.u33 != 0 || a.u40 * a.u40 != 0) abort (); if (a.u33 * a.u41 != 0x10000000000ULL || a.u40 * a.u41 != 0x10000000000ULL || a.u41 * a.u33 != 0x10000000000ULL || a.u41 * a.u40 != 0x10000000000ULL || a.u41 * a.u41 != 0x10000000000ULL) abort (); if (b.u33 + b.u33 != 0) abort (); if (b.u33 + b.u40 != 0x200000000ULL || b.u33 + b.u41 != 0x200000000ULL || b.u40 + b.u33 != 0x200000000ULL || b.u40 + b.u40 != 0x200000000ULL || b.u40 + b.u41 != 0x200000000ULL || b.u41 + b.u33 != 0x200000000ULL || b.u41 + b.u40 != 0x200000000ULL || b.u41 + b.u41 != 0x200000000ULL) abort (); if (a.u33 - b.u33 != 0x100100000ULL || a.u33 - b.u40 != 0xFF00100000ULL || a.u33 - b.u41 != 0x1FF00100000ULL || a.u40 - b.u33 != 0xFF00100000ULL || a.u40 - b.u40 != 0xFF00100000ULL || a.u40 - b.u41 != 0x1FF00100000ULL || a.u41 - b.u33 != 0x1FF00100000ULL || a.u41 - b.u40 != 0x1FF00100000ULL || a.u41 - b.u41 != 0x1FF00100000ULL) abort (); if (++c.u33 != 0 || --c.u40 != 0xFFFFFFFFFFULL || c.u41-- != 0) abort (); exit (0); }
*** Bug 14294 has been marked as a duplicate of this bug. ***
*** Bug 16039 has been marked as a duplicate of this bug. ***
Subject: Bug 3325 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
Subject: Bug 3325 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
Fixed.