You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UnsafeAccessorAttribute fails to access volatile field #109665
Unhandled exception. System.MissingFieldException: Field not found: 'A.foo'.
at Program.<<Main>$>g__GetSetFoo|0_0(A args)
at Program.<Main>$(String[] args) in D:\unsafeaccessor\Program.cs:line 5
Regression?
No response
Known Workarounds
No response
Configuration
This seems to be broken both in .NET 8 and .NET 9 with CoreCLR runtime. Tested on Windows and macOS.
Other information
The question of modreqs/modopts came up in the original feature proposal and this was the answer (#81741 (comment)):
And how would this interact with modreqs and modopts that can't be specified in C# (e.g. the IsExternalInit modifier on init property setters / volatile fields etc)?
Yeah, modreqs and modopts would be complicated. I think we will skip modreqs and modopts for the signature match.
This seems to be broken both in .NET 8 and .NET 9 with CoreCLR runtime.
I can repro it on osx-arm64 with .NET 9.0.0 and .NET 10.0.0-alpha.1.24553.1 (dotnet run) but not with .NET 8.0.10. Also, it doesn't repro on sharplab net8.0.
Yep, setting IgnoreCustomModifiers to true makes this work, but the generated accessor isn't going to be correct since we don't currently emit the .volatile prefix for the ldsfld/ldfld instructions. I can see an argument that this is "unsafe" but skipping the .volatile really seems wrong. Let me try and special case volatile.
Activity
dotnet-policy-service commentedon Nov 9, 2024
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices
See info in area-owners.md if you want to be subscribed.
filipnavara commentedon Nov 9, 2024
Additionally, this does work in both .NET 8 and .NET 9 with NativeAOT publishing.
am11 commentedon Nov 10, 2024
I can repro it on osx-arm64 with .NET 9.0.0 and .NET 10.0.0-alpha.1.24553.1 (
dotnet run) but not with .NET 8.0.10. Also, it doesn't repro on sharplab net8.0.jkotas commentedon Nov 10, 2024
cc @AaronRobinsonMSFT
AaronRobinsonMSFT commentedon Nov 11, 2024
This is likely because of
runtime/src/coreclr/vm/prestub.cpp
Line 1501 in 35d2780
It might be the case we should always ignore custom modifiers for fields.
AaronRobinsonMSFT commentedon Nov 11, 2024
Yep, setting
IgnoreCustomModifierstotruemakes this work, but the generated accessor isn't going to be correct since we don't currently emit the.volatileprefix for theldsfld/ldfldinstructions. I can see an argument that this is "unsafe" but skipping the.volatilereally seems wrong. Let me try and special casevolatile.AaronRobinsonMSFT commentedon Nov 11, 2024
Looks like there isn't any need to update the generated getters. See #109694.