From 74a96dd28c997a55344c201baeed409e9e4ce7af Mon Sep 17 00:00:00 2001 From: Vladislav Ivanishin Date: Thu, 16 May 2019 12:36:33 +0000 Subject: [PATCH] tree-ssa-uninit: avoid ICE with BIT_AND_EXPR (PR 90394) 2019-05-16 Vladislav Ivanishin PR tree-optimization/90394 * tree-ssa-uninit.c (is_pred_expr_subset_of): Potentially give false positives rather than ICE for cases where (code2 == NE_EXPR && code1 == BIT_AND_EXPR). testsuite/ * gcc.dg/uninit-pr90394-1-gimple.c: New test. * gcc.dg/uninit-pr90394.c: New test. From-SVN: r271287 --- gcc/ChangeLog | 7 +++ gcc/testsuite/ChangeLog | 6 +++ .../gcc.dg/uninit-pr90394-1-gimple.c | 47 +++++++++++++++++++ gcc/testsuite/gcc.dg/uninit-pr90394.c | 33 +++++++++++++ gcc/tree-ssa-uninit.c | 2 +- 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/uninit-pr90394-1-gimple.c create mode 100644 gcc/testsuite/gcc.dg/uninit-pr90394.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3f73f321fbe..df8135bc5fe 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-05-16 Vladislav Ivanishin + + PR tree-optimization/90394 + * tree-ssa-uninit.c (is_pred_expr_subset_of): Potentially give false + positives rather than ICE for cases where (code2 == NE_EXPR + && code1 == BIT_AND_EXPR). + 2019-05-16 Jakub Jelinek PR fortran/90329 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e6ce5a2c4db..d7af875cf74 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-05-16 Vladislav Ivanishin + + PR tree-optimization/90394 + * gcc.dg/uninit-pr90394-1-gimple.c: New test. + * gcc.dg/uninit-pr90394.c: New test. + 2019-05-16 Richard Biener PR testsuite/90502 diff --git a/gcc/testsuite/gcc.dg/uninit-pr90394-1-gimple.c b/gcc/testsuite/gcc.dg/uninit-pr90394-1-gimple.c new file mode 100644 index 00000000000..f8feb6b8967 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr90394-1-gimple.c @@ -0,0 +1,47 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */ + +unsigned int __GIMPLE (ssa,startwith("uninit1")) +foo (unsigned int v) +{ + /* The warning is not bogus, because (5 & 3) != 0 and therefore if v == 5, + the value of undef is used without being initialized. */ + unsigned int undef; /* { dg-warning "may be used uninitialized" } */ + unsigned int _2; + unsigned int _9; + unsigned int _10; + unsigned pred; + + __BB(2): + if (v_4(D) != 5u) + goto __BB3; + else + goto __BB4; + + /* 'undef' is defined conditionally (under 'v != 5' predicate) */ + __BB(3): + undef_8 = 8u; + goto __BB4; + + /* An undef value flows into a phi. */ + __BB(4): + undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8); + pred = v_4(D) & 3u; + if (pred != 0u) + goto __BB5; + else + goto __BB6; + + /* The phi value is used here (under 'v & 3' predicate). */ + __BB(5): + _9 = undef_1; + goto __BB7; + + __BB(6): + _10 = v_4(D); + goto __BB7; + + __BB(7): + _2 = __PHI (__BB5: _9, __BB6: _10); + return _2; +} diff --git a/gcc/testsuite/gcc.dg/uninit-pr90394.c b/gcc/testsuite/gcc.dg/uninit-pr90394.c new file mode 100644 index 00000000000..16e750d6b33 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr90394.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fno-tree-fre -Wuninitialized" } */ +int pz; +int zi; + +void +uk (void) +{ + int th = 1; + int *gw = &zi; + + for (zi = 0; zi < 2; ++zi) + { + int a2 = 0; + + for (zi = 0; zi < 1; ++zi) + { + th = a2 * 2; + + og: + for (pz = 0; pz < 1; ++pz) + { + } + } + + pz = !!*gw ? *gw : pz; + pz = (!!th ? (pz & 1) : 0); + if (pz == 0) + ++a2; + } + + goto og; +} diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index 7362e374dea..b89da4017e8 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -1471,7 +1471,7 @@ is_pred_expr_subset_of (pred_info expr1, pred_info expr2) if (code2 == NE_EXPR && code1 == NE_EXPR) return false; - if (code2 == NE_EXPR) + if (code2 == NE_EXPR && code1 != BIT_AND_EXPR) return !is_value_included_in (expr2.pred_rhs, expr1.pred_rhs, code1); if ((code1 == EQ_EXPR || code1 == BIT_AND_EXPR) && code2 == BIT_AND_EXPR) -- 2.30.2