Fix crossgen2 skipped methods NullReferenceException (dotnet/coreclr#27028)
authorSimon Nattress <nattress@gmail.com>
Thu, 10 Oct 2019 00:11:42 +0000 (17:11 -0700)
committerGitHub <noreply@github.com>
Thu, 10 Oct 2019 00:11:42 +0000 (17:11 -0700)
commitf7c9e537454938d1736edf6a08c6aa4199f82838
tree3de4402d7e54f168e4a8690f0c7618d65516e2d5
parent80cb4348961ad4e3d43f4c40d505d27df545699b
Fix crossgen2 skipped methods NullReferenceException (dotnet/coreclr#27028)

* Fix crossgen2 skipped methods NullReferenceException

https://github.com/dotnet/coreclr/pull/26756 introduced skipping methods based on filtering criteria, publishing empty code for methods which are skipped.
`ShouldSkipCompilation` reads properties on types and methods and can trigger type loads and thus throw `TypeLoadException`. Currently when that happens, we will not publish empty code for the method and hit the catch in `ComputeDependencyNodeDependencies`. Later when the node is scanned for dependencies, it is in a zombie state with `_methodCode` still null.

Move the `ShouldSkipCompilation` check under the `CompileMethodInternal` try/catch which will appropriately call `PublishEmptyCode` if there's a `TypeSystemException`.

Commit migrated from https://github.com/dotnet/coreclr/commit/56a97e6dc5d6ac7d413edf6ca8ab28fa77b1f255
src/coreclr/src/tools/crossgen2/Common/JitInterface/CorInfoImpl.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs