nir/search: Use larger type to hold linearized index
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 18 Feb 2020 23:31:37 +0000 (15:31 -0800)
committerMarge Bot <eric+marge@anholt.net>
Wed, 19 Feb 2020 19:07:34 +0000 (19:07 +0000)
"index" is an offset into a linearized 3-dimensional array.  Starting
with fbd5359a0a6, the 3-dimensional array can have 43 elements in each
dimension.  43**3 = 79507, and that will overflow the uint16_t.

See also the discussion in MR !3765.

Fixes: fbd5359a0a6 ("nir/algebraic: Rearrange bcsel sequences generated by nir_opt_peephole_select")
Suggested-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3871>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3871>

src/compiler/nir/nir_search.c

index 458a4eeb1ce1ec7ebe8c13b4cb9721a2bd417004..7abb023faf5a8a076bbaaf49f50ba182a2bee643 100644 (file)
@@ -789,7 +789,7 @@ nir_algebraic_automaton(nir_instr *instr, struct util_dynarray *states,
        * itertools.product(), which was used to emit the transition
        * table.
        */
-      uint16_t index = 0;
+      unsigned index = 0;
       for (unsigned i = 0; i < nir_op_infos[op].num_inputs; i++) {
          index *= tbl->num_filtered_states;
          index += tbl->filter[*util_dynarray_element(states, uint16_t,