diff mbox

unitialized memory access vs BIT_INSERT_EXPR

Message ID CA+=Sn1=ADPb-Z8QuuFy7fu1qgrXS-qzFLfMQFSxDau1-Cq0kPg@mail.gmail.com
State New
Headers show

Commit Message

Andrew Pinski July 21, 2017, 6:24 p.m. UTC
Hi,
  Due to the way bit-field access lower is done, we can get an
unitialized memory load and this causes the unitialized warning to
kick in.
The case we have is:
temp_1 = BIT_FIELD_REF<a, 0, 64>
temp_2 = BIT_INSERT<temp_1, V, P (N bits)>
BIT_FIELD_REF<a, 0, 64> = temp_2

What this patch does is similar to what was done for the case of
BIT_INSERT for unitialized ssa names (default) but for memory
accesses.
Note also tested with the bit-field lower pass added; this and the
fold-const.c/tree-ssa-sccvn.c patch (which was just committed) are
requirements to the lower pass.

OK?  Bootstrapped and tested on aarch64-linux-gnu with no regressions.

Thanks,
Andrew Pinski
* tree-ssa-uninit.c (warn_uninitialized_vars): Don't warn about memory
accesses where the use is for the first operand of a BIT_INSERT.

Comments

Richard Biener July 25, 2017, 7:10 a.m. UTC | #1
On Fri, Jul 21, 2017 at 8:24 PM, Andrew Pinski <pinskia@gmail.com> wrote:
> Hi,
>   Due to the way bit-field access lower is done, we can get an
> unitialized memory load and this causes the unitialized warning to
> kick in.
> The case we have is:
> temp_1 = BIT_FIELD_REF<a, 0, 64>
> temp_2 = BIT_INSERT<temp_1, V, P (N bits)>
> BIT_FIELD_REF<a, 0, 64> = temp_2
>
> What this patch does is similar to what was done for the case of
> BIT_INSERT for unitialized ssa names (default) but for memory
> accesses.
> Note also tested with the bit-field lower pass added; this and the
> fold-const.c/tree-ssa-sccvn.c patch (which was just committed) are
> requirements to the lower pass.
>
> OK?  Bootstrapped and tested on aarch64-linux-gnu with no regressions.

Ok.

Thanks,
Richard.

> Thanks,
> Andrew Pinski
> * tree-ssa-uninit.c (warn_uninitialized_vars): Don't warn about memory
> accesses where the use is for the first operand of a BIT_INSERT.
diff mbox

Patch

Index: tree-ssa-uninit.c
===================================================================
--- tree-ssa-uninit.c	(revision 250430)
+++ tree-ssa-uninit.c	(working copy)
@@ -273,6 +273,11 @@  warn_uninitialized_vars (bool warn_possi
 	      && gimple_has_location (stmt))
 	    {
 	      tree rhs = gimple_assign_rhs1 (stmt);
+	      tree lhs = gimple_assign_lhs (stmt);
+	      bool has_bit_insert = false;
+	      use_operand_p luse_p;
+	      imm_use_iterator liter;
+
 	      if (TREE_NO_WARNING (rhs))
 		continue;
 
@@ -300,6 +305,26 @@  warn_uninitialized_vars (bool warn_possi
 					       ref.offset) <= 0)))
 		continue;
 
+	      /* Do not warn if the access is then used for a BIT_INSERT_EXPR. */
+	      if (TREE_CODE (lhs) == SSA_NAME)
+	        FOR_EACH_IMM_USE_FAST (luse_p, liter, lhs)
+		  {
+		    gimple *use_stmt = USE_STMT (luse_p);
+                    /* BIT_INSERT_EXPR first operand should not be considered
+		       a use for the purpose of uninit warnings.  */
+		    if (gassign *ass = dyn_cast <gassign *> (use_stmt))
+		      {
+			if (gimple_assign_rhs_code (ass) == BIT_INSERT_EXPR
+			    && luse_p->use == gimple_assign_rhs1_ptr (ass))
+			  {
+			    has_bit_insert = true;
+			    break;
+			  }
+		      }
+		  }
+	      if (has_bit_insert)
+		continue;
+
 	      /* Limit the walking to a constant number of stmts after
 	         we overcommit quadratic behavior for small functions
 		 and O(n) behavior.  */