Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DCL56-CPP: Improve performance #298

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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 change_notes/2023-04-28-dcl56-cpp-perf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `DCL56-CPP` - performance has been improved for databases with complex initializers.
23 changes: 15 additions & 8 deletions 23 cpp/common/src/codingstandards/cpp/StaticInitialization.qll
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ module StaticInitializationGraph {
* - Create a `Node` instance for each injector type.
*/

/**
* Gets an Expr directly or indirectly included in an initializer.
*/
private Expr getAnInitializerExpr(Initializer i) {
result = i.getExpr()
or
result = getAnInitializerExpr(i).getAChild()
}

newtype TNode =
TInitializerNode(Initializer i) {
// This is the initializer of a static storage duration variable
Expand All @@ -48,29 +57,29 @@ module StaticInitializationGraph {
} or
TFunctionCallNode(FunctionCall fc) {
// This is a function call that occurs in an initializer called during static initialization
exists(TInitializerNode(any(Initializer i | i.getExpr().getAChild*() = fc)))
exists(TInitializerNode(any(Initializer i | getAnInitializerExpr(i) = fc)))
or
// This is a function call that occurs in a function called during static initialization
exists(
TFunctionNode(any(Function f |
f = fc.getEnclosingFunction() and
// Not in an initializer of a local variable, where the desired flow is instead:
// function -> initializer -> fc
not exists(Initializer i | i.getExpr().getAChild*() = fc)
not exists(Initializer i | getAnInitializerExpr(i) = fc)
))
)
} or
TVariableAccessNode(VariableAccess va) {
// This is a variable that is accessed in an initializer called during static initialization
exists(TInitializerNode(any(Initializer i | i.getExpr().getAChild*() = va)))
exists(TInitializerNode(any(Initializer i | getAnInitializerExpr(i) = va)))
or
// This is a variable that is accessed in a function called during static initialization
exists(
TFunctionNode(any(Function f |
f = va.getEnclosingFunction() and
// Not in an initializer of a local variable, where the desired flow is instead:
// function -> initializer -> va
not exists(Initializer i | i.getExpr().getAChild*() = va)
not exists(Initializer i | getAnInitializerExpr(i) = va)
))
)
}
Expand Down Expand Up @@ -149,9 +158,7 @@ module StaticInitializationGraph {
or
// Initializer steps
exists(Initializer i | i = n1.(InitializerNode).getInitializer() |
i.getExpr().getAChild*() = n2.(FunctionCallNode).getFunctionCall()
or
i.getExpr().getAChild*() = n2.(VariableAccessNode).getVariableAccess()
getAnInitializerExpr(i) = n2.getExpr()
)
or
// FunctionCall steps
Expand All @@ -169,7 +176,7 @@ module StaticInitializationGraph {
f = n2.getExpr().getEnclosingFunction() and
// But not in an initializer of a local variable, where the desired flow is instead:
// function -> initializer -> expression
not exists(Initializer i | i.getExpr().getAChild*() = n2.getExpr())
not exists(Initializer i | getAnInitializerExpr(i) = n2.getExpr())
or
// `n2` is an initializer of a local scope variable within function `f`
n2.(InitializerNode).getInitializer().getDeclaration().(LocalScopeVariable).getFunction() = f
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.