From 68826b15f5e926316dafc8fc1528d6c14d401b16 Mon Sep 17 00:00:00 2001 From: rguenth Date: Mon, 19 Jun 2006 14:48:47 +0000 Subject: [PATCH] 2006-06-19 Richard Guenther PR middle-end/28045 * fold-const.c (operand_equal_p): Check if the argument types have the same precision before stripping NOPs. * gcc.dg/torture/pr28045.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114772 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr28045.c | 22 ++++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr28045.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 34b7da6cbbe..be202bf61d0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2006-06-19 Richard Guenther + + PR middle-end/28045 + * fold-const.c (operand_equal_p): Check if the argument types + have the same precision before stripping NOPs. + 2006-06-19 Daniel Berlin Fix PR tree-optimization/27341 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 57a72489121..5a65586794e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2497,6 +2497,11 @@ operand_equal_p (tree arg0, tree arg1, unsigned int flags) if (TYPE_UNSIGNED (TREE_TYPE (arg0)) != TYPE_UNSIGNED (TREE_TYPE (arg1))) return 0; + /* If both types don't have the same precision, then it is not safe + to strip NOPs. */ + if (TYPE_PRECISION (TREE_TYPE (arg0)) != TYPE_PRECISION (TREE_TYPE (arg1))) + return 0; + STRIP_NOPS (arg0); STRIP_NOPS (arg1); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 985d6455567..ba44e8fb2ac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-06-19 Richard Guenther + + PR middle-end/28045 + * gcc.dg/torture/pr28045.c: New testcase. + 2006-06-18 Francois-Xavier Coudert PR fortran/26801 diff --git a/gcc/testsuite/gcc.dg/torture/pr28045.c b/gcc/testsuite/gcc.dg/torture/pr28045.c new file mode 100644 index 00000000000..f2d16646ca2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr28045.c @@ -0,0 +1,22 @@ +/* { dg-do run } */ + +extern void abort(void); +struct a +{ + unsigned int bits : 1; + signed long val : ((sizeof(long) * 8) - 1); +}; +int Fnegate (struct a b) +{ + if ((-((long)b.val)) <= ((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL)) + && (-((long)b.val)) >= (-(((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))) - 1)) + return 0 ; + abort (); +} +int main () +{ + struct a b = {1, 1}; + Fnegate (b); + return 0; +} + -- 2.11.4.GIT