We were using impl->num_blocks, but that isn't guaranteed to be
up-to-date until after the block_index metadata is required. If we were
unlucky, this could lead to overwriting memory.
Noticed by inspection.
Signed-off-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
static bool
opt_gcm_impl(nir_function_impl *impl, bool value_number)
{
+ nir_metadata_require(impl, nir_metadata_block_index |
+ nir_metadata_dominance);
+
struct gcm_state state;
state.impl = impl;
exec_list_make_empty(&state.instrs);
state.blocks = rzalloc_array(NULL, struct gcm_block_info, impl->num_blocks);
- nir_metadata_require(impl, nir_metadata_block_index |
- nir_metadata_dominance);
-
gcm_build_block_info(&impl->body, &state, 0);
nir_foreach_block(block, impl) {