The output is different by the optimization. testcase: #include <stdio.h> struct foo { unsigned long long b:33; }; int main() { struct foo x = {2}; printf("%llx\n",(x.b<<32)); return 0; } result: $ gcc bit.c -o bit; ./bit 200000000 $ gcc -O bit.c -o bit; ./bit 0
Confirmed. We are wrongly expanding ;; D.2027 = D.2026 << 32 (insn 18 17 0 (parallel [ (set (reg:DI 59 [ D.2027 ]) (ashift:DI (reg:DI 60 [ D.2026 ]) (const_int 32 [0x20]))) (clobber (reg:CC 17 flags)) ]) -1 (nil) (nil)) without properly truncating the result to 33 bit precision. Not a regression.
Very similar (apart from typeof) to PR30332.
Uh, all is broken ;) 1) we don't reduce shift or rotate results 2) we do wrong folding of rotates 3) we do wrong expansion of rotates struct foo { unsigned long long b:40; } x; extern void abort (void); void test1(unsigned long long res) { /* Build a rotate expression on a 40 bit argument. */ if ((x.b<<8) + (x.b>>32) != res) abort (); } int main() { x.b = 0x0100000001; test1(0x0000000101); x.b = 0x0100000000; test1(0x0000000001); return 0; }
I split off the rotate issues to PR34971.
Subject: Bug 32244 Author: rguenth Date: Fri Jan 25 15:33:09 2008 New Revision: 131828 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131828 Log: 2008-01-25 Richard Guenther <rguenther@suse.de> PR middle-end/32244 * expr.c (expand_expr_real_1): Reduce result of LSHIFT_EXPR to its bitfield precision if required. * gcc.c-torture/execute/pr32244-1.c: New testcase. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr32244-1.c Modified: trunk/gcc/ChangeLog trunk/gcc/expr.c trunk/gcc/testsuite/ChangeLog
Fixed.