File tree Expand file tree Collapse file tree 3 files changed +18
-25
lines changed
common/src/codingstandards/cpp Expand file tree Collapse file tree 3 files changed +18
-25
lines changed Original file line number Diff line number Diff line change @@ -44,11 +44,7 @@ int getUseCountConservatively(Variable v) {
44
44
count ( StaticAssert s | s .getCondition ( ) .getAChild * ( ) .getValue ( ) = getConstExprValue ( v ) ) +
45
45
// In case an array type uses a constant in the same scope as the constexpr variable,
46
46
// consider it as used.
47
- count ( ArrayType at , LocalVariable arrayVariable |
48
- arrayVariable .getType ( ) .resolveTypedefs ( ) = at and
49
- v .( PotentiallyUnusedLocalVariable ) .getFunction ( ) = arrayVariable .getFunction ( ) and
50
- at .getArraySize ( ) .toString ( ) = getConstExprValue ( v )
51
- )
47
+ countUsesInLocalArraySize ( v )
52
48
}
53
49
54
50
from PotentiallyUnusedLocalVariable v
Original file line number Diff line number Diff line change @@ -150,3 +150,19 @@ predicate maybeACompileTimeTemplateArgument(Variable v) {
150
150
)
151
151
)
152
152
}
153
+
154
+ /** Gets the constant value of a constexpr/const variable. */
155
+ private string getConstExprValue ( Variable v ) {
156
+ result = v .getInitializer ( ) .getExpr ( ) .getValue ( ) and
157
+ ( v .isConst ( ) or v .isConstexpr ( ) )
158
+ }
159
+
160
+ /**
161
+ * Counts uses of `Variable` v in a local array of size `n`
162
+ */
163
+ int countUsesInLocalArraySize ( Variable v ) {
164
+ result = count ( ArrayType at , LocalVariable arrayVariable |
165
+ arrayVariable .getType ( ) .resolveTypedefs ( ) = at and
166
+ v .( PotentiallyUnusedLocalVariable ) .getFunction ( ) = arrayVariable .getFunction ( ) and
167
+ at .getArraySize ( ) .toString ( ) = getConstExprValue ( v ) )
168
+ }
Original file line number Diff line number Diff line change @@ -22,25 +22,6 @@ abstract class DeadCodeSharedQuery extends Query { }
22
22
23
23
Query getQuery ( ) { result instanceof DeadCodeSharedQuery }
24
24
25
- /**
26
- * Returns integer value of a constexpr variable
27
- */
28
- int getConstexprValue ( Variable v ) {
29
- result = v .getInitializer ( ) .getExpr ( ) .getValue ( ) .toInt ( ) and v .isConstexpr ( )
30
- }
31
-
32
- /**
33
- * Holds if `Variable` v is used for a local array size with value `n`
34
- */
35
- bindingset [ n]
36
- predicate isUsedInLocalArraySize ( Variable v , int n ) {
37
- // Cf. https://github.com/github/codeql-coding-standards/pull/660/files.
38
- count ( ArrayType at , LocalVariable arrayVariable |
39
- arrayVariable .getType ( ) .resolveTypedefs ( ) = at and
40
- v .( PotentiallyUnusedLocalVariable ) .getFunction ( ) = arrayVariable .getFunction ( ) and
41
- at .getArraySize ( ) = n ) > 0
42
- }
43
-
44
25
/**
45
26
* Holds if the `Stmt` `s` is either dead or unreachable.
46
27
*/
@@ -72,7 +53,7 @@ predicate isDeadStmt(Stmt s) {
72
53
va .getTarget ( ) = v and
73
54
not isDeadOrUnreachableStmt ( va .getEnclosingStmt ( ) )
74
55
) and
75
- not isUsedInLocalArraySize ( v , getConstexprValue ( v ) )
56
+ not ( countUsesInLocalArraySize ( v ) > 0 )
76
57
)
77
58
)
78
59
)
You can’t perform that action at this time.
0 commit comments