-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bounds checks on array/span not eliminated after length check #10596
Comments
This works too: if (3 < (uint)dst.Length)
{
dst[0] = 't';
dst[1] = 'r';
dst[2] = 'u';
dst[3] = 'e';
charsWritten = 4;
return true;
}
charsWritten = 0;
return false; Hmm, maybe I can make it work without the cast to |
Interesting, thanks. Yeah, I see |
Right, that's another thing that can probably be improved in the case of constants. For variables something like |
Off-topic question: How was the disassembly of the method generated? Thanks in advance. |
With a checked build of coreclr (e.g.
|
@dotnet/jit-contrib |
@EgorBo this issue is resolved and can be closed? |
@gfoidl yes, I've just checked, thanks for pointing that out! |
I've got code similar to the following repro:
I was hoping/expecting the bounds checks on each of those four writes to dst to be eliminated, but they’re not:
To work around that, I can use Unsafe.Add and MemoryMarshal.GetReference, e.g.
in which case I get the better:
but it’d be nice not to have to use Unsafe for cases like this.
cc: @AndyAyersMS
Related: https://github.com/dotnet/coreclr/issues/12639
category:cq
theme:range-check
skill-level:intermediate
cost:medium
The text was updated successfully, but these errors were encountered: