Message ID | 20160620184518.GJ7387@tucnak.redhat.com |
---|---|
State | New |
Headers | show |
On 06/20/2016 12:45 PM, Jakub Jelinek wrote: > Hi! > > On the following testcase we ICE during warn_uninit. > Normally, has_undefined_value_p returns false for anonymous SSA_NAMEs, > so NULL expr/var aren't a problem. If t has a COMPLEX_EXPR as def-stmt, > where the first operand is some scalar var's (D) SSA_NAME and the second > operand is 0, which results from gimplification of conversion of scalar > uninitialized var to complex type, t is anonymous SSA_NAME and expr and var > are both NULL. > > This patch attempts to deal with that, try to recognize the case and use > the other SSA_NAME's underlying var as expr/var in that case, or punt (in > the unlikely case this wouldn't help). > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/6.2? > > 2016-06-20 Jakub Jelinek <jakub@redhat.com> > > PR middle-end/71581 > * tree-ssa-uninit.c (warn_uninit): If EXPR and VAR are NULL, > see if T isn't anonymous SSA_NAME with COMPLEX_EXPR created > for conversion of scalar user var to complex type and use the > underlying SSA_NAME_VAR in that case. If EXPR is still NULL, > punt. > > * gcc.dg/pr71581.c: New test. OK. jeff
--- gcc/tree-ssa-uninit.c.jj 2016-05-06 15:09:09.000000000 +0200 +++ gcc/tree-ssa-uninit.c 2016-06-20 16:13:31.324052992 +0200 @@ -131,6 +131,29 @@ warn_uninit (enum opt_code wc, tree t, t if (!has_undefined_value_p (t)) return; + /* Anonymous SSA_NAMEs shouldn't be uninitialized, but ssa_undefined_value_p + can return true if the def stmt of anonymous SSA_NAME is COMPLEX_EXPR + created for conversion from scalar to complex. Use the underlying var of + the COMPLEX_EXPRs real part in that case. See PR71581. */ + if (expr == NULL_TREE + && var == NULL_TREE + && SSA_NAME_VAR (t) == NULL_TREE + && is_gimple_assign (SSA_NAME_DEF_STMT (t)) + && gimple_assign_rhs_code (SSA_NAME_DEF_STMT (t)) == COMPLEX_EXPR) + { + tree v = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (t)); + if (TREE_CODE (v) == SSA_NAME + && has_undefined_value_p (v) + && zerop (gimple_assign_rhs2 (SSA_NAME_DEF_STMT (t)))) + { + expr = SSA_NAME_VAR (v); + var = expr; + } + } + + if (expr == NULL_TREE) + return; + /* TREE_NO_WARNING either means we already warned, or the front end wishes to suppress the warning. */ if ((context --- gcc/testsuite/gcc.dg/pr71581.c.jj 2016-06-20 16:39:18.825817407 +0200 +++ gcc/testsuite/gcc.dg/pr71581.c 2016-06-20 16:28:49.000000000 +0200 @@ -0,0 +1,24 @@ +/* PR middle-end/71581 */ +/* { dg-do compile } */ +/* { dg-options "-Wuninitialized" } */ + +_Complex float +f1 (void) +{ + float x; + return x; /* { dg-warning "is used uninitialized in this function" } */ +} + +_Complex double +f2 (void) +{ + double x; + return x; /* { dg-warning "is used uninitialized in this function" } */ +} + +_Complex int +f3 (void) +{ + int x; + return x; /* { dg-warning "is used uninitialized in this function" } */ +}