aco: Fix invalid usage of std::fill with std::array.
authorTimur Kristóf <timur.kristof@gmail.com>
Wed, 1 Sep 2021 06:40:45 +0000 (08:40 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 1 Sep 2021 09:33:28 +0000 (09:33 +0000)
In this case std::array doesn't behave like a regular array, therefore
it is NOT okay to index it outside the array, even though std::fill
needs us to do so.

Change the syntax to do the same thing slightly differently,
and add an assertion to make sure the registers are always within
the array's bounds.

Closes: #5289
Fixes: 0e4747d3fb7ec15f8c1d6b971b1352249e7d95c6
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Tony Wasserka <tony.wasserka@gmx.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12664>

src/amd/compiler/aco_optimizer_postRA.cpp

index 84ee6ef..4c38517 100644 (file)
@@ -110,9 +110,10 @@ save_reg_writes(pr_opt_ctx& ctx, aco_ptr<Instruction>& instr)
       if (def.regClass().is_subdword())
          idx = clobbered;
 
+      assert((r + dw_size) <= max_reg_cnt);
       assert(def.size() == dw_size || def.regClass().is_subdword());
       std::fill(&ctx.instr_idx_by_regs[ctx.current_block->index][r],
-                &ctx.instr_idx_by_regs[ctx.current_block->index][r + dw_size], idx);
+                &ctx.instr_idx_by_regs[ctx.current_block->index][r] + dw_size, idx);
    }
 }