From: Julian Seward Date: Tue, 7 Dec 2004 19:00:57 +0000 (+0000) Subject: Redundant-Get elimination: only do the substitution when the types X-Git-Tag: svn/VALGRIND_3_0_1^2~703 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=43641ec037b95bc265b15978dbbdc491ca1d30c4;p=thirdparty%2Fvalgrind.git Redundant-Get elimination: only do the substitution when the types match. Not doing so leads to incorrectly typed IR. git-svn-id: svn://svn.valgrind.org/vex/trunk@631 --- diff --git a/VEX/priv/ir/iropt.c b/VEX/priv/ir/iropt.c index 56073f86eb..cd4c9e61e2 100644 --- a/VEX/priv/ir/iropt.c +++ b/VEX/priv/ir/iropt.c @@ -1190,13 +1190,21 @@ static void redundant_get_removal_BB ( IRBB* bb ) get->Iex.Get.ty ); if (lookupHHW(env, &val, (HWord)key)) { /* found it */ - if (DEBUG_IROPT) { + /* Note, we could do better here. If the types are + different we don't do the substitution, since doing so + could lead to invalidly-typed IR. An improvement would + be to stick in a reinterpret-style cast, although that + would make maintaining flatness more difficult. */ + IRExpr* valE = (IRExpr*)val; + Bool typesOK = typeOfIRExpr(bb->tyenv,valE) + == st->Ist.Tmp.data->Iex.Get.ty; + if (typesOK && DEBUG_IROPT) { vex_printf("rGET: "); ppIRExpr(get); - vex_printf(" -> "); ppIRExpr((IRExpr*)val); + vex_printf(" -> "); ppIRExpr(valE); vex_printf("\n"); } - bb->stmts[i] = IRStmt_Tmp(st->Ist.Tmp.tmp, - (IRExpr*)val); + if (typesOK) + bb->stmts[i] = IRStmt_Tmp(st->Ist.Tmp.tmp, valE); } else { /* Not found, but at least we know that t and the Get(...) are now associated. So add a binding to reflect that