Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref local variable is inlined incorrectly, changing the exception behavior #2050

Closed
dgrunwald opened this issue Jun 26, 2020 · 0 comments
Closed
Labels
Bug Decompiler The decompiler engine itself
Milestone

Comments

@dgrunwald
Copy link
Member

dgrunwald commented Jun 26, 2020

Input code

using System;
class Program {
    static int GetInt()
    {
        Console.WriteLine("got int");
        return 42;
    }

    int intField;

    static void FieldAccessOrderOfEvaluation(Program c)
    {
        Console.WriteLine("NRE before GetInt:");
        try {
            ref int i = ref c.intField;
            i = GetInt();
        } catch (Exception ex) {
            Console.WriteLine(ex.Message);
        }
    }
}

Erroneous output

    private static void FieldAccessOrderOfEvaluation(Program c)
    {
        Console.WriteLine("NRE before GetInt:");
        try
        {
            c.intField = GetInt();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

This output is wrong because when called with c == null, the GetInt side-effect will happen before the NullReferenceException is throws, whereas in the original code the exception was thrown before GetInt was called.

Expected output

Same as original input.

Details

  • Product in use: e.g. ILSpy
  • Version in use: da905ac
dgrunwald added a commit that referenced this issue Jun 26, 2020
…TargetSlot.

The C# translation of StObj will always apply delayed exceptions in these two cases, so putting an instruction with delayed exceptions in that slot would change program semantics.
@dgrunwald dgrunwald added Bug Decompiler The decompiler engine itself labels Jun 27, 2020
dgrunwald added a commit that referenced this issue Jul 1, 2020
@dgrunwald dgrunwald added this to the v6.1 milestone Jul 11, 2020
dgrunwald added a commit that referenced this issue Sep 2, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

1 participant