|
From: <sv...@va...> - 2017-03-13 13:08:25
|
Author: iraisr
Date: Mon Mar 13 13:08:13 2017
New Revision: 3315
Log:
Fix IRSB traversal problem in sanityCheckIRSB()
Modified:
branches/VEX_JIT_HACKS/priv/ir_defs.c
Modified: branches/VEX_JIT_HACKS/priv/ir_defs.c
==============================================================================
--- branches/VEX_JIT_HACKS/priv/ir_defs.c (original)
+++ branches/VEX_JIT_HACKS/priv/ir_defs.c Mon Mar 13 13:08:13 2017
@@ -4006,6 +4006,11 @@
return True;
}
+Bool isFlatIRSB(const IRSB* irsb)
+{
+ return isFlatIRStmtVec(irsb->stmts);
+}
+
/*---------------------------------------------------------------*/
/*--- Sanity checking ---*/
/*---------------------------------------------------------------*/
@@ -4137,7 +4142,7 @@
def_counts[tmp.id][tmp.index]++;
if (def_counts[tmp.id][tmp.index] > 1) {
- sanityCheckFail(bb,stmt,err_msg_assigned_more_than_once);
+ sanityCheckFail(bb, stmt, err_msg_assigned_more_than_once);
}
}
@@ -4236,9 +4241,6 @@
}
}
-static void useBeforeDef_Stmts(const IRSB* bb, const IRStmtVec* stmts,
- UInt* def_counts[]);
-
static
void useBeforeDef_Stmt(const IRSB* bb, const IRStmtVec* stmts,
const IRStmt* stmt, UInt* def_counts[])
@@ -4322,8 +4324,7 @@
case Ist_IfThenElse:
useBeforeDef_Expr(bb, stmts, stmt, stmt->Ist.IfThenElse.cond,
def_counts);
- useBeforeDef_Stmts(bb, stmt->Ist.IfThenElse.then_leg, def_counts);
- useBeforeDef_Stmts(bb, stmt->Ist.IfThenElse.else_leg, def_counts);
+ /* Traversing into legs driven from sanityCheckIRStmtVec(). */
if (stmt->Ist.IfThenElse.phi_nodes != NULL) {
useBeforeDef_PhiNodes(bb, stmts, stmt,
stmt->Ist.IfThenElse.phi_nodes, def_counts);
@@ -4335,18 +4336,6 @@
}
static
-void useBeforeDef_Stmts(const IRSB* bb, const IRStmtVec* stmts,
- UInt* def_counts[])
-{
- for (UInt i = 0; i < stmts->stmts_used; i++) {
- useBeforeDef_Stmt(bb, stmts, stmts->stmts[i], def_counts);
- }
-}
-
-static void assignedOnce_Stmts(const IRSB* bb, const IRStmtVec* stmts,
- UInt* def_counts[]);
-
-static
void assignedOnce_Stmt(const IRSB* bb, const IRStmtVec* stmts,
const IRStmt* stmt, UInt* def_counts[])
{
@@ -4396,8 +4385,7 @@
"IRStmt.LLSC: destination tmp is assigned more than once");
break;
case Ist_IfThenElse: {
- assignedOnce_Stmts(bb, stmt->Ist.IfThenElse.then_leg, def_counts);
- assignedOnce_Stmts(bb, stmt->Ist.IfThenElse.else_leg, def_counts);
+ /* Traversing into legs driven from sanityCheckIRStmtVec(). */
const IRPhiVec* phi_nodes = stmt->Ist.IfThenElse.phi_nodes;
if (phi_nodes != NULL) {
for (UInt i = 0; i < phi_nodes->phis_used; i++) {
@@ -4420,15 +4408,6 @@
}
static
-void assignedOnce_Stmts(const IRSB* bb, const IRStmtVec* stmts,
- UInt* def_counts[])
-{
- for (UInt i = 0; i < stmts->stmts_used; i++) {
- assignedOnce_Stmt(bb, stmts, stmts->stmts[i], def_counts);
- }
-}
-
-static
void tcExpr(const IRSB* bb, const IRStmtVec* stmts, const IRStmt* stmt,
const IRExpr* expr, IRType gWordTy)
{
@@ -4652,9 +4631,6 @@
}
}
-static void tcStmts(const IRSB* bb, const IRStmtVec* stmts, Bool require_flat,
- IRType gWordTy);
-
static
void tcStmt(const IRSB* bb, const IRStmtVec* stmts, const IRStmt* stmt,
Bool require_flat, IRType gWordTy)
@@ -4940,8 +4916,7 @@
tcExpr(bb, stmts, stmt, stmt->Ist.IfThenElse.cond, gWordTy);
if (typeOfIRExpr(tyenv, stmt->Ist.IfThenElse.cond) != Ity_I1)
sanityCheckFail(bb,stmt,"IRStmt.IfThenElse.cond: not :: Ity_I1");
- tcStmts(bb, stmt->Ist.IfThenElse.then_leg, require_flat, gWordTy);
- tcStmts(bb, stmt->Ist.IfThenElse.else_leg, require_flat, gWordTy);
+ /* Traversing into legs driven from sanityCheckIRStmtVec(). */
const IRPhiVec* phi_nodes = stmt->Ist.IfThenElse.phi_nodes;
if (phi_nodes != NULL) {
for (UInt i = 0; i < phi_nodes->phis_used; i++) {
@@ -4955,18 +4930,10 @@
}
static
-void tcStmts(const IRSB* bb, const IRStmtVec* stmts, Bool require_flat,
- IRType gWordTy)
-{
- for (UInt i = 0; i < stmts->stmts_used; i++) {
- tcStmt(bb, stmts, stmts->stmts[i], require_flat, gWordTy);
- }
-}
-
-static
void sanityCheckIRStmtVec(const IRSB* bb, const IRStmtVec* stmts,
Bool require_flat, UInt* def_counts[],
- UInt n_stmt_vecs, UInt id_counts[])
+ UInt n_stmt_vecs, UInt id_counts[],
+ IRType gWordTy)
{
const IRTypeEnv* tyenv = stmts->tyenv;
IRTyEnvID id = tyenv->id;
@@ -5009,21 +4976,30 @@
}
}
- /* Check for flatness, if required. */
- if (require_flat) {
- for (UInt i = 0; i < stmts->stmts_used; i++) {
- const IRStmt *stmt = stmts->stmts[i];
- if (stmt == NULL)
- sanityCheckFail(bb,stmt,"IRStmt: is NULL");
- if (!isFlatIRStmt(stmt))
- sanityCheckFail(bb,stmt,"IRStmt: is not flat");
- if (stmt->tag == Ist_IfThenElse) {
- sanityCheckIRStmtVec(bb, stmt->Ist.IfThenElse.then_leg,
- require_flat, def_counts, n_stmt_vecs, id_counts);
- sanityCheckIRStmtVec(bb, stmt->Ist.IfThenElse.else_leg,
- require_flat, def_counts, n_stmt_vecs, id_counts);
+ for (UInt i = 0; i < stmts->stmts_used; i++) {
+ const IRStmt *stmt = stmts->stmts[i];
+ if (stmt == NULL)
+ sanityCheckFail(bb, stmt, "IRStmt: is NULL");
+
+ /* Check for flatness, if required. */
+ if (require_flat) {
+ if (!isFlatIRStmt(stmt)) {
+ sanityCheckFail(bb, stmt, "IRStmt: is not flat");
}
}
+
+ /* Count the defs of each temp. Only one def is allowed.
+ Also, check that each used temp has already been defd. */
+ useBeforeDef_Stmt(bb, stmts, stmt, def_counts);
+ assignedOnce_Stmt(bb, stmts, stmt, def_counts);
+ tcStmt(bb, stmts, stmt, require_flat, gWordTy);
+
+ if (stmt->tag == Ist_IfThenElse) {
+ sanityCheckIRStmtVec(bb, stmt->Ist.IfThenElse.then_leg, require_flat,
+ def_counts, n_stmt_vecs, id_counts, gWordTy);
+ sanityCheckIRStmtVec(bb, stmt->Ist.IfThenElse.else_leg, require_flat,
+ def_counts, n_stmt_vecs, id_counts, gWordTy);
+ }
}
}
@@ -5047,13 +5023,7 @@
vassert(gWordTy == Ity_I32 || gWordTy == Ity_I64);
sanityCheckIRStmtVec(bb, bb->stmts, require_flat, def_counts, n_stmt_vecs,
- id_counts);
-
- /* Count the defs of each temp. Only one def is allowed.
- Also, check that each used temp has already been defd. */
- useBeforeDef_Stmts(bb, bb->stmts, def_counts);
- assignedOnce_Stmts(bb, bb->stmts, def_counts);
- tcStmts(bb, bb->stmts, require_flat, gWordTy);
+ id_counts, gWordTy);
if (require_flat) {
if (!isIRAtom(bb->next)) {
|