-
Notifications
You must be signed in to change notification settings - Fork 66
Implement Concurrency7 package #799
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
lcartey
merged 10 commits into
main
from
michaelrfairhurst/implement-concurrency7-package
Feb 19, 2025
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9ff699b
Implement Concurrency7 package
MichaelRFairhurst 8a2076e
Fix query metadata
MichaelRFairhurst 6f36b1c
Fix query metadata, format
MichaelRFairhurst 9ac5159
Fix rule 21-26 packages in rules.csv: Concurrency7 not 8.
MichaelRFairhurst a739041
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/imp…
MichaelRFairhurst fcb870c
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/imp…
MichaelRFairhurst 3882e87
Address feedback
MichaelRFairhurst b294477
CI/CD fixes: format, rules.csv package -> Concurrency8 for unhandled …
MichaelRFairhurst 1b2199f
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/imp…
MichaelRFairhurst 3eecfa0
Update StdFunctionOrMacro with feedback
MichaelRFairhurst 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
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
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
7 changes: 4 additions & 3 deletions
7
c/misra/test/rules/RULE-9-7/UninitializedAtomicObject.expected
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
| test.c:22:15:22:16 | definition of l3 | Atomic object 'l3' has no initializer or corresponding use of 'atomic_init()'. | | ||
| test.c:25:15:25:16 | definition of l4 | Atomic object 'l4' has no initializer or corresponding use of 'atomic_init()'. | | ||
| test.c:29:15:29:16 | definition of l5 | Atomic object 'l5' has no initializer or corresponding use of 'atomic_init()'. | | ||
| test.c:24:15:24:16 | definition of l3 | Atomic object 'l3' has no initializer or corresponding use of 'atomic_init()'. | | ||
| test.c:27:15:27:16 | definition of l4 | Atomic object 'l4' has no initializer or corresponding use of 'atomic_init()'. | | ||
| test.c:31:15:31:16 | definition of l5 | Atomic object 'l5' has no initializer or corresponding use of 'atomic_init()'. | | ||
| test.c:41:15:41:16 | definition of l7 | Atomic object 'l7' has no initializer or corresponding use of 'atomic_init()'. | |
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
111 changes: 111 additions & 0 deletions
111
cpp/common/src/codingstandards/cpp/StdFunctionOrMacro.qll
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,111 @@ | ||
/** | ||
* This module intends to reduce the difficulty of handling the pattern where implementations | ||
* implement a function as a macro: the class `StdFunctionOrMacro<...>::Call` matches both std | ||
* function calls as well as std function macro expansions. | ||
* | ||
* For instance, `atomic_init` may be implemented as a function, but is also implemented as | ||
* `#DEFINE atomic_init(x) __c11_atomic_init(x)` on some platforms. This module aids in finding | ||
* calls to any standard function which may be a macro, and has predefined behavior for | ||
* handling `__c11_*` macros. | ||
* | ||
* Since a macro can be defined to expand to any expression, we cannot know generally which | ||
* expanded expressions in `f(x, y)` correspond to arguments `x` or `y`. To handle this, the | ||
* following inference options are available: | ||
* - `NoMacroExpansionInference`: Assume any expression in the macro expansion could correspond to | ||
* any macro argument. | ||
* - `C11FunctionWrapperMacro`: Check if the macro expands to a function call prefixed with | ||
* `__c11_` and if so, return the corresponding argument. Otherwise, fall back to | ||
* `NoMacroExpansionInference`. | ||
* - `InferMacroExpansionArguments`: Implement your own logic for inferring the argument. | ||
* | ||
* To use this module, pick one of the above inference strategies, and then create a predicate for | ||
* the name you wish to match. For instance: | ||
* | ||
* ```codeql | ||
* private string atomicInit() { result = "atomic_init" } | ||
* | ||
* from StdFunctionOrMacro<C11FunctionWrapperMacro, atomicInit/0>::Call c | ||
* select c.getArgument(0) | ||
* ``` | ||
*/ | ||
|
||
import cpp as cpp | ||
|
||
/** Specify the name of your function as a predicate */ | ||
signature string getName(); | ||
|
||
/** Signature module to implement custom argument resolution behavior in expanded macros */ | ||
signature module InferMacroExpansionArguments { | ||
bindingset[mi, argumentIdx] | ||
cpp::Expr inferArgument(cpp::MacroInvocation mi, int argumentIdx); | ||
} | ||
|
||
/** Assume all subexpressions of an expanded macro may be the result of any ith argument */ | ||
module NoMacroExpansionInference implements InferMacroExpansionArguments { | ||
bindingset[mi, argumentIdx] | ||
cpp::Expr inferArgument(cpp::MacroInvocation mi, int argumentIdx) { | ||
result.getParent*() = mi.getExpr() | ||
MichaelRFairhurst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
/** Assume macro `f(x, y, ...)` expands to `__c11_f(x, y, ...)`. */ | ||
module C11FunctionWrapperMacro implements InferMacroExpansionArguments { | ||
bindingset[mi, argumentIdx] | ||
cpp::Expr inferArgument(cpp::MacroInvocation mi, int argumentIdx) { | ||
if mi.getExpr().(cpp::FunctionCall).getTarget().hasName("__c11_" + mi.getMacroName()) | ||
then result = mi.getExpr().(cpp::FunctionCall).getArgument(argumentIdx) | ||
else result = NoMacroExpansionInference::inferArgument(mi, argumentIdx) | ||
} | ||
} | ||
|
||
/** | ||
* A module to find calls to standard functions, or expansions of macros with the same name. | ||
* | ||
* To use this module, specify a name predicate and an inference strategy for correlating macro | ||
* expansions to macro arguments. | ||
* | ||
* For example: | ||
* | ||
* ```codeql | ||
* private string atomicInit() { result = "atomic_init" } | ||
* from StdFunctionOrMacro<C11FunctionWrapperMacro, atomicInit/0>::Call c | ||
* select c.getArgument(0) | ||
* ``` | ||
*/ | ||
module StdFunctionOrMacro<InferMacroExpansionArguments InferExpansion, getName/0 getStdName> { | ||
final private class Expr = cpp::Expr; | ||
|
||
final private class FunctionCall = cpp::FunctionCall; | ||
|
||
final private class MacroInvocation = cpp::MacroInvocation; | ||
|
||
private newtype TStdCall = | ||
TStdFunctionCall(FunctionCall fc) { fc.getTarget().hasName(getStdName()) } or | ||
TStdMacroInvocation(MacroInvocation mi) { mi.getMacro().hasName(getStdName()) } | ||
|
||
/** | ||
* A call to a standard function or an expansion of a macro with the same name. | ||
*/ | ||
class Call extends TStdCall { | ||
bindingset[this, argumentIdx] | ||
Expr getArgument(int argumentIdx) { | ||
exists(FunctionCall fc | | ||
this = TStdFunctionCall(fc) and | ||
result = fc.getArgument(argumentIdx) | ||
) | ||
or | ||
exists(MacroInvocation mi | | ||
this = TStdMacroInvocation(mi) and | ||
result = InferExpansion::inferArgument(mi, argumentIdx) | ||
) | ||
} | ||
|
||
string toString() { | ||
this = TStdFunctionCall(_) and | ||
result = "Standard function call" | ||
or | ||
this = TStdMacroInvocation(_) and | ||
result = "Invocation of a standard function implemented as a macro" | ||
} | ||
} | ||
} |
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
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
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.