runtime icon indicating copy to clipboard operation
runtime copied to clipboard

ILDASM incorrectly reconstruct EH clauses

Open kyulee1 opened this issue 10 years ago • 3 comments

ILDASM incorrectly reconstruct EH clauses when fTryInCode is true. A part of reason is due to sort which shouldn't be applied -- https://github.com/dotnet/coreclr/blob/master/src/ildasm/dis.cpp#L352 In addition, inserting ".try" clauses into source is not properly implemented. Note passing "-raweh" to just display raw EH tables at the end of method works correctly.

The followings are example assembly. Try ilasm followed by ildasm then EH clauses are reversed -- catching ArithmeticException followed by DivideByZeroException.

.class public _div {
.method public static   int32 _div(int32,int32) {
.locals     (class [mscorlib]System.Exception,int32)
.maxstack       3
try_start:
    ldarg   0
    ldarg   1
    div
    stloc.1
    leave.s try_end
try_end:
    ldloc.1
    br              END
arithmetic:
    isinst          [mscorlib]System.ArithmeticException
    stloc   0
    leave           AEEnd
AEEnd:

    ldloc   0
    brfalse         FAIL
    ldc.i4          0xAE
    br              END
divbyzero:
    isinst          [mscorlib]System.DivideByZeroException
    stloc   0
    leave           DBZEnd
DBZEnd:

    ldloc   0
    brfalse         FAIL
    ldc.i4          0xDB0E
    br              END
FAIL:
    ldc.i4          0x00000000
    br              END
END:
    ret
.try try_start to try_end catch [mscorlib]System.DivideByZeroException handler divbyzero to DBZEnd
.try try_start to try_end catch [mscorlib]System.ArithmeticException handler arithmetic to AEEnd
}

kyulee1 avatar Dec 29 '15 21:12 kyulee1

@kyulee1 If this is not a regression against desktop would you put it in the Future milestone?

russellhadley avatar Apr 06 '16 16:04 russellhadley

Changed it for futher since it's the existing issue in desktop as well.

kyulee1 avatar Apr 06 '16 16:04 kyulee1

Not clear if this issue needs to be fixed. IL catch clause are processed in the order that they are specified and the first one that handled the Object kind handles the exception. It is illegal in C# to have multiple catch clauses that can handle the exception.

As noted the Desktop IL assembler also has this behavior and no one has filed a bug on this .

briansull avatar Sep 28 '20 21:09 briansull