From a0fac73d2b6a463a96c93d8ea37d1c33e605aa93 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Tue, 3 Aug 2004 21:24:32 +0000 Subject: [PATCH] re PR middle-end/16790 (Integer down cast ignored in larger expression) PR middle-end/16790 * fold-const.c (extract_muldiv_1) : Disallow local truncations, not just global truncations. * gcc.c-torture/execute/pr16790-1.c: New test case. From-SVN: r85506 --- gcc/ChangeLog | 6 +++ gcc/fold-const.c | 6 +-- gcc/testsuite/ChangeLog | 5 +++ .../gcc.c-torture/execute/pr16790-1.c | 41 +++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr16790-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9b2fc027c26..2825c795b1f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-08-03 Roger Sayle + + PR middle-end/16790 + * fold-const.c (extract_muldiv_1) : Disallow local + truncations, not just global truncations. + 2004-08-03 Andrew Pinski PR bootstrap/16865 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index f4a6fb022d4..503b6f094cf 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5102,9 +5102,9 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type) && TYPE_IS_SIZETYPE (TREE_TYPE (op0))) && (GET_MODE_SIZE (TYPE_MODE (ctype)) > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0))))) - /* ... or its type is larger than ctype, - then we cannot pass through this truncation. */ - || (GET_MODE_SIZE (TYPE_MODE (ctype)) + /* ... or this is a truncation (t is narrower than op0), + then we cannot pass through this narrowing. */ + || (GET_MODE_SIZE (TYPE_MODE (type)) < GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))) /* ... or signedness changes for division or modulus, then we cannot pass through this conversion. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 72e026ca131..db11af67a72 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-08-03 Roger Sayle + + PR middle-end/16790 + * gcc.c-torture/execute/pr16790-1.c: New test case. + 2004-08-03 Mark Mitchell * gcc.dg/symbian1.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr16790-1.c b/gcc/testsuite/gcc.c-torture/execute/pr16790-1.c new file mode 100644 index 00000000000..dc6a77404b5 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr16790-1.c @@ -0,0 +1,41 @@ +/* PR middle-end/16790. */ + +extern void abort (); + +static void test1(unsigned int u1) +{ + unsigned int y_final_1; + signed short y_middle; + unsigned int y_final_2; + + y_final_1 = (unsigned int)( (signed short)(u1 * 2) * 3 ); + y_middle = (signed short)(u1 * 2); + y_final_2 = (unsigned int)( y_middle * 3 ); + + if (y_final_1 != y_final_2) + abort (); +} + + +static void test2(unsigned int u1) +{ + unsigned int y_final_1; + signed short y_middle; + unsigned int y_final_2; + + y_final_1 = (unsigned int)( (signed short)(u1 << 1) * 3 ); + y_middle = (signed short)(u1 << 1); + y_final_2 = (unsigned int)( y_middle * 3 ); + + if (y_final_1 != y_final_2) + abort (); +} + + +int main() +{ + test1(0x4000U); + test2(0x4000U); + return 0; +} + -- 2.30.2