-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
JIT/Intrinsics/MemoryMarshalGetArrayDataReference from #72725 fails on Mono JIT #72745
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Well if it gets intrinsified it should emit a null check... runtime/src/mono/mono/mini/intrinsics.c Line 1011 in 1729ca6
So maybe we're running the Interp has a null check too runtime/src/mono/mono/mini/interp/interp.c Line 5507 in 20dd6ea
|
Both AOT and interp pass this test, only JIT fails. And I'd rather assume that an indirect call would run the non-intrinsic version and those calls do correctly NRE. |
For reference, this also fails: [MethodImpl(MethodImplOptions.NoInlining)]
static T NoInline<T>(T t) => t;
_ = ref MemoryMarshal.GetArrayDataReference(NoInline<byte[]>(null)); |
maybe dead code elimination is eliding the null check (I should be in a position to run some tests in a couple of hours. just taking some notes in the meantime) |
I've added some more tests in #72745 that'll show if this is dead code elimination. |
Ok, it's not dce. it's actually the backends runtime/src/mono/mono/mini/mini-amd64.c Lines 4914 to 4915 in aa5ff31
(arm64 is the same)
turns into
So we make it all the way down to register allocation and then the backend cc @vargaz - do we have some other opcode that emits a real load for a null check? |
Call MONO_EMIT_NEW_CHECK_THIS () instead of MONO_EMIT_NULL_CHECK () the latter only seems to work if exlicit null checks are enabled. |
Is that ok to call on something that isn't really It's messing with CFG flags...
Ah interesting. the only side-effect is that we run array bounds check removal on the method |
…ataReference using MONO_EMIT_NULL_CHECK does not emit a null check in the backend if the pointer is otherwise unused Fixes dotnet#72745
Could this affect other places if it's not exactly specific to this intrinsic then @lambdageek? |
I took a quick glance over the other intrinsics and it doesn't seem like others would be affected. The atomic intrinsics, for example, perform an actual load/store which would produce a It was only a problem here because |
The change seems to have made LLVM AOT fail when compiling the tests now, see #72725. |
Description
A test introduced in #72725 shows that Mono JIT in some cases doesn't throw NRE on null array passed to MemoryMarshal.GetArrayDataReference.
Reproduction Steps
Expected behavior
NullReferenceException.
Actual behavior
No exceptions.
Regression?
Works on CoreCLR.
Known Workarounds
Indirect calls to GetArrayDataReference via a function pointer do throw NRE.
Configuration
mono minijit Pri0 Runtime Tests Run OSX x64 release
job.Other information
No response
The text was updated successfully, but these errors were encountered: