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

Support IntPtr conversions in the method argument rewriter. #11751

Closed
VSadov opened this issue Jun 3, 2016 · 1 comment
Closed

Support IntPtr conversions in the method argument rewriter. #11751

VSadov opened this issue Jun 3, 2016 · 1 comment
Labels
Area-Compilers Bug Language-C# Tenet-Compatibility Violation of forwards/backwards compatibility in a design-time piece.
Milestone

Comments

@VSadov
Copy link
Member

VSadov commented Jun 3, 2016

IntPtr conversion can stay in the bound tree past lowering in a case where a COM method is invoked in an Expression Tree lambda.

A typical situation where this could happen is when a COM method is tested in a mock framework that is Expression Tree based.

If such conversion is seen by the call argument rewriter a crash/watson would result when code is compiled.

Short repro:

using System;
using System.Linq.Expressions;
using System.Runtime.InteropServices;

unsafe class Program
{

    static void Main(string[] args)
    {
        IntPtr y = new IntPtr();

        IAaa i = null;

        Expression<Action> e = () =>  i.Test((ulong)y, null);
    }
}

[ComImport]
[Guid(""A88A175D-2448-447A-B786-64682CBEF156"")]
public interface IAaa
{
    void Test(ulong y, object z);
}

causes a crash like:
CLR: Managed code called FailFast, saying "System.InvalidOperationException: Unexpected value 'IntPtr' of type 'Microsoft.CodeAnalysis.CSharp.ConversionKind'
at Microsoft.CodeAnalysis.CSharp.LocalRewriter.IsSafeForReordering(BoundExpression expression, RefKind kind)
at Microsoft.CodeAnalysis.CSharp.LocalRewriter.BuildStoresToTemps(Boolean expanded, ImmutableArray1 argsToParamsOpt, ImmutableArray1 argumentRefKinds, ImmutableArray1 rewrittenArguments, BoundExpression[] arguments, ArrayBuilder1 refKinds, ArrayBuilder1 storesToTemps) at Microsoft.CodeAnalysis.CSharp.LocalRewriter.MakeArguments(CSharpSyntaxNode syntax, ImmutableArray1 rewrittenArguments, Symbol methodOrIndexer, MethodSymbol optionalParametersMethod, Boolean expanded, ImmutableArray1 argsToParamsOpt, ImmutableArray1& argumentRefKindsOpt, ImmutableArray1& temps, Boolean invokedAsExtensionMethod, ThreeState enableCallerInfo) at Microsoft.CodeAnalysis.CSharp.LocalRewriter.MakeCall(CSharpSyntaxNode syntax, BoundExpression rewrittenReceiver, MethodSymbol method, ImmutableArray1 rewrittenArguments, ImmutableArray1 argumentRefKindsOpt, Boolean expanded, Boolean invokedAsExtensionMethod, ImmutableArray1 argsToParamsOpt, LookupResultKind resultKind, TypeSymbol type, BoundCall nodeOpt)
at Microsoft.CodeAnalysis.CSharp.LocalRewriter.VisitCall(BoundCall node)

@VSadov VSadov added Bug Language-C# Area-Compilers Tenet-Compatibility Violation of forwards/backwards compatibility in a design-time piece. labels Jun 3, 2016
@VSadov VSadov added this to the 1.3 milestone Jun 3, 2016
VSadov added a commit to VSadov/roslyn that referenced this issue Jun 3, 2016
IntPtr conversion can stay in the bound tree past lowering in a case where a COM method is invoked in an Expression Tree lambda.

Fixes: dotnet#11751
@VSadov VSadov changed the title Support IntPtr conversions in method argument rewriter. Support IntPtr conversions in the method argument rewriter. Jun 3, 2016
@VSadov
Copy link
Member Author

VSadov commented Jun 4, 2016

Fixed in #11752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Language-C# Tenet-Compatibility Violation of forwards/backwards compatibility in a design-time piece.
Projects
None yet
Development

No branches or pull requests

1 participant