From f9b781149e7cb42a079dda811caa52576209e6b0 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 23:39:44 -0600 Subject: [PATCH] add extra type checks to Compiler::store and Compiler::memory --- src/codegen/compiler.cpp | 6 ++++++ src/compile.cpp | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index e530610609..016682d8df 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -2323,6 +2323,8 @@ class MyCompiler: public Compiler { Operand* index = 0, unsigned scale = 1) { + assert(&c, index != 0 || scale == 1); + assert(&c, type.size() == scale || index == 0); Value* result = value(&c, type); appendMemory(&c, static_cast(base), displacement, @@ -2600,6 +2602,10 @@ class MyCompiler: public Compiler { { assert(&c, srcType.flavor() == static_cast(src)->type.flavor()); assert(&c, dstType.flavor() == static_cast(dst)->type.flavor()); + assert(&c, srcType.flavor() == dstType.flavor()); + assert(&c, + srcType.flavor() != ir::Type::Float + || srcType.size() == static_cast(src)->type.size()); appendMove(&c, lir::Move, srcType.size(), diff --git a/src/compile.cpp b/src/compile.cpp index ba013a9008..cb76f78db0 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -4145,7 +4145,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt( c->load(1, 1, - c->memory(array, types.i4, TargetArrayBody, index, 1), + c->memory(array, types.i1, TargetArrayBody, index, 1), TargetBytesPerWord)); break; @@ -4153,25 +4153,25 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->pushInt( c->loadz(2, 2, - c->memory(array, types.i4, TargetArrayBody, index, 2), + c->memory(array, types.i2, TargetArrayBody, index, 2), TargetBytesPerWord)); break; case daload: frame->pushLong(c->load( - 8, 8, c->memory(array, types.f4, TargetArrayBody, index, 8), 8)); + 8, 8, c->memory(array, types.f8, TargetArrayBody, index, 8), 8)); break; case laload: frame->pushLong(c->load( - 8, 8, c->memory(array, types.i4, TargetArrayBody, index, 8), 8)); + 8, 8, c->memory(array, types.i8, TargetArrayBody, index, 8), 8)); break; case saload: frame->pushInt( c->load(2, 2, - c->memory(array, types.i4, TargetArrayBody, index, 2), + c->memory(array, types.i2, TargetArrayBody, index, 2), TargetBytesPerWord)); break; } @@ -4245,7 +4245,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store(types.address, value, types.i1, - c->memory(array, types.i4, TargetArrayBody, index, 1)); + c->memory(array, types.i1, TargetArrayBody, index, 1)); break; case castore: @@ -4253,14 +4253,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->store(types.address, value, types.i2, - c->memory(array, types.i4, TargetArrayBody, index, 2)); + c->memory(array, types.i2, TargetArrayBody, index, 2)); break; case dastore: c->store(types.f8, value, types.f8, - c->memory(array, types.f4, TargetArrayBody, index, 8)); + c->memory(array, types.f8, TargetArrayBody, index, 8)); break; case lastore: @@ -5453,8 +5453,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, memcpy(&v, &singletonValue(t, pool, index - 1), 8); frame->pushLong(c->constant( v, - singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f4 - : types.i4)); + singletonBit(t, pool, poolSize(t, pool), index - 1) ? types.f8 + : types.i8)); } break; case ldiv_: {