From bbe708a3914c49b9124bd2b44a9d62d5640ffd27 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand <uweigand@de.ibm.com> Date: Thu, 11 Mar 2004 22:48:36 +0000 Subject: [PATCH] combine.c (if_then_else_cond): Check for NULL return value of simplify_gen_subreg. ChangeLog: * combine.c (if_then_else_cond): Check for NULL return value of simplify_gen_subreg. testsuite/ChangeLog: * gcc.dg/20040310-1.c: New test. From-SVN: r79347 --- gcc/ChangeLog | 5 +++++ gcc/combine.c | 14 ++++++++----- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/20040310-1.c | 34 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/20040310-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bf5617d263d5..8526cfb6c883 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-03-11 Ulrich Weigand <uweigand@de.ibm.com> + + * combine.c (if_then_else_cond): Check for NULL return value of + simplify_gen_subreg. + 2004-03-11 Richard Sandiford <rsandifo@redhat.com> PR target/14496 diff --git a/gcc/combine.c b/gcc/combine.c index 497e8263ad97..c627187c1741 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -7378,12 +7378,16 @@ if_then_else_cond (rtx x, rtx *ptrue, rtx *pfalse) && 0 != (cond0 = if_then_else_cond (SUBREG_REG (x), &true0, &false0))) { - *ptrue = simplify_gen_subreg (mode, true0, + true0 = simplify_gen_subreg (mode, true0, + GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x)); + false0 = simplify_gen_subreg (mode, false0, GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x)); - *pfalse = simplify_gen_subreg (mode, false0, - GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x)); - - return cond0; + if (true0 && false0) + { + *ptrue = true0; + *pfalse = false0; + return cond0; + } } /* If X is a constant, this isn't special and will cause confusions diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 90916b8b98a7..da07a0408e90 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-03-11 Ulrich Weigand <uweigand@de.ibm.com> + + * gcc.dg/20040310-1.c: New test. + 2004-03-11 Roger Sayle <roger@eyesopen.com> * gcc.c-torture/execute/20040311-1.c: New test case. diff --git a/gcc/testsuite/gcc.dg/20040310-1.c b/gcc/testsuite/gcc.dg/20040310-1.c new file mode 100644 index 000000000000..104e98d08893 --- /dev/null +++ b/gcc/testsuite/gcc.dg/20040310-1.c @@ -0,0 +1,34 @@ +/* This caused cc1 to segfault on s390x-ibm-linux + due to a bug in if_then_else_cond (combine.c). */ + +/* { dg-do compile } */ +/* { dg-options "-O1" } */ + +extern void use (unsigned int x); + +int main (void) +{ + union + { + unsigned int x; + unsigned long pad; + } A; + + struct + { + unsigned int x : 1; + } B; + + A.x = 1; + B.x = 1; + A.x /= B.x; + use (A.x); + + A.x = 1; + B.x = 1; + B.x /= A.x; + use (B.x); + + return 0; +} + -- GitLab