Is add operation on object reference valid? #65793
Unanswered
buybackoff
asked this question in
Q&A
Replies: 2 comments 13 replies
-
Sounds like what |
Beta Was this translation helpful? Give feedback.
5 replies
-
@buybackoff It is not supported, this seems like a mistake in the standard (though you'll note this is "informative text"). E. g. if I ran the following through RyuJit built with assertions, it'll fail: [MethodImpl(MethodImplOptions.NoInlining)]
private static ref int Problem(ClassWithFields a)
{
IL.Emit.Ldarg(0);
IL.Emit.Ldc_I4(4);
IL.Emit.Conv_I();
IL.Emit.Add();
return ref IL.ReturnRef<int>();
}
Relying on illegal IL being accepted is undefined behavior and is not supported. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
ECMA 335 says in one place in parentheses that addition is supported for

O
types.Other places say that's it's not OK.

We have a discussion on the fastest and still correct way to read array elements without bound checks here: disruptor-net/Disruptor-net#65
In the following implementation, is it OK to use the result of
ldind.ref
as a managed pointer and add offset to it? Is the result a GC-tracked managed pointer?Asking specifically for
#if NETCOREAPP
, on Mono it blows up (and onnet48
it works but it's not that important so could take safe slower path as with Mono and use simple if-def).Beta Was this translation helpful? Give feedback.
All reactions