-
Couldn't load subscription status.
- Fork 602
Add Slice to Csharp --enable-analysis #4617
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR adds support for enabling static analysis in the C# code generator (slice2cs) and fixes several code quality issues identified by the analyzers.
Key changes:
- Added
--enable-analysisflag to slice2cs compiler to optionally suppress the<auto-generated>tag and enable analyzer warnings - Fixed threading issue in
ProgressCallback.Report()by directly setting private fields instead of using properties - Improved code clarity with better variable naming and added parentheses for operator precedence
- Added missing period in documentation comment
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| slice/IceGrid/Descriptor.ice | Added missing period to documentation comment |
| csharp/test/Ice/executor/AllTests.cs | Renamed parameter from sentSynchronously to value for clarity |
| csharp/test/Ice/ami/AllTests.cs | Fixed concurrency issue by directly setting backing fields in Report() method |
| csharp/test/Directory.Build.props | Added MSBuild configuration to pass --enable-analysis flag to slice compiler |
| csharp/src/Directory.Build.props | Added MSBuild configuration to pass --enable-analysis flag to slice compiler |
| cpp/src/slice2cs/Main.cpp | Added command-line option --enable-analysis and passes it to Gen constructor |
| cpp/src/slice2cs/Gen.h | Updated Gen constructor signature to accept enableAnalysis parameter |
| cpp/src/slice2cs/Gen.cpp | Implemented analysis mode logic and applied analyzer-suggested improvements |
| cpp/src/slice2cs/CsUtil.cpp | Added parentheses for clarity in arithmetic expressions |
| .github/workflows/ci.yml | Enabled analysis in Windows debug build configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _sentSynchronously = value; | ||
| _sent = true; |
Copilot
AI
Oct 29, 2025
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.
The Report() method directly sets the backing fields without acquiring the lock on _mutex, while the corresponding properties use locking. This creates a race condition where one thread could read via the properties while another writes via Report(). The direct field assignments should be wrapped in lock (_mutex) to maintain thread safety.
| _sentSynchronously = value; | |
| _sent = true; | |
| lock (_mutex) | |
| { | |
| _sentSynchronously = value; | |
| _sent = true; | |
| } |
| _out << nl << "#pragma warning disable SA1611 // The documentation for parameter x is missing"; | ||
| if (_enableAnalysis) | ||
| { | ||
| // Disable some warnings when auto-generated is removed from the header. See printGeneratedHeader above. |
Copilot
AI
Oct 29, 2025
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.
The comment references 'when auto-generated is removed from the header', but the logic shows this code runs when _enableAnalysis is true, which is when the auto-generated tag is NOT included (removed). Consider rephrasing to 'when auto-generated tag is not included in the header' for clarity.
| // Disable some warnings when auto-generated is removed from the header. See printGeneratedHeader above. | |
| // Disable some warnings when the auto-generated tag is not included in the header. See printGeneratedHeader above. |
| "--depend-xml Generate dependencies in XML format.\n" | ||
| "--depend-file FILE Write dependencies to FILE instead of standard output.\n" | ||
| "--enable-analysis Enable static analysis for generated code by not including\n" | ||
| " <auto-generated> tag which suppresses analyzer warnings.\n" |
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.
Since there are potentially multiple tags involved (one per file).
| " <auto-generated> tag which suppresses analyzer warnings.\n" | |
| " <auto-generated> tags which suppresses analyzer warnings.\n" |
| _sentSynchronously = value; | ||
| _sent = true; |
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.
Not familiar with this specific test, but it does seem a little suspicious not using the mutex here.
Fix #3700