[Beignet] [PATCH] GBE: fix a regression for piglit test.

Zhigang Gong zhigang.gong at intel.com
Wed May 28 02:04:11 PDT 2014


Access this->store[insnID+2] is not always safe, as it may
not exist.

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 backend/src/backend/gen_encoder.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/backend/src/backend/gen_encoder.cpp b/backend/src/backend/gen_encoder.cpp
index 038d14b..0091e81 100644
--- a/backend/src/backend/gen_encoder.cpp
+++ b/backend/src/backend/gen_encoder.cpp
@@ -1101,7 +1101,6 @@ namespace gbe
 
   void GenEncoder::patchJMPI(uint32_t insnID, int32_t jumpDistance) {
     GenNativeInstruction &insn = *(GenNativeInstruction *)&this->store[insnID];
-    GenNativeInstruction &insn2 = *(GenNativeInstruction *)&this->store[insnID+2];
     GBE_ASSERT(insnID < this->store.size());
     GBE_ASSERT(insn.header.opcode == GEN_OPCODE_JMPI ||
                insn.header.opcode == GEN_OPCODE_BRD  ||
@@ -1130,12 +1129,15 @@ namespace gbe
       // for all the branching instruction. And need to adjust the distance
       // for those branch instruction's start point and end point contains
       // this instruction.
-      GBE_ASSERT(insn2.header.opcode == GEN_OPCODE_NOP);
+      GenNativeInstruction *insn2 = (GenNativeInstruction *)&this->store[insnID+2];
+      GBE_ASSERT(insn2->header.opcode == GEN_OPCODE_NOP);
+      insn2 = insn2;
       insn.header.opcode = GEN_OPCODE_ADD;
       this->setDst(&insn, GenRegister::ip());
       this->setSrc0(&insn, GenRegister::ip());
       this->setSrc1(&insn, GenRegister::immd(jumpDistance * 8));
     } else {
+      GenNativeInstruction &insn2 = *(GenNativeInstruction *)&this->store[insnID+2];
       insn.header.predicate_inverse ^= 1;
       this->setSrc1(&insn, GenRegister::immd(2));
       GBE_ASSERT(insn2.header.opcode == GEN_OPCODE_NOP);
-- 
1.8.3.2



More information about the Beignet mailing list