-
Notifications
You must be signed in to change notification settings - Fork 69
Improve performance of m0-1-3, unused local vars. #974
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - `M0-1-3` - `UnusedLocalVariable.ql`: | ||
| - Improved performance of the unused local variable analysis by moving constant expression value extraction to a separate pass, eliminating certain expensive joins. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,29 +18,52 @@ import cpp | |||||
| import codingstandards.cpp.autosar | ||||||
| import codingstandards.cpp.deadcode.UnusedVariables | ||||||
|
|
||||||
| // This predicate is similar to getUseCount for M0-1-4 except that it also | ||||||
| // considers static_asserts. This was created to cater for M0-1-3 specifically | ||||||
| // and hence, doesn't attempt to reuse the M0-1-4 specific predicate | ||||||
| // - getUseCount() | ||||||
| // Collect constant values that we should use to exclude otherwise unused constexpr variables. | ||||||
| // | ||||||
| // For constexpr variables used as template arguments or in static_asserts, we don't see accesses | ||||||
| // (just the appropriate literals). We therefore take a conservative approach and do not report | ||||||
| // constexpr variables whose values are used in such contexts. | ||||||
| // | ||||||
| // For performance reasons, these special values should be collected in a single pass. | ||||||
| predicate excludedConstantValue(string value) { | ||||||
| // For constexpr variables used as template arguments, we don't see accesses (just the | ||||||
| // appropriate literals). We therefore take a conservative approach and count the number of | ||||||
| // template instantiations that use the given constant, and consider each one to be a use | ||||||
| // of the variable | ||||||
| value = any(ClassTemplateInstantiation cti).getTemplateArgument(_).(Expr).getValue() | ||||||
| or | ||||||
| // For static asserts too, check if there is a child which has the same value | ||||||
| // as the constexpr variable. | ||||||
| value = any(StaticAssert sa).getCondition().getAChild*().getValue() | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Defines the local variables that should be excluded from the unused variable analysis based | ||||||
| * on their constant value. | ||||||
| * | ||||||
| * See `excludedConstantValue` for more details. | ||||||
| */ | ||||||
| predicate excludeVariableByValue(Variable variable) { | ||||||
| variable.isConstexpr() and | ||||||
|
||||||
| variable.isConstexpr() and | |
| (variable.isConst() or variable.isConstexpr()) and |
Uh oh!
There was an error while loading. Please reload this page.