diff mbox series

avoid uninitialized use in -Walloca* pass

Message ID c3bbd856-e65a-c028-dbb7-74b40837d631@redhat.com
State New
Headers show
Series avoid uninitialized use in -Walloca* pass | expand

Commit Message

Aldy Hernandez Sept. 7, 2018, 9:12 a.m. UTC
Semi obvious patch here...

As the comment for alloca_type_and_limit says:

   // For ALLOCA_BOUND_MAYBE_LARGE and ALLOCA_BOUND_DEFINITELY_LARGE
   // types, this field indicates the assumed limit if known or
   // integer_zero_node if unknown.  For any other alloca types, this
   // field is undefined.

So, there's no sense in creating ALLOCA_BOUND_*_LARGE entries without a 
limit, as doing so would trigger reading undefined memory later on.

We could put an assert here, but I'd rather just let the constructor 
build the right thing.

OK for trunk?

Comments

Jeff Law Sept. 11, 2018, 10:50 p.m. UTC | #1
On 9/7/18 3:12 AM, Aldy Hernandez wrote:
> Semi obvious patch here...
> 
> As the comment for alloca_type_and_limit says:
> 
>   // For ALLOCA_BOUND_MAYBE_LARGE and ALLOCA_BOUND_DEFINITELY_LARGE
>   // types, this field indicates the assumed limit if known or
>   // integer_zero_node if unknown.  For any other alloca types, this
>   // field is undefined.
> 
> So, there's no sense in creating ALLOCA_BOUND_*_LARGE entries without a
> limit, as doing so would trigger reading undefined memory later on.
> 
> We could put an assert here, but I'd rather just let the constructor
> build the right thing.
> 
> OK for trunk?
> 
> curr.patch
> 
> gcc/
> 
> 	* gimple-ssa-warn-alloca.c
> 	(alloca_type_and_limit::alloca_type_and_limit): Initialize limit
> 	field for ALLOCA_BOUND_*_LARGE.
OK.
jeff
diff mbox series

Patch

gcc/

	* gimple-ssa-warn-alloca.c
	(alloca_type_and_limit::alloca_type_and_limit): Initialize limit
	field for ALLOCA_BOUND_*_LARGE.

diff --git a/gcc/gimple-ssa-warn-alloca.c b/gcc/gimple-ssa-warn-alloca.c
index 4d5aed866e1..d1b1de4a2d5 100644
--- a/gcc/gimple-ssa-warn-alloca.c
+++ b/gcc/gimple-ssa-warn-alloca.c
@@ -128,7 +128,11 @@  struct alloca_type_and_limit {
   alloca_type_and_limit ();
   alloca_type_and_limit (enum alloca_type type,
 			 wide_int i) : type(type), limit(i) { }
-  alloca_type_and_limit (enum alloca_type type) : type(type) { }
+  alloca_type_and_limit (enum alloca_type type) : type(type)
+  { if (type == ALLOCA_BOUND_MAYBE_LARGE
+	|| type == ALLOCA_BOUND_DEFINITELY_LARGE)
+      limit = wi::to_wide (integer_zero_node);
+  }
 };
 
 /* Return the value of the argument N to -Walloca-larger-than= or