Handle RunClassConstructor with nonreflectable cctor (#62947)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Sat, 18 Dec 2021 04:59:42 +0000 (13:59 +0900)
committerGitHub <noreply@github.com>
Sat, 18 Dec 2021 04:59:42 +0000 (13:59 +0900)
commit118349fa452bf952946cbecc53dc46444f2493a3
tree859a0ba83d4e05ea9cd2d451386ec3661daf5293
parent5e9381cabf2dfffeb58e28fa1067da88c31aa5bf
Handle RunClassConstructor with nonreflectable cctor (#62947)

This is now getting hit in #62927, so it's somewhat more urgent. (The feature switches from the SDK put us into the situation that triggers this bug around `RunClassConstructor` on an otherwise unused type.)

Fixes dotnet/runtimelab#987.

Remember what class constructor contexts we saw during scanning phase and if the owning type is also generated, assume `RunClassConstructor` could be used and ensure the cctor context is also generated in the compilation phase.

This is somewhat less precise, but introducing a new node type for "a type used with `RunClassConstructor`" that dataflow analysis could report doesn't seem worth it.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/AnalysisBasedMetadataManager.cs
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs
src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs