Repository navigation
[ILVerify] Implement backward branch verification - #5113
Conversation
| // ECMA III 1.7.5 Backward Branch Constraints | ||
| // if stack is not empty at beginning of this block, | ||
| // there must exist a predecessor block with lower IL offset. | ||
| Check(basicBlock.HasPredecessorWithLowerOffset, VerifierError.BackwardBranch); |
There was a problem hiding this comment.
The basic block can have more than one predecessor. We can be here because we have seen the one with higher offset, but not the one with lower offset yet, and thus report error incorrectly.
Would it be better to this in InitialPass instead? This InitialPass does a single forward scan of IL that this is trying to check for.
There was a problem hiding this comment.
I actually thought that the way the current implementation imports fallthroughs would guarantee that all relevant blocks with lower offsets will be verified first.
But you are right, this is not always the case. I found another test case, which would actually produce such an incorrect error.
I will change this so the HasPredecessor flag is set inside the InitialPass and add the mentioned test case.
|
cc @VSadov |
|
I just noticed that the |
Yes. This instruction is not support by the .NET runtimes, but it does not hurt to have it for completeness. |
I see, that explains why I haven't heard of it yet, haha. Thanks! |
|
The (Interestingly - there is a known hole involving throwing from ctors and then resurrecting uninited instances. Arguably, resurrection is in the same "messy" league as reflection usage though, so not a huge concern ...) Anyways, I think the initialization rules themselves make sense but validation likely just follows from general flow analysis and exception regions are not special. The code that special cases them for the |
|
@VSadov thanks for your insight! |
This implements the verification of backward branches. According to ECMA backward branches require their target blocks to have an empty entry stack or a predecessor block with a lower IL-offset.
In the course of implementing this verification I also implemented the checks for CatchByRef and correct entry stack depth of exception regions.
I also noticed the PEVerify implementation of
THIS_UNINIT_EXCEP, but do not fully understand it:A comment above the relevant code says
// cannot enter a try with an uninitialized 'this', however the code then actually only performs a check for an initialized 'this' if the region is not of typeRGN_TRYorRGN_FAULT. I also couldn't find the definition of this rule in ECMA.(see: https://github.com/lewischeng-ms/sscli/blob/master/clr/src/jit64/newverify.cpp#L1580)