diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b9e35dc6666..a99d0c88c3b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2007-04-22 Andrew Pinski + + PR middle-end/31448 + * expr.c (reduce_to_bit_field_precision): Handle + CONST_INT rtx's. + 2007-04-22 Uros Bizjak PR tree-optimization/24659 diff --git a/gcc/expr.c b/gcc/expr.c index c644933c0ba..e239f4c69b5 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -8962,7 +8962,14 @@ reduce_to_bit_field_precision (rtx exp, rtx target, tree type) HOST_WIDE_INT prec = TYPE_PRECISION (type); if (target && GET_MODE (target) != GET_MODE (exp)) target = 0; - if (TYPE_UNSIGNED (type)) + /* For constant values, reduce using build_int_cst_type. */ + if (GET_CODE (exp) == CONST_INT) + { + HOST_WIDE_INT value = INTVAL (exp); + tree t = build_int_cst_type (type, value); + return expand_expr (t, target, VOIDmode, EXPAND_NORMAL); + } + else if (TYPE_UNSIGNED (type)) { rtx mask; if (prec < HOST_BITS_PER_WIDE_INT) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 571c5d9dae4..2546590cb79 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-04-22 Andrew Pinski + + PR middle-end/31448 + * gcc.c-torture/execute/pr31448.c: New testcase. + 2007-04-22 Nick Clifton * gcc.dg/20020312-2.c: Add support for the FRV. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr31448.c b/gcc/testsuite/gcc.c-torture/execute/pr31448.c new file mode 100644 index 00000000000..720ba926eaa --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr31448.c @@ -0,0 +1,36 @@ +/* PR middle-end/31448, this used to ICE during expand because + reduce_to_bit_field_precision was not ready to handle constants. */ + +typedef struct _st { + int iIndex : 24; + int iIndex1 : 24; +} st; +st *next; +void g(void) +{ + st *next = 0; + int nIndx; + const static int constreg[] = { 0,}; + nIndx = 0; + next->iIndex = constreg[nIndx]; +} +void f(void) +{ + int nIndx; + const static int constreg[] = { 0xFEFEFEFE,}; + nIndx = 0; + next->iIndex = constreg[nIndx]; + next->iIndex1 = constreg[nIndx]; +} +int main(void) +{ + st a; + next = &a; + f(); + if (next->iIndex != 0xFFFEFEFE) + __builtin_abort (); + if (next->iIndex1 != 0xFFFEFEFE) + __builtin_abort (); + return 0; +} +