How can we help you today? How can we help you today?

Bug in the array type with a negative lower bound.

When we declare a member of a multidimesion array type with a negative lower bound, .NET Reflector could not dump the type correctly.

For example, consider the following code:

.field static string[-1...0] F0

When compiled the code above with ILASM.exe, open the generated assembly in .NET Reflector, we will see the following declaration:

.field compilercontrolled static string[-63..-62] F0

The lower bound of the array is -63, but not the originally declared -1.

I think may be the de-compress arithmetic comes from [Expert .NET 2.0 IL Assembly], which says:

Signed integer values (lower bound values) are compressed according to a different compression procedure. First the signed integer is encoded as an unsigned integer by taking the absolute value of the original integer, shifting it left by 1 bit, and setting the least significant bit according to the most significant (sign) bit of the original value. Then compression is applied according to the formula shown in Table 8-4.

But it is not true.

After observe more negative lower bound, I think the compress arithmetic may be:

First, take the absolute value of the original integer and shift it left by 1 bit, and calculate how many bits should be involved for storing the compressed value.

Second, shift the ORIGINAL integer left by 1 bit, and setting the least significant bit according to the most significant (sign) bit of the original value.

Finally, set the most significant bits of the result according to the number of bytes used to store the compressed value. Set the most significant bit to 0 for the case of using 1 byte to store the compressed value, set the most significant 2 bits to 10 for 2 bytes, and the most significant 3 bits to 110 for 4 bytes.
AndersLiu
0

Add comment

Please sign in to leave a comment.