-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Forward substitution for relops can create new data races #62048
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsReproduction: public class Program
{
private static int _intStatic;
private static void Main()
{
for (int i = 0; i < Environment.ProcessorCount; i++)
{
new Thread(() =>
{
while (true)
{
Volatile.Write(ref _intStatic, 0);
Volatile.Write(ref _intStatic, 1);
}
}).Start();
}
while (true)
{
Problem(ref _intStatic);
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static void Problem(ref int a)
{
var b = Volatile.Read(ref a) == 0;
var c = b;
if (b)
{
Assert(c);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Assert(bool b)
{
if (!b)
{
throw new Exception("!!!");
}
}
} Eventually this program will throw an exception, even as one would think it never should. This cause is that in the branch forward substitution optimization, we copy the indirection and end up with two indirections (that can, naturally, disagree). It is unclear to me whether this new behavior can be considered correct or not. @dotnet/jit-contrib
|
Thanks for pointing this out. We should be more careful here. |
The copy may not get the same value as the original. Closes dotnet#62048.
The copy may not get the same value as the original. Detect this by looking for `GTF_ORDER_SIDEEFF`. Closes #62048.
Reproduction:
Eventually this program will throw an exception, even as one would think it never should.
The cause is that in the branch forward substitution optimization, we copy the indirection and end up with two indirections (that can, naturally, disagree).
It is unclear to me whether this new behavior can be considered correct or not.
@dotnet/jit-contrib
The text was updated successfully, but these errors were encountered: