diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 03a9e8771d3..3a9d0e1b6a4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2009-01-09 Jakub Jelinek + + PR middle-end/38771 + * fold-const.c (fold_unary): For COMPOUND_EXPR and COND_EXPR, + fold_convert arg0 operands to TREE_TYPE (op0) first. + 2009-01-08 Vladimir Makarov * params.def (ira-max-conflict-table-size): Decrease default value diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 9b4106bd9e0..820ca5a7fe6 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8053,15 +8053,19 @@ fold_unary (enum tree_code code, tree type, tree op0) { if (TREE_CODE (arg0) == COMPOUND_EXPR) return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0), - fold_build1 (code, type, TREE_OPERAND (arg0, 1))); + fold_build1 (code, type, + fold_convert (TREE_TYPE (op0), + TREE_OPERAND (arg0, 1)))); else if (TREE_CODE (arg0) == COND_EXPR) { tree arg01 = TREE_OPERAND (arg0, 1); tree arg02 = TREE_OPERAND (arg0, 2); if (! VOID_TYPE_P (TREE_TYPE (arg01))) - arg01 = fold_build1 (code, type, arg01); + arg01 = fold_build1 (code, type, + fold_convert (TREE_TYPE (op0), arg01)); if (! VOID_TYPE_P (TREE_TYPE (arg02))) - arg02 = fold_build1 (code, type, arg02); + arg02 = fold_build1 (code, type, + fold_convert (TREE_TYPE (op0), arg02)); tem = fold_build3 (COND_EXPR, type, TREE_OPERAND (arg0, 0), arg01, arg02); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2874af0e1d7..199cd6e10b9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-01-09 Jakub Jelinek + + PR middle-end/38771 + * gcc.c-torture/compile/pr38771.c: New test. + 2009-01-08 Nathan Froyd * gcc.dg/pr34856.c: Ignore irrelevant warning. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr38771.c b/gcc/testsuite/gcc.c-torture/compile/pr38771.c new file mode 100644 index 00000000000..7988680dd46 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr38771.c @@ -0,0 +1,7 @@ +/* PR middle-end/38771 */ + +unsigned long long +foo (long long x) +{ + return -(unsigned long long) (x ? : x); +}