Commit c22c179
Fix latent stale gtCompileTimeHandle poisoning EmbeddedHandleMap
`GenTree::BashToConst<T>` repurposes an arbitrary node into a constant but
never resets `AsIntCon()->gtCompileTimeHandle`, so the field retains stale
data from the node's prior life. `optConstantAssertionProp` then re-applies
`GTF_ICON_CLASS_HDL` on top of the bashed node based on the VN's handle
flags, leaving a CNS_INT with `iconValue = realClassHandle`, the class-handle
flag set, but a stale `gtCompileTimeHandle`.
When `fgValueNumberTreeConst` later sees this node it overwrites the
existing entry in the EmbeddedHandleMap with that stale handle (via
`AddOrUpdate`), poisoning lookups. Consumers such as `IsVNTypeHandle` and
`VNEvalForCast` then read the garbage back, and `compareTypesForCast`
crashes when dereferencing the bogus type handle.
Three small fixes:
1. `GenTree::BashToConst<T>`: zero `gtCompileTimeHandle` alongside the
existing `gtFieldSeq = nullptr`, matching the "node is now a fresh
constant" semantics.
2. `fgValueNumberTreeConst`: only register an entry in the
EmbeddedHandleMap when `gtCompileTimeHandle != 0`, so a re-flagged
bashed node cannot overwrite a valid mapping placed by a real
`gtNewIconEmbHndNode` that shares the same iconValue.
3. `fgValueNumberSpecialIntrinsic`: fix an inverted bail-out that proceeds
to `getRuntimeTypePointer` with a 0 handle when the map lookup fails
(`&&` + `clsHandle != 0` made the bail unreachable because `clsHandle`
is initialized to 0). With fix #2, "no entry" becomes more common, and
this site must bail explicitly.
Reproduced on System.Memory.Tests / System.Linq.Tests with
DOTNET_TieredCompilation=1 against the PR's `IsVNTypeHandle` consumer.
Tests pass after the fix.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 9e37596 commit c22c179
2 files changed
Lines changed: 12 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2101 | 2101 | | |
2102 | 2102 | | |
2103 | 2103 | | |
2104 | | - | |
| 2104 | + | |
| 2105 | + | |
2105 | 2106 | | |
2106 | 2107 | | |
2107 | 2108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12287 | 12287 | | |
12288 | 12288 | | |
12289 | 12289 | | |
12290 | | - | |
| 12290 | + | |
12291 | 12291 | | |
| 12292 | + | |
| 12293 | + | |
| 12294 | + | |
| 12295 | + | |
12292 | 12296 | | |
12293 | 12297 | | |
12294 | 12298 | | |
| |||
14430 | 14434 | | |
14431 | 14435 | | |
14432 | 14436 | | |
14433 | | - | |
14434 | | - | |
14435 | | - | |
| 14437 | + | |
| 14438 | + | |
| 14439 | + | |
| 14440 | + | |
| 14441 | + | |
14436 | 14442 | | |
14437 | 14443 | | |
14438 | 14444 | | |
| |||
0 commit comments