dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.95k stars 4.02k forks source link

Nullable flow tracking doesn't work through pointer dereference #65634

Open stephentoub opened 1 year ago

stephentoub commented 1 year ago

Version Used: https://github.com/dotnet/roslyn/commit/07c6b71f9d061a28296b5c6791c4f60014356784

Steps to Reproduce: SharpLab

#pragma warning disable 8500
using System.Diagnostics;

public unsafe class C
{
    public string M(Data* data)
    {
        Debug.Assert(data->Value is not null);
        return data->Value;
    }
}

public struct Data
{
    public string? Value;
}

Expected Behavior:

No warning.

Actual Behavior:

warning CS8603: Possible null reference return.

RikkiGibson commented 1 year ago

I think fixing this would require us to treat the pointed-at variable as a child slot of the pointer variable.