Allow {iput,sput}-boolean on a byte value.
javac generates code that can only be understood as storing a byte value
into a boolean field. The verifier now allows this.
diff --git a/vm/analysis/CodeVerify.c b/vm/analysis/CodeVerify.c
index 0ab36ea..5bb546a 100644
--- a/vm/analysis/CodeVerify.c
+++ b/vm/analysis/CodeVerify.c
@@ -1941,6 +1941,13 @@
*
* Assumes we've already validated reg1/reg2.
*
+ * TODO: consider generalizing this. The key principle is that the
+ * result of a bitwise operation can only be as wide as the widest of
+ * the operands. You can safely AND/OR/XOR two chars together and know
+ * you still have a char, so it's reasonable for the compiler or "dx"
+ * to skip the int-to-char instruction. (We need to do this for boolean
+ * because there is no int-to-boolean operation.)
+ *
* Returns true if both args are Boolean, Zero, or One.
*/
static bool upcastBooleanOp(RegType* insnRegs, const int insnRegCount,
@@ -4421,9 +4428,17 @@
ClassObject* fieldClass;
InstField* instField;
- /* make sure the source register has the correct type */
srcType = getRegisterType(workRegs, insnRegCount, decInsn.vA,
&failure);
+
+ /*
+ * javac generates synthetic functions that write byte values
+ * into boolean fields.
+ */
+ if (tmpType == kRegTypeBoolean && srcType == kRegTypeByte)
+ srcType = kRegTypeBoolean;
+
+ /* make sure the source register has the correct type */
if (!canConvertTo1nr(srcType, tmpType)) {
LOG_VFY("VFY: invalid reg type %d on iput instr (need %d)\n",
srcType, tmpType);
@@ -4676,11 +4691,19 @@
RegType srcType, fieldType;
StaticField* staticField;
- /* make sure the source register has the correct type */
srcType = getRegisterType(workRegs, insnRegCount, decInsn.vA,
&failure);
+
+ /*
+ * javac generates synthetic functions that write byte values
+ * into boolean fields.
+ */
+ if (tmpType == kRegTypeBoolean && srcType == kRegTypeByte)
+ srcType = kRegTypeBoolean;
+
+ /* make sure the source register has the correct type */
if (!canConvertTo1nr(srcType, tmpType)) {
- LOG_VFY("VFY: invalid reg type %d on iput instr (need %d)\n",
+ LOG_VFY("VFY: invalid reg type %d on sput instr (need %d)\n",
srcType, tmpType);
failure = VERIFY_ERROR_GENERIC;
break;