+2019-04-29 Vladislav Ivanishin <vlad@ispras.ru>
+
+ * tree-ssa-uninit.c (is_pred_expr_subset_of): Correctly handle cases
+ where cond2 is NE_EXPR.
+ (is_value_included_in): Update comment.
+
2019-04-29 Richard Biener <rguenther@suse.de>
PR tree-optimization/90278
+2019-04-29 Vladislav Ivanishin <vlad@ispras.ru>
+
+ * gcc.dg/uninit-25-gimple.c: New test.
+ * gcc.dg/uninit-25.c: New test.
+ * gcc.dg/uninit-26.c: New test.
+ * gcc.dg/uninit-27-gimple.c: New test.
+
2019-04-29 Richard Biener <rguenther@suse.de>
PR tree-optimization/90278
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */
+
+unsigned int __GIMPLE (ssa,startwith("uninit1"))
+foo (unsigned int v)
+{
+ unsigned int undef; /* { dg-warning "may be used uninitialized" } */
+ unsigned int _2;
+ unsigned int _9;
+ unsigned int _10;
+
+ __BB(2):
+ if (v_4(D) != 1u)
+ goto __BB3;
+ else
+ goto __BB4;
+
+ __BB(3):
+ undef_8 = 8u; // 'undef' is defined conditionally (under 'v != 1' predicate)
+ goto __BB4;
+
+ __BB(4):
+ // An undef value flows into a phi.
+ undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8);
+ if (v_4(D) != 2u) // This condition is neither a superset nor a subset of 'v != 1'.
+ goto __BB5;
+ else
+ goto __BB6;
+
+ __BB(5):
+ _9 = undef_1; // The phi value is used here (under 'v != 2' predicate).
+ goto __BB7;
+
+ __BB(6):
+ _10 = v_4(D);
+ goto __BB7;
+
+ __BB(7):
+ _2 = __PHI (__BB5: _9, __BB6: _10);
+ return _2;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O -Wmaybe-uninitialized" } */
+
+extern unsigned bar (void);
+extern void quux (void);
+
+unsigned foo (unsigned v)
+{
+ unsigned u;
+ if (v != 1)
+ u = bar ();
+
+ // Prevent the "dom" pass from changing the CFG layout based on the inference
+ // 'if (v != 1) is false then (v != 2) is true'. (Now it would have to
+ // duplicate the loop in order to do so, which is deemed expensive.)
+ for (int i = 0; i < 10; i++)
+ quux ();
+
+ if (v != 2)
+ return u; /* { dg-warning "may be used uninitialized" } */
+
+ return 0;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O -Wmaybe-uninitialized" } */
+
+extern unsigned bar (void);
+extern void quux (void);
+
+unsigned foo (unsigned v)
+{
+ unsigned u;
+ if (v != 100)
+ u = bar ();
+
+ // Prevent the "dom" pass from changing the CFG layout based on the inference
+ // 'if (v != 100) is false then (v < 105) is true'. (Now it would have to
+ // duplicate the loop in order to do so, which is deemed expensive.)
+ for (int i = 0; i < 10; i++)
+ quux ();
+
+ if (v < 105) /* v == 100 falls into this range. */
+ return u; /* { dg-warning "may be used uninitialized" } */
+
+ return 0;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fgimple -O -Wmaybe-uninitialized" } */
+
+unsigned int __GIMPLE (ssa,startwith("uninit1"))
+foo (unsigned int v)
+{
+ unsigned int undef; /* { dg-bogus "may be used uninitialized" } */
+ unsigned int _2;
+ unsigned int _9;
+ unsigned int _10;
+
+ __BB(2):
+ if (v_4(D) != 100u)
+ goto __BB3;
+ else
+ goto __BB4;
+
+ __BB(3):
+ undef_8 = 8u; // 'undef' is defined conditionally (under 'v != 100' predicate)
+ goto __BB4;
+
+ __BB(4):
+ // An undef value flows into a phi.
+ undef_1 = __PHI (__BB2: undef_5(D), __BB3: undef_8);
+ if (v_4(D) < 100u)
+ goto __BB5;
+ else
+ goto __BB6;
+
+ __BB(5):
+ _9 = undef_1; // The phi value is used here (under 'v < 100' predicate).
+ goto __BB7;
+
+ __BB(6):
+ _10 = v_4(D);
+ goto __BB7;
+
+ __BB(7):
+ _2 = __PHI (__BB5: _9, __BB6: _10);
+ return _2;
+}
return tc;
}
-/* Returns true if VAL falls in the range defined by BOUNDARY and CMPC, i.e.
- all values in the range satisfies (x CMPC BOUNDARY) == true. */
+/* Returns whether VAL CMPC BOUNDARY is true. */
static bool
is_value_included_in (tree val, tree boundary, enum tree_code cmpc)
if (expr2.invert)
code2 = invert_tree_comparison (code2, false);
+ if (code2 == NE_EXPR && code1 == NE_EXPR)
+ return false;
+
+ if (code2 == NE_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)
return (wi::to_wide (expr1.pred_rhs)
== (wi::to_wide (expr1.pred_rhs) & wi::to_wide (expr2.pred_rhs)));
- if (code1 != code2 && code2 != NE_EXPR)
+ if (code1 != code2)
return false;
if (is_value_included_in (expr1.pred_rhs, expr2.pred_rhs, code2))