From 9918ea6cddd01648ce09cf9db7537174955fe21b Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 18 Apr 2013 11:27:05 -0600 Subject: [PATCH] fix sign extension from constant to register on x86 scalac may generate a ldc followed by an l2i, whereas javac always seems to condense this into a single ldc_w. The former exposed a bug in the JIT compiler which we never hit with javac-generated bytecode. --- src/codegen/target/x86/encode.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/codegen/target/x86/encode.cpp b/src/codegen/target/x86/encode.cpp index 97c85d5fc3..7f8782b105 100644 --- a/src/codegen/target/x86/encode.cpp +++ b/src/codegen/target/x86/encode.cpp @@ -330,6 +330,10 @@ void moveCR2(Context* c, UNUSED unsigned aSize, lir::Constant* a, if (vm::TargetBytesPerWord == 4 and bSize == 8) { int64_t v = a->value->value(); + if (aSize == 4) { + v = static_cast(v); + } + ResolvedPromise high((v >> 32) & 0xFFFFFFFF); lir::Constant ah(&high); @@ -344,8 +348,16 @@ void moveCR2(Context* c, UNUSED unsigned aSize, lir::Constant* a, maybeRex(c, vm::TargetBytesPerWord, b); opcode(c, 0xb8 + regCode(b)); if (a->value->resolved()) { - c->code.appendTargetAddress(a->value->value()); + int64_t v = a->value->value(); + + if (aSize == 4 and bSize == 8) { + v = static_cast(v); + } + + c->code.appendTargetAddress(v); } else { + expect(c, aSize == vm::TargetBytesPerWord); + appendImmediateTask (c, a->value, offsetPromise(c), vm::TargetBytesPerWord, promiseOffset); c->code.appendTargetAddress(static_cast(0));