Repository navigation
C++: Fix multiple parameter types in IR #23165
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
cpp/ql/test/library-tests/ir/parameter-types/declarations.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // The parameter is declared as `char *argv[]` in `test.cpp`. | ||
| void array_param_with_pointer_declaration(char **argv); | ||
|
|
||
| // The parameter is declared as `char **argv` in `test.cpp`. | ||
| void pointer_param_with_array_declaration(char *argv[]); | ||
|
|
||
| // The parameter is declared as `void f()` in `test.cpp`. | ||
| void function_param_with_pointer_declaration(void (*f)()); | ||
|
|
||
| // The parameter is declared as `const int x` in `test.cpp`. | ||
| void const_param_with_non_const_declaration(int x); | ||
|
|
||
| // The parameter is declared as `size_t n` in `test.cpp`. | ||
| void typedef_param_with_underlying_type_declaration(unsigned long n); | ||
Empty file.
19 changes: 19 additions & 0 deletions
19
cpp/ql/test/library-tests/ir/parameter-types/parameter-types.ql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| private import cpp | ||
| private import semmle.code.cpp.ir.IR | ||
| import utils.test.InlineExpectationsTest | ||
|
|
||
| module ParameterTypesTest implements TestSig { | ||
| string getARelevantTag() { result = "type" } | ||
|
|
||
| predicate hasActualResult(Location location, string element, string tag, string value) { | ||
| exists(VariableAddressInstruction va, InitializeParameterInstruction init | | ||
| init.getAnOperand().getDef() = va and | ||
| location = va.getLocation() and | ||
| element = va.toString() and | ||
| tag = "type" and | ||
| value = "\"" + va.getResultLanguageType().toString() + "\"" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| import MakeTest<ParameterTypesTest> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| typedef unsigned long size_t; | ||
|
|
||
| void pointer_param(char **argv) { // $ type="glval<char **>" | ||
| } | ||
|
|
||
| void array_param(char *argv[]) { // $ type="glval<char **>" | ||
| } | ||
|
|
||
| // The parameter is declared as `char **argv` in `declarations.cpp`. | ||
| void array_param_with_pointer_declaration(char *argv[]) { // $ type="glval<char **>" | ||
| } | ||
|
|
||
| // The parameter is declared as `char *argv[]` in `declarations.cpp`. | ||
| void pointer_param_with_array_declaration(char **argv) { // $ type="glval<char **>" | ||
| } | ||
|
|
||
| // The parameter is declared as `void (*f)()` in `declarations.cpp`. | ||
| void function_param_with_pointer_declaration(void f()) { // $ type="glval<..(*)(..)>" | ||
| } | ||
|
|
||
| // The parameter is declared as `int x` in `declarations.cpp`. | ||
| void const_param_with_non_const_declaration(const int x) { // $ type="glval<const int>" | ||
| } | ||
|
|
||
| // The parameter is declared as `unsigned long n` in `declarations.cpp`. | ||
| void typedef_param_with_underlying_type_declaration(size_t n) { // $ type="glval<size_t>" | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Are all of these legal? As in: are the definition and declaration actually allowed to differ this much (e.g, wrt.
const).Uh oh!
There was an error while loading. Please reload this page.
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.
My reading of the standard certainly makes me believe there are no violations here. From https://eel.is/c++draft/dcl.fct:
(and prior to that there's also a note about "array" vs "pointer")