File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -289,8 +289,22 @@ public MethodIL GetMethodILWithInlinedSubstitutions(MethodIL method)
289289 if ( delta >= 0 && delta < ehRegion . TryLength )
290290 {
291291 if ( ehRegion . Kind == ILExceptionRegionKind . Filter )
292+ {
292293 offsetsToVisit . Push ( ehRegion . FilterOffset ) ;
293294
295+ // Filter must end with endfilter, so ensure we don't accidentally remove it.
296+ // ECMA-335 dictates that filter block starts at FilterOffset and ends at HandlerOffset.
297+ int expectedEndfilterLocation = ehRegion . HandlerOffset - 2 ;
298+ bool isValidFilter = expectedEndfilterLocation >= 0
299+ && ( flags [ expectedEndfilterLocation ] & OpcodeFlags . InstructionStart ) != 0
300+ && methodBytes [ expectedEndfilterLocation ] == ( byte ) ILOpcode . prefix1
301+ && methodBytes [ expectedEndfilterLocation + 1 ] == unchecked ( ( byte ) ILOpcode . endfilter ) ;
302+ if ( isValidFilter )
303+ {
304+ flags [ expectedEndfilterLocation ] |= OpcodeFlags . VisibleBasicBlockStart | OpcodeFlags . Mark ;
305+ }
306+ }
307+
294308 offsetsToVisit . Push ( ehRegion . HandlerOffset ) ;
295309
296310 // RyuJIT is going to look at this basic block even though it's unreachable.
You can’t perform that action at this time.
0 commit comments