Repository navigation
cpp: Model BDE single-element concurrent queue operations #22584
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
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Added data-flow models for single-element operations on BDE `bdlcc::Deque` and `bdlcc::BoundedQueue`. |
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,31 @@ | ||
| # BDE single-element concurrent queue operations (C++11 reference overloads). | ||
| # https://github.com/bloomberg/bde/tree/ec310b87e008199ecbdbc00a0b0264a53d806a0a/groups/bdl/bdlcc | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/cpp-all | ||
| extensible: summaryModel | ||
| data: | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "pushBack", "(const T &)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "pushBack", "(T &&)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "pushFront", "(const T &)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "pushFront", "(T &&)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "forcePushBack", "(const T &)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "forcePushBack", "(T &&)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "forcePushFront", "(const T &)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "forcePushFront", "(T &&)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "tryPushBack", "(const T &)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "tryPushBack", "(T &&)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "popBack", "(T *)", "", "Argument[-1].Element[@]", "Argument[*@0]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "popFront", "(T *)", "", "Argument[-1].Element[@]", "Argument[*@0]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "tryPopBack", "(T *)", "", "Argument[-1].Element[@]", "Argument[*@0]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque<T>", False, "tryPopFront", "(T *)", "", "Argument[-1].Element[@]", "Argument[*@0]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "BoundedQueue<T>", False, "pushBack", "(const T &)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "BoundedQueue<T>", False, "pushBack", "(T &&)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "BoundedQueue<T>", False, "tryPushBack", "(const T &)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "BoundedQueue<T>", False, "tryPushBack", "(T &&)", "", "Argument[*@0]", "Argument[-1].Element[@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "BoundedQueue<T>", False, "popFront", "(T *)", "", "Argument[-1].Element[@]", "Argument[*@0]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "BoundedQueue<T>", False, "tryPopFront", "(T *)", "", "Argument[-1].Element[@]", "Argument[*@0]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque", False, "popBack", "", "", "Argument[-1].Element[]", "ReturnValue", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque", False, "popFront", "", "", "Argument[-1].Element[]", "ReturnValue", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque", False, "popBack", "", "", "Argument[-1].Element[*@]", "ReturnValue[*@]", "value", "manual"] | ||
| - ["BloombergLP::bdlcc", "Deque", False, "popFront", "", "", "Argument[-1].Element[*@]", "ReturnValue[*@]", "value", "manual"] | ||
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 @@ | ||
|
|
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 @@ | ||
| import cpp | ||
| import utils.test.dataflow.FlowTestCommon | ||
| import semmle.code.cpp.ir.dataflow.TaintTracking | ||
|
|
||
| module Config implements DataFlow::ConfigSig { | ||
| predicate isSource(DataFlow::Node node) { | ||
| node.asExpr().(FunctionCall).getTarget().hasName("source") | ||
| } | ||
|
|
||
| predicate isSink(DataFlow::Node node) { | ||
| exists(FunctionCall call | | ||
| call.getTarget().hasName("sink") and node.asExpr() = call.getArgument(0) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| module Flow = TaintTracking::Global<Config>; | ||
|
|
||
| import MakeTest<IRFlowTest<Flow>> |
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,34 @@ | ||
| // Public single-element overloads from bloomberg/bde groups/bdl/bdlcc. | ||
| namespace BloombergLP { namespace bslma { class Allocator; } namespace bdlcc { | ||
| template<class TYPE> class Deque { | ||
| public: | ||
| void pushBack(const TYPE& value); | ||
| void pushBack(TYPE&& value); | ||
| void pushFront(const TYPE& value); | ||
| void pushFront(TYPE&& value); | ||
| void forcePushBack(const TYPE& value); | ||
| void forcePushBack(TYPE&& value); | ||
| void forcePushFront(const TYPE& value); | ||
| void forcePushFront(TYPE&& value); | ||
| int tryPushBack(const TYPE& value); | ||
| int tryPushBack(TYPE&& value); | ||
| void popBack(TYPE *value); | ||
| void popFront(TYPE *value); | ||
| int tryPopBack(TYPE *value); | ||
| int tryPopFront(TYPE *value); | ||
| TYPE popBack(); | ||
| TYPE popFront(); | ||
| template<class ITER> void forcePushBack(ITER begin, ITER end); | ||
| void tryPopFront(unsigned long count); | ||
| }; | ||
| template<class TYPE> class BoundedQueue { | ||
| public: | ||
| BoundedQueue(unsigned long capacity, bslma::Allocator *allocator = 0); | ||
| int pushBack(const TYPE& value); | ||
| int pushBack(TYPE&& value); | ||
| int tryPushBack(const TYPE& value); | ||
| int tryPushBack(TYPE&& value); | ||
| int popFront(TYPE *value); | ||
| int tryPopFront(TYPE *value); | ||
| }; | ||
| } } |
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,24 @@ | ||
| #include "queues.h" | ||
| int source(); | ||
| void sink(int); | ||
|
|
||
| struct InputIterator { | ||
| int value; | ||
| const int &operator*() const { return value; } | ||
| }; | ||
|
|
||
| // Reduced range overload body. The single-element models must not replace it. | ||
| namespace BloombergLP { namespace bdlcc { | ||
| template<class TYPE> | ||
| template<class ITER> | ||
| void Deque<TYPE>::forcePushBack(ITER begin, ITER end) { | ||
| pushBack(*begin); | ||
| } | ||
| } } | ||
|
|
||
| void rangeOverloadKeepsItsBody() { | ||
| BloombergLP::bdlcc::Deque<int> q; | ||
| InputIterator begin = {source()}, end = {0}; | ||
| q.forcePushBack(begin, end); | ||
| sink(q.popFront()); // $ ir | ||
| } |
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,107 @@ | ||
| #include "queues.h" | ||
| int source(); | ||
| void sink(int); | ||
| using namespace BloombergLP::bdlcc; | ||
|
|
||
| void DequepushBack() { | ||
| Deque<int> q; | ||
| int input = source(), output = 0; | ||
| q.pushBack(input); | ||
| q.popBack(&output); | ||
| sink(output); // $ ir | ||
| } | ||
| void DequepushFront() { | ||
| Deque<int> q; | ||
| int input = source(), output = 0; | ||
| q.pushFront(input); | ||
| q.popFront(&output); | ||
| sink(output); // $ ir | ||
| } | ||
| void DequeforcePushBack() { | ||
| Deque<int> q; | ||
| int input = source(), output = 0; | ||
| q.forcePushBack(input); | ||
| q.tryPopBack(&output); | ||
| sink(output); // $ ir | ||
| } | ||
| void DequeforcePushFront() { | ||
| Deque<int> q; | ||
| int input = source(), output = 0; | ||
| q.forcePushFront(input); | ||
| q.tryPopFront(&output); | ||
| sink(output); // $ ir | ||
| } | ||
| void DequetryPushBack() { | ||
| Deque<int> q; | ||
| int input = source(), output = 0; | ||
| q.tryPushBack(input); | ||
| q.popBack(&output); | ||
| sink(output); // $ ir | ||
| } | ||
| void BoundedQueuepushBack() { | ||
| BoundedQueue<int> q(8); | ||
| int input = source(), output = 0; | ||
| q.pushBack(input); | ||
| q.popFront(&output); | ||
| sink(output); // $ ir | ||
| } | ||
| void BoundedQueuetryPushBack() { | ||
| BoundedQueue<int> q(8); | ||
| int input = source(), output = 0; | ||
| q.tryPushBack(input); | ||
| q.tryPopFront(&output); | ||
| sink(output); // $ ir | ||
| } | ||
|
|
||
| void returnAndMove() { | ||
| Deque<int> q; | ||
| int input = source(); | ||
| q.pushBack(static_cast<int&&>(input)); | ||
| int output = 0; | ||
| q.popBack(&output); | ||
| sink(output); // $ ir | ||
| sink(q.popFront()); // $ ir | ||
| sink(q.popBack()); // $ ir | ||
| } | ||
| void returnAfterCopy() { | ||
| Deque<int> q; | ||
| int input = source(); | ||
| q.pushBack(input); | ||
| sink(q.popFront()); // $ ir | ||
| } | ||
| void pointerPayload() { | ||
| int input = source(); | ||
| int *p = &input, *output = 0; | ||
| BoundedQueue<int*> q(8); | ||
| q.pushBack(p); | ||
| q.popFront(&output); | ||
| sink(*output); // $ ir | ||
| } | ||
| void pointerReturn() { | ||
| int input = source(); | ||
| int *p = &input; | ||
| Deque<int*> q; | ||
| q.pushBack(p); | ||
| sink(*q.popFront()); // $ ir | ||
| } | ||
| struct Payload { int value; }; | ||
| void objectPayload() { | ||
| Payload input = {source()}, output = {0}; | ||
| Deque<Payload> q; | ||
| q.pushFront(input); | ||
| q.popBack(&output); | ||
| sink(output.value); // $ ir | ||
| } | ||
| void statusesAreNotPayload() { | ||
| BoundedQueue<int> q(8); | ||
| int input = source(), output = 0; | ||
| sink(q.tryPushBack(input)); | ||
| sink(q.tryPopFront(&output)); | ||
| sink(output); // $ ir | ||
| } | ||
| void failureCanPreserveOutput() { | ||
| Deque<int> q; | ||
| int output = source(); | ||
| if (q.tryPopFront(&output) != 0) | ||
| sink(output); // $ ir | ||
| } |
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.
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.e. we could model
tryPushFrontas well. I'd be happy if we do, but you have to draw a line somewhere so I'm also happy with this PR without.