Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit0d3a06e

Browse files
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/preconditions-rule-22-4-1-literal-value-0-errno
2 parents81062d7 +b0d2c22 commit0d3a06e

File tree

26 files changed

+222
-37
lines changed

26 files changed

+222
-37
lines changed

‎c/cert/src/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name:codeql/cert-c-coding-standards
2-
version:2.52.0-dev
2+
version:2.53.0-dev
33
description:CERT C 2016
44
suites:codeql-suites
55
license:MIT

‎c/cert/test/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name:codeql/cert-c-coding-standards-tests
2-
version:2.52.0-dev
2+
version:2.53.0-dev
33
extractor:cpp
44
license:MIT
55
dependencies:

‎c/common/src/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name:codeql/common-c-coding-standards
2-
version:2.52.0-dev
2+
version:2.53.0-dev
33
license:MIT
44
dependencies:
55
codeql/common-cpp-coding-standards:'*'

‎c/common/test/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name:codeql/common-c-coding-standards-tests
2-
version:2.52.0-dev
2+
version:2.53.0-dev
33
extractor:cpp
44
license:MIT
55
dependencies:

‎c/misra/src/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name:codeql/misra-c-coding-standards
2-
version:2.52.0-dev
2+
version:2.53.0-dev
33
description:MISRA C 2012
44
suites:codeql-suites
55
license:MIT

‎c/misra/test/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name:codeql/misra-c-coding-standards-tests
2-
version:2.52.0-dev
2+
version:2.53.0-dev
33
extractor:cpp
44
license:MIT
55
dependencies:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-`M0-1-3` -`UnusedLocalVariable.ql`:
2+
- Improved performance of the unused local variable analysis by moving constant expression value extraction to a separate pass, eliminating certain expensive joins.

‎cpp/autosar/src/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name:codeql/autosar-cpp-coding-standards
2-
version:2.52.0-dev
2+
version:2.53.0-dev
33
description:AUTOSAR C++14 Guidelines R22-11, R21-11, R20-11, R19-11 and R19-03
44
suites:codeql-suites
55
license:MIT

‎cpp/autosar/src/rules/M0-1-3/UnusedLocalVariable.ql‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,46 @@ import cpp
1818
import codingstandards.cpp.autosar
1919
import codingstandards.cpp.deadcode.UnusedVariables
2020

21-
// This predicate is similar to getUseCount for M0-1-4 except that it also
22-
// considers static_asserts. This was created to cater for M0-1-3 specifically
23-
// and hence, doesn't attempt to reuse the M0-1-4 specific predicate
24-
// - getUseCount()
21+
// Collect constant values that we should use to exclude otherwise unused constexpr variables.
22+
//
23+
// For constexpr variables used as template arguments or in static_asserts, we don't see accesses
24+
// (just the appropriate literals). We therefore take a conservative approach and do not report
25+
// constexpr variables whose values are used in such contexts.
26+
//
27+
// For performance reasons, these special values should be collected in a single pass.
28+
predicateexcludedConstantValue(stringvalue){
29+
value=any(ClassTemplateInstantiationcti).getTemplateArgument(_).(Expr).getValue()
30+
or
31+
value=any(StaticAssertsa).getCondition().getAChild*().getValue()
32+
}
33+
34+
/**
35+
* Defines the local variables that should be excluded from the unused variable analysis based
36+
* on their constant value.
37+
*
38+
* See `excludedConstantValue` for more details.
39+
*/
40+
predicateexcludeVariableByValue(Variablevariable){
41+
variable.isConstexpr()and
42+
excludedConstantValue(getConstExprValue(variable))
43+
}
44+
45+
// TODO: This predicate may be possible to merge with M0-1-4's getUseCount(). These two rules
46+
// diverged to handle `excludeVariableByValue`, but may be possible to merge.
2547
intgetUseCountConservatively(Variablev){
2648
result=
2749
count(VariableAccessaccess|access=v.getAnAccess())+
2850
count(UserProvidedConstructorFieldInitcfi|cfi.getTarget()=v)+
29-
// For constexpr variables used as template arguments, we don't see accesses (just the
30-
// appropriate literals). We therefore take a conservative approach and count the number of
31-
// template instantiations that use the given constant, and consider each one to be a use
32-
// of the variable
33-
count(ClassTemplateInstantiationcti|
34-
cti.getTemplateArgument(_).(Expr).getValue()=getConstExprValue(v)
35-
)+
36-
// For static asserts too, check if there is a child which has the same value
37-
// as the constexpr variable.
38-
count(StaticAsserts|s.getCondition().getAChild*().getValue()=getConstExprValue(v))+
3951
// In case an array type uses a constant in the same scope as the constexpr variable,
4052
// consider it as used.
4153
countUsesInLocalArraySize(v)
4254
}
4355

56+
predicateisConservativelyUnused(Variablev){
57+
getUseCountConservatively(v)=0and
58+
notexcludeVariableByValue(v)
59+
}
60+
4461
fromPotentiallyUnusedLocalVariablev
4562
where
4663
notisExcluded(v, DeadCodePackage::unusedLocalVariableQuery())and
@@ -54,5 +71,5 @@ where
5471
exists(another.getAnAccess())and
5572
another!=v
5673
)and
57-
getUseCountConservatively(v)=0
74+
isConservativelyUnused(v)
5875
selectv,"Local variable '"+v.getName()+"' in '"+v.getFunction().getName()+"' is not used."

‎cpp/autosar/test/qlpack.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name:codeql/autosar-cpp-coding-standards-tests
2-
version:2.52.0-dev
2+
version:2.53.0-dev
33
extractor:cpp
44
license:MIT
55
dependencies:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp