-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Make remaining managed pointer type scenarios warnings #64294
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
Conversation
a1bb112 to
85e5ecd
Compare
|
/azp run In reply to: 1259913235 |
|
Azure Pipelines successfully started running 4 pipeline(s). In reply to: 1259913936 |
| diagnostics.Add(ErrorCode.ERR_ManagedAddr, location, type); | ||
| return true; | ||
| } | ||
| diagnostics.Add(ErrorCode.WRN_ManagedAddr, location, type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also do a LangVersion check so that people on old language versions can't suppress these #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good idea. I'll do a runtime rebuild tonight to verify they don't have a project with managed pointers and LangVer<11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following conversation with Jared, I added a LangVer check. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from the LangVersion concern.
| diagnostics.Add(ErrorCode.WRN_ManagedAddr, location, type); | ||
| } | ||
|
|
||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, the method comment should be updated to reflect the new behavior.
Should this be In reply to: 1262856400 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:8675 in 39a1e43. [](commit_id = 39a1e43, deletion_comment = False) |
This reverts commit 39a1e43.
From offline discussion, it sounds like these In reply to: 1262902999 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:1482 in 39a1e43. [](commit_id = 39a1e43, deletion_comment = False) |
Perhaps "Dev10 and Roslyn produce diagnostics here." In reply to: 1262923374 In reply to: 1262923374 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/UnsafeTests.cs:8387 in 39a1e43. [](commit_id = 39a1e43, deletion_comment = False) |
|
Command 'run
In' is not supported by Azure Pipelines.
See additional documentation. |
This is just a comment in an existing test. I'll leave as-is In reply to: 1262923374 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/UnsafeTests.cs:8387 in 39a1e43. [](commit_id = 39a1e43, deletion_comment = False) |
dotnet/roslyn#64294 Compiler now issues warnings for pointer operations involving managed types
dotnet/roslyn#64294 Compiler now issues warnings for pointer operations involving managed types
* Patches for scoped locals dotnet/roslyn#64093 This change enforced that `scoped` on a local set the escape scope to the current block where previously it was incorrectly setting to the containing method. * Make return and out equivalent for ref safety dotnet/roslyn#64318 This change allows anything returnable from a method to be assigned to an `out` parameter. In several places had to add `scoped` to `ref` to inform compiler they could not be captured in an `out` parameter. * Warnings on managed pointer types dotnet/roslyn#64294 Compiler now issues warnings for pointer operations involving managed types * Update compiler version * PR feedback * Ref safety rules attribute Co-authored-by: Charles Stoner <[email protected]>
* Patches for scoped locals dotnet/roslyn#64093 This change enforced that `scoped` on a local set the escape scope to the current block where previously it was incorrectly setting to the containing method. * Make return and out equivalent for ref safety dotnet/roslyn#64318 This change allows anything returnable from a method to be assigned to an `out` parameter. In several places had to add `scoped` to `ref` to inform compiler they could not be captured in an `out` parameter. * Warnings on managed pointer types dotnet/roslyn#64294 Compiler now issues warnings for pointer operations involving managed types * Update compiler version * Fixup * Ref safety rules attribute Co-authored-by: Charles Stoner <[email protected]>
|
@jcouv in the following code, X1 warns twice, while X2 warns just once for the right hand side. is this expected? using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public ref struct StackAllocatedByRefs
{
internal ref byte arg;
}
public class C
{
public void X1()
{
StackAllocatedByRefs byrefStorage = default;
unsafe
{
StackAllocatedByRefs* x = &byrefStorage;
}
}
public void X2()
{
StackAllocatedByRefs byrefStorage = default;
unsafe
{
var x = &byrefStorage;
}
}
} |
Corresponding spec change: dotnet/csharplang#6492
Corresponding proposal: dotnet/csharplang#6476
Note: from follow-up discussion with Chuck and David, we need to keep the stackalloc scenario an error, as the runtime doesn't support it.