Skip to content

ILDASM incorrectly reconstruct EH clauses #4873

Open

Description

@kyulee1

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
}

Activity

  1. russellhadley commented on Apr 6, 2016

    @russellhadley
    Contributor

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

  2. kyulee1 commented on Apr 6, 2016

    @kyulee1
    ContributorAuthor

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

  3. removed their assignment
    on Sep 15, 2016
  4. transferred this issue fromdotnet/coreclron Jan 30, 2020
  5. added this to the Future milestone on Jan 30, 2020
  6. briansull commented on Sep 28, 2020

    @briansull
    Contributor

    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 .

  7. added
    Priority:3
    on Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:3area-ILTools-coreclrbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions