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-return of dynamic expression emits local variable address return #16947

Closed
controlflow opened this issue Feb 4, 2017 · 2 comments
Closed

Comments

@controlflow
Copy link

Version Used:

master branch @ February 4

Steps to Reproduce:

  1. Compile the following code:
class C {
  ref object D(dynamic d) => ref d.Something;
}
  1. See the emitted code returning the address of local variables slot:
        ...
        IL_0046: callvirt instance !2 class [mscorlib]System.Func`3<class [System.Core]System.Runtime.CompilerServices.CallSite, object, object>::Invoke(!0, !1)
        IL_004b: stloc.0
        IL_004c: ldloca.s 0 // address of 'object' local variable used to capture the result of dynamic expression
        IL_004e: ret        // boom!
    }

Expected Behavior:

The analysis of local address returns should think of references taken with ref expression from dynamic values as locally-allocated. The result of dynamic expression always behaves like "temporary", local expression.

cc @gafter

@VSadov
Copy link
Member

VSadov commented Feb 4, 2017

cc @jaredpar - for triage.

Another example:

public class C 
{
    public void M() 
    {
        dynamic d = "qq";
        
        foo(ref d.Length);
    }
    
    public static ref dynamic foo(ref dynamic d)
    {
        return ref d;
    }
}

@controlflow
Copy link
Author

The same with ref from indexer access:

class C {
  ref object D(dynamic d) => ref d[42];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants