Repository navigation
Description
Description
When passing a struct to a method on a class, if there is a second parameter of interface type and an instance of a struct implementing that interface is passed in as the second parameter, then if stepping into the record constructor of the struct and then stepping into the method using a debugger via VS Code or Visual Studio for Mac two of the fields of the first parameter are set to null.
This change in the value is "real" and not a visual bug in the debugger, attempting to access or read that value will confirm this.
Note that the bug was detected whilst running code without a debugger, when inexplicable null values were detected deeper in the call stack. So under certain conditions it happens even without stepping in the debugger, but this is a reliable repro.
Reproduction Steps
To produce the bug: place breakpoint on the first line, step into the constructor of the record, then step into the method Z::Foo, inspect the method argument obj and X::D and X::E have been set to null.
The second line which passes new B() instead of new A() does not have this issue.
Also placing breakpoint within Z::Foo and running directly to that point (do not step into record constructor) will NOT produce the bug.
Not related to using record struct, same problem with a regular struct.
new Z().Foo(new X(8, "hello", "world", "cool", "stuff", "baby"), new A());
new Z().Foo(new X(8, "hello", "world", "cool", "stuff", "baby"), new B());
sealed class Z
{
public void Foo(X obj, IA service)
{
Console.WriteLine(string.Join(" ", obj.A, obj.B, obj.C, obj.D, obj.E, obj.F));
}
}
public readonly record struct X(uint A, string B, string C, string D, string E, string F);
interface IA
{
bool Bar();
}
readonly struct A : IA
{
public readonly bool Bar() => true;
}
class B : IA
{
public bool Bar() => true;
}
Expected behavior
When an instance of a plain struct is passed to a method, it is expected that the copy of the struct should arrive whole and intact -- i.e. some fields should not suddenly go missing or be altered.
Actual behavior
Under certain conditions, when passing an instance of a struct to method, some of the fields of the struct are missing in the copy of the instance accessible from within the method.
Regression?
No response
Known Workarounds
No response
Configuration
.net version: 7.0.304
OS: macOS Ventura 13.4.1
Arch: x64
VS Code and Visual Studio for Mac both exhibit the same behaviour.
Other information
No response
Activity
filipnavara commentedon Aug 1, 2023
I tried it on SDKs 7.0.306 and 8.0.100-preview.7. It didn't repro on my macOS machine in either x64 or arm64 builds.
AndyAyersMS commentedon Aug 1, 2023
@odyssjii was this with a debug or release build?
odyssjii commentedon Aug 2, 2023
@AndyAyersMS This is with debug build.
Here is repro in VS Code on a different machine also running macOS:
dotnet version: 7.0.304
MSBuild version 17.6.3+07e294721 for .NET
macOS Ventura 13.4.1
Note that both of the machines are Apple computers with Intel CPUs.
jakobbotsch commentedon Aug 2, 2023
Do I understand correctly that this only repros under the debugger and requires stepping in a very specific pattern?
Do you happen to have an example that doesn't require attaching and stepping with a debugger? It sounds likely these could be two separate issues.
odyssjii commentedon Aug 3, 2023
Hi @jakobbotsch ! I will try to construct a repro that does not require the stepping in with a debugger. It is not as straightforward though, I still don't know under what condition that happens.
jakobbotsch commentedon Aug 3, 2023
Thanks @odyssjii! If you are able to reproduce it without a debugger it would definitely indicate some sort of codegen bug. Sadly I don't have an Intel Mac and it seems like VSCode/OmniSharp does not support debugging with an SDK running under Rosetta, so I cannot try it while stepping.
@dotnet/jit-contrib Anyone with an Intel Mac who wants to see if they are able to repro it? I've looked at the x64 debug codegen on my Mac and I do not see anything suspicious. I've also tried reproducing it when stepping on Ubuntu x64 (which should be the exact same codegen since it's the same ABI), but haven't had luck.
17 remaining items
jakobbotsch commentedon Aug 9, 2023
I'm going to move this to 9.0 and mark it as needing author action since there is nothing actionable from the codegen side at this point. Will happily take another look once a repro case that doesn't involve the debugger/stepping is provided.
mikem8361 commentedon Aug 10, 2023
It doesn't repro if COMPlus_EnableAVX=0. If does also repro on .NET 8 even with the AVX PR ##89705 changes.
jakobbotsch commentedon Aug 10, 2023
Ok, so the summary is that the repro case posted is a duplicate of #78991. We still need to determine whether there is a codegen issue, but we need a repro case that doesn't involve stepping or more details to do that.