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

Crash in DataFlowAnalysis #27969

Closed
bkoelman opened this issue Jun 18, 2018 · 3 comments · Fixed by #28252
Closed

Crash in DataFlowAnalysis #27969

bkoelman opened this issue Jun 18, 2018 · 3 comments · Fixed by #28252
Assignees
Labels
Area-Compilers Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@bkoelman
Copy link
Contributor

Version Used:
Microsoft.CodeAnalysis v2.8.2

Steps to Reproduce:
Consider the next program, which runs data flow analysis on lambda expression x => true:

using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace RoslynDataFlowCrash
{
    class Program
    {
        static void Main()
        {
            const string source = @"
class C
{
    object P { get; } = Create(nameof(P), x => true);

    static object Create(string name, Func<string, bool> f) => throw null;
}
";

            SyntaxTree tree = CSharpSyntaxTree.ParseText(source);
            var compilation = CSharpCompilation.Create("test.dll", new[] { tree });
            var model = compilation.GetSemanticModel(tree);

            SimpleLambdaExpressionSyntax lambdaSyntax = tree.GetRoot().DescendantNodes().OfType<SimpleLambdaExpressionSyntax>().First();

            DataFlowAnalysis dataFlowAnalysis = model.AnalyzeDataFlow(lambdaSyntax.Body);

            bool succeeded = dataFlowAnalysis.Succeeded; // NullReferenceException
        }
    }
}

Expected Behavior:
No exception.

Actual Behavior:
NullReferenceException. Full stack trace:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Microsoft.CodeAnalysis.CSharp
  StackTrace:
   at Microsoft.CodeAnalysis.CSharp.Binder.AccessingAutoPropertyFromConstructor(BoundExpression receiver, PropertySymbol propertySymbol, Symbol fromMember)
   at Microsoft.CodeAnalysis.CSharp.Binder.AccessingAutoPropertyFromConstructor(BoundPropertyAccess propertyAccess, Symbol fromMember)
   at Microsoft.CodeAnalysis.CSharp.DataFlowPass.VisitPropertyAccess(BoundPropertyAccess node)
   at Microsoft.CodeAnalysis.CSharp.BoundPropertyAccess.Accept(BoundTreeVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitExpressionWithoutStackGuard(BoundExpression node)
   at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionWithStackGuard(Int32& recursionDepth, BoundExpression node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitWithStackGuard(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitAlways(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.Visit(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitNameOfOperator(BoundNameOfOperator node)
   at Microsoft.CodeAnalysis.CSharp.BoundNameOfOperator.Accept(BoundTreeVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitExpressionWithoutStackGuard(BoundExpression node)
   at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionWithStackGuard(Int32& recursionDepth, BoundExpression node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitWithStackGuard(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitAlways(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.Visit(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitArguments(ImmutableArray`1 arguments, ImmutableArray`1 refKindsOpt, MethodSymbol method)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitCall(BoundCall node)
   at Microsoft.CodeAnalysis.CSharp.DataFlowPass.VisitCall(BoundCall node)
   at Microsoft.CodeAnalysis.CSharp.BoundCall.Accept(BoundTreeVisitor visitor)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitExpressionWithoutStackGuard(BoundExpression node)
   at Microsoft.CodeAnalysis.CSharp.BoundTreeVisitor.VisitExpressionWithStackGuard(Int32& recursionDepth, BoundExpression node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitWithStackGuard(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.VisitAlways(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.Visit(BoundNode node)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.Scan(Boolean& badRegion)
   at Microsoft.CodeAnalysis.CSharp.DataFlowPass.Scan(Boolean& badRegion)
   at Microsoft.CodeAnalysis.CSharp.PreciseAbstractFlowPass`1.Analyze(Boolean& badRegion)
   at Microsoft.CodeAnalysis.CSharp.DataFlowPass.Analyze(Boolean& badRegion, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.UnassignedVariablesWalker.Analyze(CSharpCompilation compilation, Symbol member, BoundNode node, Boolean convertInsufficientExecutionStackExceptionToCancelledByStackGuardException)
   at Microsoft.CodeAnalysis.CSharp.CSharpDataFlowAnalysis.get_UnassignedVariables()
   at Microsoft.CodeAnalysis.CSharp.CSharpDataFlowAnalysis.get_DataFlowsIn()
   at Microsoft.CodeAnalysis.CSharp.CSharpDataFlowAnalysis.get_Succeeded()
   at RoslynDataFlowCrash.Program.Main() in E:\Bart\Source\Visual Studio 2017\RoslynDataFlowCrash\RoslynDataFlowCrash\Program.cs:line 29
@bkoelman
Copy link
Contributor Author

Above is a simplified repro. Actual crash was found during analysis of:

        public static PerLanguageOption<bool> UseTabs { get; } =
            new PerLanguageOption<bool>(nameof(FormattingOptions), nameof(UseTabs), defaultValue: false,
                storageLocations: new EditorConfigStorageLocation<bool>("indent_style", s => s == "tab"));

in file .\roslyn\src\Workspaces\Core\Portable\Formatting.FormattingOptions.cs

@gafter gafter added this to the 15.8 milestone Jun 19, 2018
@gafter
Copy link
Member

gafter commented Jun 19, 2018

Thank you for so carefully narrowing down the repro!

@gafter gafter self-assigned this Jun 19, 2018
@gafter
Copy link
Member

gafter commented Jul 2, 2018

Possibly related to #19845

gafter added a commit to gafter/roslyn that referenced this issue Jul 3, 2018
…or property.

Code used to assume it was (and typed it as) a method.
Fixes dotnet#19845
Fixes dotnet#27969
@gafter gafter added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Jul 3, 2018
gafter pushed a commit that referenced this issue Jul 3, 2018
…or property. (#28252)

* Track enclosing symbol in data flow analysis, which might be a field or property.
Code used to assume it was (and typed it as) a method.
Fixes #19845
Fixes #27969
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants