This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix ICE in predicate comparison in uninit (PR middle-end/67512)


We were crashing on this testcase in invert_tree_comparison because it
got BIT_AND_EXPR, but this function expects comparison codes only.  In
this case pred_equal_p got two predicates: m != 1 and m & 1.  By checking
the tcc_comparison first we don't ICE anymore and pred_equal_p correctly
says false for these two predicates.

In 4.9 we were able to mark 'z' as maybe-uninitialized, but that's likely
out of scope for this patch.

Bootstrapped/regtested on x86_64-linux, ok for trunk and 5?

2015-09-09  Marek Polacek  <polacek@redhat.com>

	PR middle-end/67512
	* tree-ssa-uninit.c (pred_equal_p): Only call invert_tree_comparison
	for comparisons.

	* gcc.dg/pr67512.c: New test.

diff --git gcc/testsuite/gcc.dg/pr67512.c gcc/testsuite/gcc.dg/pr67512.c
index e69de29..628fd71 100644
--- gcc/testsuite/gcc.dg/pr67512.c
+++ gcc/testsuite/gcc.dg/pr67512.c
@@ -0,0 +1,15 @@
+/* PR middle-end/67512 */
+/* { dg-do compile }  */
+/* { dg-options "-O -Wuninitialized" } */
+
+extern int fn2 (void);
+extern int fn3 (int);
+void
+fn1 (void)
+{
+  int z, m;
+  if (1 & m) /* { dg-warning "is used uninitialized" } */
+    z = fn2 ();
+  z = 1 == m ? z : 2 == m;
+  fn3 (z);
+}
diff --git gcc/tree-ssa-uninit.c gcc/tree-ssa-uninit.c
index ec6d6f5..fa59642 100644
--- gcc/tree-ssa-uninit.c
+++ gcc/tree-ssa-uninit.c
@@ -1296,7 +1296,8 @@ pred_equal_p (pred_info x1, pred_info x2)
     return false;
 
   c1 = x1.cond_code;
-  if (x1.invert != x2.invert)
+  if (x1.invert != x2.invert
+      && TREE_CODE_CLASS (x2.cond_code) == tcc_comparison)
     c2 = invert_tree_comparison (x2.cond_code, false);
   else
     c2 = x2.cond_code;

	Marek


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]