C#: Correct printing of returns via out/ref parameters in model generation.#19114
Merged
michaelnebel merged 3 commits intogithub:mainfrom Mar 27, 2025
Merged
Conversation
215ceb8 to
cdb7127
Compare
cdb7127 to
8bda7ce
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the model generation to correctly print return flows via out/ref parameters and addresses an issue with ref parameter usage in method declarations. The changes include:
- Updating model summaries for methods that handle out and ref parameters.
- Fixing the incorrect summary flow for methods using ref parameters.
- Introducing a new ParameterModifiers class with methods to test the updated behavior.
Files not reviewed (2)
- csharp/ql/src/utils/modelgenerator/internal/CaptureModels.qll: Language not supported
- shared/mad/codeql/mad/modelgenerator/internal/ModelGeneratorImpl.qll: Language not supported
Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more
| // neutral=Models;ParameterModifiers;RefParamUse;(System.Object);summary;df-generated | ||
| public void RefParamUse(ref object value) | ||
| { | ||
| var b = value is null; |
There was a problem hiding this comment.
The variable 'b' is assigned but never used; consider removing it or using it meaningfully to avoid confusion.
Suggested change
| var b = value is null; | |
| // The variable 'b' was removed as it was unused. |
hvitved
approved these changes
Mar 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is addressing the issue https://github.com/github/codeql-csharp-team/issues/474 reported by @MathiasVP.
There are two note-worthy consequences of this
outorrefparameter will now correctly targetArgument[...]instead ofReturnValue.refparameter and a use of therefparameter in the callable declaration would lead to an incorrect summary, as there would be flow from the parameter node to the SSA definition corresponding to the parameter. This is fixed with this change.