Repository navigation
JIT: don't skip covariant store check for shared sealed element types - #134940
Conversation
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Co-authored-by: EgorBo <[email protected]>
|
@copilot add a jit regression test (no csproj) |
…generics Co-authored-by: EgorBo <[email protected]>
Added in 343cebb: |
|
PTAL @jakobbotsch @dotnet/jit-contrib |
I wonder if this difference is expected or not. Maybe CoreCLR should also report |
It seems like it intentionally does it, but I am not sure why (or rather why ilc/cg2 don't do it) |
In R2R/NativeAOT shared generic code, the JIT removed the covariant array store check when storing a
G<U>into aG<T>[](withGsealed). This let aG<object>be stored into aG<string>[]:Root cause
gtCanSkipCovariantStoreCheckskips the check whenisExactType(elem) && valueHandle == elem. In shared code both handles areG<__Canon>, but they can stand for different runtime types. crossgen2 and ILC report the preciseG<__Canon>[]for the parameter, so the shortcut fires. Plain JIT isn't affected because the VM reports the parameter as__Canon[], which isn't sealed.Change
gentree.cpp: the sealed/handle-equality shortcut now also requires!eeIsSharedInst(arrayElementHandle). This matches the existing shared-type filter in VN's exact-typeIND(obj)folding.G<__Canon>[]stored intoG<__Canon>[][]), because the shared-type flag also applies to arrays of shared types.object[]path and thecompareTypesForCast == Mustpath already return conservative answers for shared types.Impact
G<int>[]) still skip the check.G<T>intoG<T>[]with the sameTnow callsCORINFO_HELP_ARRADDR_ST. Type handles alone can't tell type parameters apart, so there's no cheaper way to keep this correct.