Fix compiler crashes for invalid IL sequences (#81940)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Fri, 10 Feb 2023 08:15:47 +0000 (17:15 +0900)
committerGitHub <noreply@github.com>
Fri, 10 Feb 2023 08:15:47 +0000 (17:15 +0900)
commit254355fd5327a7a9173c912f1c713b96bbd84b54
tree47c1385dae97c4be5821a781961eb1d8bf6bf44b
parentba1d6253f058c0ddc3399119dd1ec52017b704d7
Fix compiler crashes for invalid IL sequences (#81940)

The JIT test tree has many tests that test invalid IL. We were crashing on some of them in optimized builds.

The problem is that optimized builds look at the program twice - first time when building whole program view, and second time for codegen. The whole program view building doesn't look at the IL in detail and doesn't need to detect invalid IL like "filter block that doesn't end with endfilter". At the same time, scanning phase must precompute the whole world, including situations when invalid code is going to be replaced by a call to a throw helper.

We were ending up in situations where the throw helper was not predicted and we didn't even know how the vtable of `InvalidProgramException` should look like (because it wasn't scanned). A simple fix is to always generate the helper. It's a bit of garbage 99% of time, but probably fine.
src/coreclr/tools/aot/ILCompiler/ILCompiler.props
src/coreclr/tools/aot/ILCompiler/Program.cs