diff mbox series

Fix PR89296

Message ID alpine.LSU.2.20.1902181353570.23386@zhemvz.fhfr.qr
State New
Headers show
Series Fix PR89296 | expand

Commit Message

Richard Biener Feb. 18, 2019, 12:54 p.m. UTC
no-warning overloading means we should be quite narrow to catch only
problematic cases when setting the flag.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2019-02-18  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/89296
	* tree-ssa-loop-ch.c (ch_base::copy_headers): Restrict setting
	of no-warning flag to cases that might emit the bogus warning.

	* gcc.dg/uninit-pr89296.c: New testcase.
diff mbox series

Patch

Index: gcc/tree-ssa-loop-ch.c
===================================================================
--- gcc/tree-ssa-loop-ch.c	(revision 268979)
+++ gcc/tree-ssa-loop-ch.c	(working copy)
@@ -452,11 +452,23 @@  ch_base::copy_headers (function *fun)
 		{
 		  gimple *stmt = gsi_stmt (bsi);
 		  if (gimple_code (stmt) == GIMPLE_COND)
-		    gimple_set_no_warning (stmt, true);
+		    {
+		      tree lhs = gimple_cond_lhs (stmt);
+		      if (gimple_cond_code (stmt) != EQ_EXPR
+			  && gimple_cond_code (stmt) != NE_EXPR
+			  && INTEGRAL_TYPE_P (TREE_TYPE (lhs))
+			  && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (lhs)))
+			gimple_set_no_warning (stmt, true);
+		    }
 		  else if (is_gimple_assign (stmt))
 		    {
 		      enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
-		      if (TREE_CODE_CLASS (rhs_code) == tcc_comparison)
+		      tree rhs1 = gimple_assign_rhs1 (stmt);
+		      if (TREE_CODE_CLASS (rhs_code) == tcc_comparison
+			  && rhs_code != EQ_EXPR
+			  && rhs_code != NE_EXPR
+			  && INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
+			  && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (rhs1)))
 			gimple_set_no_warning (stmt, true);
 		    }
 		}
Index: gcc/testsuite/gcc.dg/uninit-pr89296.c
===================================================================
--- gcc/testsuite/gcc.dg/uninit-pr89296.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/uninit-pr89296.c	(working copy)
@@ -0,0 +1,13 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+int get_a_value ();
+void printk(const char *);
+void test_func()
+{
+    int loop;
+    while (!loop) {             /* { dg-warning "is used uninitialized" } */
+	loop = get_a_value();
+	printk("...");
+    }
+}