Fix assert in NativeAOT when handling data flow on compiler generated code. (#73085)
authorVitek Karas <10670590+vitek-karas@users.noreply.github.com>
Mon, 1 Aug 2022 05:35:14 +0000 (22:35 -0700)
committerGitHub <noreply@github.com>
Mon, 1 Aug 2022 05:35:14 +0000 (14:35 +0900)
commit75abdd41a2521e6752c78e83f68498b205f057ab
tree6b07bb749cbc86bddba074b607f9ccd1560a30d5
parent508fef51e841aa16ffed1aae32bf4793a2cea363
Fix assert in NativeAOT when handling data flow on compiler generated code. (#73085)

The problem occurs when an entire type/assembly is preserved through explicit rooting (command line, rd.xml, ...). If such type contains a local function (for example) which is only called from a branch which is going to be removed by constant-prop/branch removal the internal tracking of compiler generated methods will see this local function as orphaned (not belonging to any user method). This leads to a case where we will try to run data flow on the local function - but that should never happen for compiler generated methods directly -> assert.

The fix is (just like in the linker), to never run data flow on compiler generated methods directly - they should only run data flow as part of their respective user method.

Fixes https://github.com/dotnet/runtime/issues/73027
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs