Open suriyadi15 opened 3 years ago
This problem has been solved. Change this code error code with solved code.
This problem because use IF
function, and I replace it with a custom function.
I wonder if this could be the same reason IIS is crashing for some people on 64 bit.
Your function will have worse performance as all the expressions need to be evaluated whereas the built-in only evaluates the needed expresion.
I reproduced this on .Net Framework 4.7.2 without the AND function: "IF(2.1<>2.1,IF(2.1>2.1,2.1,IF(2.1>2.1 AND 2.1<=2.1,2.1,IF(2.1>2.1 AND 2.1<=2.1,2.1,2.1))),IF(2.1>2.1,2.1,IF(2.1>2.1 AND 2.1<=2.1,2.1,IF(2.1>2.1 AND 2.1<=2.1,2.1,2.1))))"
I believe the problem is in BranchManager.ComputeBranches()
. This is where the branch addresses are adjusted for long branches vs short branches, but there is an edge case that isn't handled. It seems to only support one depth level of branches going from a short to a long branch. So you if have a long branch that starts inside a short branch, and the extra bytes from that branch cause the short branch to become a long branch, that is handled, But if the short branch that becomes a long ALSO starts within a short branch, that 2nd level short branch also needs to be extended and may also need to become a long branch. But that adjustment is never made.
I'm working on it to see if I can find a fix.
Turns out this is messier than I hoped. ComputeBranches
is never called with more than 2 branches, so the possible problems I could see won't manifest.
However, the problem is definitely similar to what I described: nested long branches. Nested conditionals don't generate their correct length until the final time they are compiled.
In order to detect long branches, Flee generates the IL in a temporary mode, will all short branches. But as it breaks the code down it doesn't gather ALL the branches into one array and test them, it on tests at the top of the current level. The offsets are wrong because if there is a long branch inside a conditional expression (a conditional in a conditional in a conditional....) it doesn't do the adjustment for the branches until the 2nd time through, but that time the top level expects the size to be the same, but it isn't so the long branch detection fails.
I have implemented a fix, but it involves outputting NOP in the temp mode generation. This reduces the work of generating code at the lower levels over what exists in the current repo, but it could be better.
Another approach which would track all branches from the very top level, and then fix up all branches and compile only twice the entire expression. Currently, nested expressions can be compiled more than twice. However, since ComputeBranches is only suited for 2 branches, this would require a lot more work and a lot more structural changes maintain a single list of branches. (I think ComputeBranches could work if the branches were sorted in reverse order by start location)
My patch is available in this repo: https://github.com/hunkydoryrepair/Flee
I can submit a pull request unless somebody wants to invest into a better solution.
I use .NET Core 2.0 and this is the code:
The exception throw
I just changed
2
to2.1
and it doesn't work. How to solve this?