Repository navigation
Ensure we differentiate between division by zero and overflow - #737
Conversation
|
@jkotas Can you take a look please? |
There was a problem hiding this comment.
It does not look right that this is unsigned - could you please double check it?
Here is a small repro to try:
using System;
using System.Runtime.CompilerServices;
unsafe class My {
[MethodImplAttribute(MethodImplOptions.NoInlining)]
static int foo(int *p) {
return 5/ *(p-1);
}
static void Main() {
int[] a = new int[2];
fixed(int * p = a)
foo(p);
}
}
There was a problem hiding this comment.
I agree, it looks strange. Let me take a look. Btw, this is what we have in the amd64walker.cpp, I haven't functionaly modified this piece.
There was a problem hiding this comment.
It is extremely rare to have negative offset for indirect call target, so if would not be surprising if the amd64walker had a bug. We should fix there too if there is one.
There was a problem hiding this comment.
As expected, it is really incorrect. Just from looking at few compiled instructions:
idiv dword ptr [rax+1] -> f7 78 01
idiv dword ptr [rax-1] -> f7 78 ff
idiv dword ptr [rax-512] -> f7 b8 00 fe ff ff
idiv dword ptr [rax+512] -> f7 b8 00 02 00 00|
Looks good to me otherwise. |
1d64ab4 to
d6d5e98
Compare
|
I've fixed the wrong unsigned offsets (also in the |
|
Oh, the VS copy and paste screwed the formatting of the function comment headers. Let me fix it. |
This change implements parsing of the IDIV instruction operand so that we can find whether an integer division error was a division by zero or an integer overflow. It replaces the previous functionality that was implemented for OSX only and was incomplete (it didn't handle memory operands) and partially incorrect (not handling R8..R15 properly).
d6d5e98 to
ac0ce45
Compare
|
Fixed |
|
Build failure doesn't seem related |
|
@dotnet-bot test this please |
|
LGTM |
Ensure we differentiate between division by zero and overflow
This change implements parsing of the IDIV instruction operand so that
we can find whether an integer division error was a division by zero or
an integer overflow.
It replaces the previous functionality that was implemented for OSX only
and was incomplete (it didn't handle memory operands) and partially incorrect
(not handling R8..R15 properly).
I have reused code from https://github.com/dotnet/coreclr/blob/master/src/debug/ee/amd64/amd64walker.cpp#L27,
but I have enhanced it to be complete w.r.t. the multiple possible operand sizes. The original code was created for parsing
call/jmpoperand where only the 64 bit operand was possible. In theidiv, 8, 16, 32 or 64 bit operands are possible.