[release/8.0] JIT: Disallow mismatched GC-ness for physical promotions (#90739)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Thu, 17 Aug 2023 17:27:20 +0000 (10:27 -0700)
committerGitHub <noreply@github.com>
Thu, 17 Aug 2023 17:27:20 +0000 (10:27 -0700)
commit3ab4246e5a3913786dd846da5cbbfa96435a3243
tree911bed717eaa7dac4306cb8026c75dd918a0689b
parent3924341ea7216d9b313d5d8e0590fbd3dca4be00
[release/8.0] JIT: Disallow mismatched GC-ness for physical promotions (#90739)

* JIT: Disallow mismatched GC-ness for physical promotions

Physical promotion was working under the assumption that reinterpreting
GC pointers is undefined behavior, and would happily promote GC pointers
as integers if it saw such accesses. However, physical promotion is
function wide while the UB accesses can be happening in a restricted
(dynamically unreachable) scope. This exact situation happens in
MemoryExtensions.Contains. The issue was uncovered under jit stress
where we did not fold away the guard early enough, meaning that
promotion then saw a `TYP_LONG` access of a `struct { object, int }` and
proceeded to promote it as such.

Fix #90602

* Address feedback

---------

Co-authored-by: Jakob Botsch Nielsen <jakob.botsch.nielsen@gmail.com>
src/coreclr/jit/layout.cpp
src/coreclr/jit/layout.h
src/coreclr/jit/promotion.cpp