aco: Fix convert_to_SDWA when instruction has 3 operands.
authorTimur Kristóf <timur.kristof@gmail.com>
Sat, 22 Aug 2020 18:45:54 +0000 (20:45 +0200)
committerTimur Kristóf <timur.kristof@gmail.com>
Mon, 24 Aug 2020 13:55:14 +0000 (15:55 +0200)
Previously, when the instruction had 3 operands, this would cause
possible corruption because of writing to sdwa->sel[2].
This was noticed thanks to GCC 10's -Wstringop-overflow warning.

Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6436>

src/amd/compiler/aco_ir.cpp

index 801fbc68616be47af44a9f83abb9e6c358e7454c..b594b2824e9a1ed4f02b2824df07ba49a3fc81aa 100644 (file)
@@ -238,6 +238,10 @@ aco_ptr<Instruction> convert_to_SDWA(chip_class chip, aco_ptr<Instruction>& inst
    }
 
    for (unsigned i = 0; i < instr->operands.size(); i++) {
+      /* SDWA only uses operands 0 and 1. */
+      if (i >= 2)
+         break;
+
       switch (instr->operands[i].bytes()) {
       case 1:
          sdwa->sel[i] = sdwa_ubyte;