Do not promote struct field with type mistmatch. (#20085)
authorSergey Andreenko <seandree@microsoft.com>
Tue, 9 Oct 2018 22:03:19 +0000 (15:03 -0700)
committerGitHub <noreply@github.com>
Tue, 9 Oct 2018 22:03:19 +0000 (15:03 -0700)
commit13dc153a7718a6d9297b757f5969c403856ef618
treeccfbfa39dbb80f6441bd821f0a3ff3c4d4f0bc1d
parent36c9dd8e269a9ca8da203622fccde98ce476ffaa
Do not promote struct field with type mistmatch. (#20085)

* Add a test that reads int field as double.

It fails in `void CodeGen::genCodeForStoreInd(GenTreeStoreInd* tree)`  on `assert(!varTypeIsFloating(targetType) || (targetType == data->TypeGet()));`.

* Fix for the previous test.

No asm diffs.

* Add a test that reads struct field as another struct type.

It fails with assert `Compiler::StructPromotionHelper::CheckFakedType` `assert(fakedFieldsMap.Lookup(fieldHnd));`.

* Fix the previous test.

Check that we promote with the same class.

* Add a test case for accessing an invalid offset.

It fails in `fgMorphStructField` with `noway_assert(fieldLclIndex != BAD_VAR_NUM);`.

* Fix the previous test.

Reject field promotion if offset is invalid. No asm diffs.
src/jit/morph.cpp
tests/src/JIT/Directed/StructPromote/Unsafe/AccessInvalidFieldOffset.cs [new file with mode: 0644]
tests/src/JIT/Directed/StructPromote/Unsafe/AccessInvalidFieldOffset.csproj [new file with mode: 0644]
tests/src/JIT/Directed/StructPromote/Unsafe/ReadDoubleFromIntOffset.cs [new file with mode: 0644]
tests/src/JIT/Directed/StructPromote/Unsafe/ReadDoubleFromIntOffset.csproj [new file with mode: 0644]
tests/src/JIT/Directed/StructPromote/Unsafe/ReadStructAsAnotherType.cs [new file with mode: 0644]
tests/src/JIT/Directed/StructPromote/Unsafe/ReadStructAsAnotherType.csproj [new file with mode: 0644]