Skip to content

Commit 8159166

Browse files
authored
Merge pull request #261 from github/jsinglet/performance-hotfix-2-15-1
Performance Hotfix for 2.15.1
2 parents c2aa225 + e2ef4e0 commit 8159166

File tree

19 files changed

+107
-49
lines changed

19 files changed

+107
-49
lines changed

c/cert/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards
2-
version: 2.15.0
2+
version: 2.15.1
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT

c/cert/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards-tests
2-
version: 2.15.0
2+
version: 2.15.1
33
extractor: cpp
44
license: MIT
55
dependencies:

c/common/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards
2-
version: 2.15.0
2+
version: 2.15.1
33
license: MIT
44
dependencies:
55
codeql/common-cpp-coding-standards: '*'

c/common/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards-tests
2-
version: 2.15.0
2+
version: 2.15.1
33
extractor: cpp
44
license: MIT
55
dependencies:

c/misra/src/codingstandards/c/misra/EssentialTypes.qll

+65-26
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,83 @@ class EssentialTypeCategory extends TEssentialTypeCategory {
3131
}
3232
}
3333

34+
/**
35+
* An expression in the program that evaluates to a compile time constant signed or unsigned integer.
36+
*/
37+
private class ConstantIntegerExpr extends Expr {
38+
pragma[noinline]
39+
ConstantIntegerExpr() {
40+
getEssentialTypeCategory(this.getType()) =
41+
[
42+
EssentiallyUnsignedType().(EssentialTypeCategory),
43+
EssentiallySignedType().(EssentialTypeCategory)
44+
] and
45+
exists(this.getValue().toFloat()) and
46+
not this instanceof Conversion
47+
}
48+
}
49+
50+
/** A `float` which represents an integer constant in the program. */
51+
private class IntegerConstantAsFloat extends float {
52+
IntegerConstantAsFloat() { exists(ConstantIntegerExpr ce | this = ce.getValue().toFloat()) }
53+
}
54+
55+
/**
56+
* Identifies which integral types from which type categories can represent a given integer constant
57+
* in the program.
58+
*/
59+
pragma[nomagic]
60+
private predicate isCandidateIntegralType(
61+
EssentialTypeCategory cat, IntegralType it, IntegerConstantAsFloat c
62+
) {
63+
getEssentialTypeCategory(it) = cat and
64+
c = any(ConstantIntegerExpr ce).getValue().toFloat() and
65+
// As with range analysis, we assume two's complement representation
66+
typeLowerBound(it) <= c and
67+
typeUpperBound(it) >= c
68+
}
69+
3470
/**
3571
* Gets the unsigned type of lowest rank that can represent the value of the given expression,
3672
* assuming that the expression is essentially unsigned.
3773
*/
38-
private IntegralType utlr(Expr const) {
74+
pragma[nomagic]
75+
private IntegralType utlr(ConstantIntegerExpr const) {
3976
getEssentialTypeCategory(const.getType()) = EssentiallyUnsignedType() and
40-
getEssentialTypeCategory(result) = EssentiallyUnsignedType() and
41-
exists(float c | c = const.getValue().toFloat() |
42-
// As with range analysis, we assume two's complement representation
43-
typeLowerBound(result) <= c and
44-
typeUpperBound(result) >= c and
45-
forall(IntegralType it |
46-
getEssentialTypeCategory(it) = EssentiallyUnsignedType() and
47-
typeLowerBound(it) <= c and
48-
typeUpperBound(it) >= c
49-
|
50-
result.getSize() <= it.getSize()
51-
)
77+
result = utlr_c(const.getValue().toFloat())
78+
}
79+
80+
/**
81+
* Given an integer constant that appears in the program, gets the unsigned type of lowest rank
82+
* that can hold it.
83+
*/
84+
pragma[nomagic]
85+
private IntegralType utlr_c(IntegerConstantAsFloat c) {
86+
isCandidateIntegralType(EssentiallyUnsignedType(), result, c) and
87+
forall(IntegralType it | isCandidateIntegralType(EssentiallyUnsignedType(), it, c) |
88+
result.getSize() <= it.getSize()
5289
)
5390
}
5491

5592
/**
5693
* Gets the signed type of lowest rank that can represent the value of the given expression,
5794
* assuming that the expression is essentially signed.
5895
*/
59-
private IntegralType stlr(Expr const) {
96+
pragma[nomagic]
97+
private IntegralType stlr(ConstantIntegerExpr const) {
6098
getEssentialTypeCategory(const.getType()) = EssentiallySignedType() and
61-
getEssentialTypeCategory(result) = EssentiallySignedType() and
62-
exists(float c | c = const.getValue().toFloat() |
63-
// As with range analysis, we assume two's complement representation
64-
typeLowerBound(result) <= c and
65-
typeUpperBound(result) >= c and
66-
forall(IntegralType it |
67-
getEssentialTypeCategory(it) = EssentiallySignedType() and
68-
typeLowerBound(it) <= c and
69-
typeUpperBound(it) >= c
70-
|
71-
result.getSize() <= it.getSize()
72-
)
99+
result = stlr_c(const.getValue().toFloat())
100+
}
101+
102+
/**
103+
* Given an integer constant that appears in the program, gets the signed type of lowest rank
104+
* that can hold it.
105+
*/
106+
pragma[nomagic]
107+
private IntegralType stlr_c(IntegerConstantAsFloat c) {
108+
isCandidateIntegralType(EssentiallySignedType(), result, c) and
109+
forall(IntegralType it | isCandidateIntegralType(EssentiallySignedType(), it, c) |
110+
result.getSize() <= it.getSize()
73111
)
74112
}
75113

@@ -108,6 +146,7 @@ EssentialTypeCategory getEssentialTypeCategory(Type type) {
108146
/**
109147
* Gets the essential type of the given expression `e`, considering any explicit conversions.
110148
*/
149+
pragma[nomagic]
111150
Type getEssentialType(Expr e) {
112151
if e.hasExplicitConversion()
113152
then

c/misra/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-c-coding-standards
2-
version: 2.15.0
2+
version: 2.15.1
33
description: MISRA C 2012
44
suites: codeql-suites
55
license: MIT

c/misra/src/rules/RULE-10-5/InappropriateEssentialTypeCast.ql

+11-4
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,23 @@ predicate isIncompatibleEssentialTypeCast(EssentialTypeCategory fromCat, Essenti
4949
]
5050
}
5151

52+
predicate isCastTypes(
53+
Cast c, Type essentialFromType, Type essentialToType, EssentialTypeCategory fromCategory,
54+
EssentialTypeCategory toCategory
55+
) {
56+
essentialFromType = getEssentialTypeBeforeConversions(c.getExpr()) and
57+
essentialToType = c.getType() and
58+
fromCategory = getEssentialTypeCategory(essentialFromType) and
59+
toCategory = getEssentialTypeCategory(essentialToType)
60+
}
61+
5262
from
5363
Cast c, Type essentialFromType, Type essentialToType, EssentialTypeCategory fromCategory,
5464
EssentialTypeCategory toCategory, string message
5565
where
5666
not isExcluded(c, EssentialTypesPackage::inappropriateEssentialTypeCastQuery()) and
5767
not c.isImplicit() and
58-
essentialFromType = getEssentialTypeBeforeConversions(c.getExpr()) and
59-
essentialToType = c.getType() and
60-
fromCategory = getEssentialTypeCategory(essentialFromType) and
61-
toCategory = getEssentialTypeCategory(essentialToType) and
68+
isCastTypes(c, essentialFromType, essentialToType, fromCategory, toCategory) and
6269
isIncompatibleEssentialTypeCast(fromCategory, toCategory) and
6370
(
6471
if fromCategory = EssentiallyEnumType() and toCategory = EssentiallyEnumType()

c/misra/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-c-coding-standards-tests
2-
version: 2.15.0
2+
version: 2.15.1
33
extractor: cpp
44
license: MIT
55
dependencies:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* The performance of the following queries related to essential types have been improved:
2+
* `Rule 10.1`
3+
* `Rule 10.2`
4+
* `Rule 10.3`
5+
* `Rule 10.4`
6+
* `Rule 10.5`
7+
* `Rule 10.6`
8+
* `Rule 10.7`
9+
* `Rule 10.8`
10+
* `Rule 14.1`
11+
* `Rule 21.14`
12+
* `Rule 21.16`

cpp/autosar/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/autosar-cpp-coding-standards
2-
version: 2.15.0
2+
version: 2.15.1
33
description: AUTOSAR C++14 Guidelines 20-11
44
suites: codeql-suites
55
license: MIT

cpp/autosar/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/autosar-cpp-coding-standards-tests
2-
version: 2.15.0
2+
version: 2.15.1
33
extractor: cpp
44
license: MIT
55
dependencies:

cpp/cert/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-cpp-coding-standards
2-
version: 2.15.0
2+
version: 2.15.1
33
description: CERT C++ 2016
44
suites: codeql-suites
55
license: MIT

cpp/cert/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-cpp-coding-standards-tests
2-
version: 2.15.0
2+
version: 2.15.1
33
extractor: cpp
44
license: MIT
55
dependencies:

cpp/common/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-cpp-coding-standards
2-
version: 2.15.0
2+
version: 2.15.1
33
license: MIT
44
dependencies:
55
codeql/cpp-all: 0.3.5

cpp/common/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-cpp-coding-standards-tests
2-
version: 2.15.0
2+
version: 2.15.1
33
extractor: cpp
44
license: MIT
55
dependencies:

cpp/misra/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-cpp-coding-standards
2-
version: 2.15.0
2+
version: 2.15.1
33
description: MISRA C++ 2008
44
suites: codeql-suites
55
license: MIT

cpp/misra/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-cpp-coding-standards-tests
2-
version: 2.15.0
2+
version: 2.15.1
33
extractor: cpp
44
license: MIT
55
dependencies:

cpp/report/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/report-cpp-coding-standards
2-
version: 2.15.0
2+
version: 2.15.1
33
license: MIT
44
dependencies:
55
codeql/cpp-all: 0.3.5

docs/user_manual.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
This user manual documents release `2.10.0` of the coding standards located at https://github.com/github/codeql-coding-standards/releases/tag/v2.10.0 .
2727
The release page documents the release notes and contains the following artifacts part of the release:
2828

29-
- `code-scanning-cpp-query-pack-anon-2.15.0.zip`: coding standard queries and scripts to be used with GitHub Code Scanning or the CodeQL CLI as documented in the section _Operating manual_.
30-
- `supported_rules_list_2.15.0.csv`: A Comma Separated File (CSV) containing the supported rules per standard and the queries that implement the rule.
29+
- `code-scanning-cpp-query-pack-anon-2.15.1.zip`: coding standard queries and scripts to be used with GitHub Code Scanning or the CodeQL CLI as documented in the section _Operating manual_.
30+
- `supported_rules_list_2.15.1.csv`: A Comma Separated File (CSV) containing the supported rules per standard and the queries that implement the rule.
3131
- `upported_rules_list_2.15.0-dev.md`: A Markdown formatted file with a table containing the supported rules per standard and the queries that implement the rule.
32-
- `user_manual_2.15.0.md`: This user manual.
32+
- `user_manual_2.15.1.md`: This user manual.
3333
- `Source Code (zip)`: A zip archive containing the contents of https://github.com/github/codeql-coding-standards
3434
- `Source Code (tar.gz)`: A GZip compressed tar archive containing the contents of https://github.com/github/codeql-coding-standards
3535
- `checksums.txt`: A text file containing sha256 checksums for the aforementioned artifacts.
@@ -457,7 +457,7 @@ This section describes known failure modes for "CodeQL Coding Standards" and des
457457
| | Ouf of space | Less output. Some files may be only be partially analyzed, or not analyzed at all. | Error reported on the command line. | Increase space. If it remains an issue report space consumption issues via the CodeQL Coding Standards [bug tracker](https://github.com/github/codeql-coding-standards/issues). |
458458
| | False positives | More output. Results are reported which are not violations of the guidelines. | All reported results must be reviewed. | Report false positive issues via the CodeQL Coding Standards [bug tracker](https://github.com/github/codeql-coding-standards/issues). |
459459
| | False negatives | Less output. Violations of the guidelines are not reported. | Other validation and verification processes during software development should be used to complement the analysis performed by CodeQL Coding Standards. | Report false negative issues via the CodeQL Coding Standards [bug tracker](https://github.com/github/codeql-coding-standards/issues). |
460-
| | Modifying coding standard suite | More or less output. If queries are added to the query set more result can be reported. If queries are removed less results might be reported. | All queries supported by the CodeQL Coding Standards are listed in the release artifacts `supported_rules_list_2.15.0.csv` where VERSION is replaced with the used release. The rules in the resulting Sarif file must be cross-referenced with the expected rules in this list to determine the validity of the used CodeQL suite. | Ensure that the CodeQL Coding Standards are not modified in ways that are not documented as supported modifications. |
460+
| | Modifying coding standard suite | More or less output. If queries are added to the query set more result can be reported. If queries are removed less results might be reported. | All queries supported by the CodeQL Coding Standards are listed in the release artifacts `supported_rules_list_2.15.1.csv` where VERSION is replaced with the used release. The rules in the resulting Sarif file must be cross-referenced with the expected rules in this list to determine the validity of the used CodeQL suite. | Ensure that the CodeQL Coding Standards are not modified in ways that are not documented as supported modifications. |
461461
| | Incorrect deviation record specification | More output. Results are reported for guidelines for which a deviation is assigned. | Analysis integrity report lists all deviations and incorrectly specified deviation records with a reason. Ensure that all deviation records are correctly specified. | Ensure that the deviation record is specified according to the specification in the user manual. |
462462
| | Incorrect deviation permit specification | More output. Results are reported for guidelines for which a deviation is assigned. | Analysis integrity report lists all deviations and incorrectly specified deviation permits with a reason. Ensure that all deviation permits are correctly specified. | Ensure that the deviation record is specified according to the specification in the user manual. |
463463
| | Unapproved use of a deviation record | Less output. Results for guideline violations are not reported. | Validate that the deviation record use is approved by verifying the approved-by attribute of the deviation record specification. | Ensure that each raised deviation record is approved by an independent approver through an auditable process. |

0 commit comments

Comments
 (0)