Add back missing conv opcodes when compiling via System.Linq.Expressions (#76024)
authorVlad Brezae <brezaevlad@gmail.com>
Sat, 24 Sep 2022 06:23:23 +0000 (09:23 +0300)
committerGitHub <noreply@github.com>
Sat, 24 Sep 2022 06:23:23 +0000 (09:23 +0300)
commit05aa1fdf72daa876e482f3a762d72d40e82c50b8
tree0d7f4f83c62868fa2d18e61d42cb1bbcd95bb8da
parent901b0a1ee23c441e255acaf032adbf709f36d6a6
Add back missing conv opcodes when compiling via System.Linq.Expressions (#76024)

* Add new convert tests

With expression funcs that return int32 instead of short/byte to prevent implicit conversions.

* Add back missing conv opcodes when compiling via System.Linq.Expressions

The conversion opcodes are still necessary when the sign of the value might change, in which case the conversion opcode will do a sign/zero extend to the full i32 storage used by the IL execution stack.

For example, before this change, conversions from ushort to short were ignored. Consider expressions converting the value `ushort.MaxValue` to short (testcase ConvertUShortToShortTest). `ushort.MaxValue` will be pushed to execution stack as a i32 ldc of value 0xffff. The conv.i2 opcode would change the value on the stack to 0xffffffff so it shouldn't be omitted.
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/ILGen.cs
src/libraries/System.Linq.Expressions/tests/Convert/ConvertTests.cs