cf6222
commit 6aa4f7e7e76b40c183fb29650540d119ce1b4a4a
cf6222
Author: Julian Seward <jseward@acm.org>
cf6222
Date:   Thu Jun 11 09:01:52 2020 +0200
cf6222
cf6222
    expr_is_guardable, stmt_is_guardable, add_guarded_stmt_to_end_of: handle GetI/PutI cases.
cf6222
    
cf6222
    This fixes #422715.
cf6222
cf6222
diff --git a/VEX/priv/guest_generic_bb_to_IR.c b/VEX/priv/guest_generic_bb_to_IR.c
cf6222
index 2f204c5b0..0cee970e4 100644
cf6222
--- a/VEX/priv/guest_generic_bb_to_IR.c
cf6222
+++ b/VEX/priv/guest_generic_bb_to_IR.c
cf6222
@@ -425,6 +425,7 @@ static Bool expr_is_guardable ( const IRExpr* e )
cf6222
       case Iex_ITE:
cf6222
       case Iex_CCall:
cf6222
       case Iex_Get:
cf6222
+      case Iex_GetI:
cf6222
       case Iex_Const:
cf6222
       case Iex_RdTmp:
cf6222
          return True;
cf6222
@@ -450,6 +451,7 @@ static Bool stmt_is_guardable ( const IRStmt* st )
cf6222
       case Ist_NoOp:
cf6222
       case Ist_IMark:
cf6222
       case Ist_Put:
cf6222
+      case Ist_PutI:
cf6222
          return True;
cf6222
       // These are definitely not guardable, or at least it's way too much
cf6222
       // hassle to do so.
cf6222
@@ -506,7 +508,7 @@ static void add_guarded_stmt_to_end_of ( /*MOD*/IRSB* bb,
cf6222
          // Put(offs, e) ==> Put(offs, ITE(guard, e, Get(offs, sizeof(e))))
cf6222
          // Which when flattened out is:
cf6222
          //   t1 = Get(offs, sizeof(e))
cf6222
-         //   t2 = ITE(guard, e, t2)
cf6222
+         //   t2 = ITE(guard, e, t1)
cf6222
          //   Put(offs, t2)
cf6222
          Int offset = st->Ist.Put.offset;
cf6222
          IRExpr* e = st->Ist.Put.data;
cf6222
@@ -519,6 +521,26 @@ static void add_guarded_stmt_to_end_of ( /*MOD*/IRSB* bb,
cf6222
          addStmtToIRSB(bb, IRStmt_Put(offset, IRExpr_RdTmp(t2)));
cf6222
          break;
cf6222
       }
cf6222
+      case Ist_PutI: {
cf6222
+         // PutI(descr,ix,bias, e) ==> Put(descr,ix,bias, ITE(guard, e, GetI(descr,ix,bias)))
cf6222
+         // Which when flattened out is:
cf6222
+         //   t1 = GetI(descr,ix,bias)
cf6222
+         //   t2 = ITE(guard, e, t1)
cf6222
+         //   PutI(descr,ix,bias, t2)
cf6222
+         IRPutI*     details = st->Ist.PutI.details;
cf6222
+         IRRegArray* descr   = details->descr;
cf6222
+         IRExpr*     ix      = details->ix;
cf6222
+         Int         bias    = details->bias;
cf6222
+         IRExpr*     e       = details->data;
cf6222
+         IRType ty = typeOfIRExpr(bb->tyenv, e);
cf6222
+         IRTemp t1 = newIRTemp(bb->tyenv, ty);
cf6222
+         IRTemp t2 = newIRTemp(bb->tyenv, ty);
cf6222
+         addStmtToIRSB(bb, IRStmt_WrTmp(t1, IRExpr_GetI(descr,ix,bias)));
cf6222
+         addStmtToIRSB(bb, IRStmt_WrTmp(t2, IRExpr_ITE(IRExpr_RdTmp(guard),
cf6222
+                                                       e, IRExpr_RdTmp(t1))));
cf6222
+         addStmtToIRSB(bb, IRStmt_PutI(mkIRPutI(descr,ix,bias, IRExpr_RdTmp(t2))));
cf6222
+         break;
cf6222
+      }
cf6222
       case Ist_Exit: {
cf6222
          // Exit(xguard, dst, jk, offsIP)
cf6222
          // ==> t1 = And1(xguard, guard)