Skip to content

Commit 71bd3ac

Browse files
Make sure not to strip endfilter (#86374)
Fixes the issue described in #86304 (but doesn't fix the issue because that's for ILLink). Found by Pri0 tests.
1 parent a5a485c commit 71bd3ac

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/FeatureSwitchManager.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)