From e002c7cbaff40445b05da1d5213cb8a08422fb9e Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Mon, 18 Jul 2011 13:39:28 +0000 Subject: [PATCH] expr.c (expand_expr_real_2): Properly truncate the BIT_NOT_EXPR expansion result to bitfield precision if... 2011-07-18 Richard Guenther * expr.c (expand_expr_real_2): Properly truncate the BIT_NOT_EXPR expansion result to bitfield precision if required. * gcc.dg/torture/20110718-1.c: New testcase. From-SVN: r176398 --- gcc/ChangeLog | 5 +++++ gcc/expr.c | 10 +++++++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/torture/20110718-1.c | 23 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/20110718-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6026f4ac364..5907bf25892 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2011-07-18 Richard Guenther + + * expr.c (expand_expr_real_2): Properly truncate the BIT_NOT_EXPR + expansion result to bitfield precision if required. + 2011-07-18 Rainer Orth * config.gcc (i[3456x]86-*-netware*): Remove. diff --git a/gcc/expr.c b/gcc/expr.c index ee1114218ca..0f2037206d9 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -8037,7 +8037,15 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode, VOIDmode, EXPAND_NORMAL); if (modifier == EXPAND_STACK_PARM) target = 0; - temp = expand_unop (mode, one_cmpl_optab, op0, target, 1); + /* In case we have to reduce the result to bitfield precision + expand this as XOR with a proper constant instead. */ + if (reduce_bit_field) + temp = expand_binop (mode, xor_optab, op0, + immed_double_int_const + (double_int_mask (TYPE_PRECISION (type)), mode), + target, 1, OPTAB_LIB_WIDEN); + else + temp = expand_unop (mode, one_cmpl_optab, op0, target, 1); gcc_assert (temp); return temp; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 65125bd6494..32f59bd279b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-07-18 Richard Guenther + + * gcc.dg/torture/20110718-1.c: New testcase. + 2011-07-18 Rainer Orth * g++.dg/ext/bitfield2.C: Remove i?86-*-netware support. diff --git a/gcc/testsuite/gcc.dg/torture/20110718-1.c b/gcc/testsuite/gcc.dg/torture/20110718-1.c new file mode 100644 index 00000000000..ccabbd91421 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/20110718-1.c @@ -0,0 +1,23 @@ +/* { dg-do run } */ + +extern void abort (void); +struct X { +#if (__SIZEOF_LONG__ != __SIZEOF_INT__) && (__SIZEOF_LONG__ == 8) + unsigned long i : 33; +#else + unsigned long i; +#endif +}; +unsigned long __attribute__((noinline)) +foo (struct X *p) +{ + return ~p->i; +} +int main() +{ + struct X x; + x.i = -1; + if (foo (&x) != 0) + abort (); + return 0; +} -- 2.30.2