Skip to content

Commit bc842ad

Browse files
Merge remote-tracking branch 'origin/main' into michaelrfairhurst/deadcode-4-rule-0-0-2
2 parents 7de954c + ca3c09c commit bc842ad

File tree

49 files changed

+290404
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+290404
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- "Function-like macros"
2+
- The parameter list of variadic macros previously included the ellipsis in name of the final parameter, potentially leading to incorrect analysis. This has been corrected.
3+
- The parameter list of function-like macros with no parameters (i.e. `MACRO()`) was interpreted in a shared library as having a single parameter with an empty name. This does not seem to have had an impact on any existing queries, but has been fixed to correctly show no parameters.

cpp/common/src/codingstandards/cpp/Identifiers.qll

Lines changed: 446 additions & 0 deletions
Large diffs are not rendered by default.

cpp/common/src/codingstandards/cpp/Macro.qll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import cpp
22

33
/**
4-
* Macros with a parameter
4+
* Macros with parentheses, e.g. `#define MACRO(x) (x * 2)`.
5+
*
6+
* Note that this includes macros with empty parameter lists, e.g. `#define MACRO() 42`.
57
*/
68
class FunctionLikeMacro extends Macro {
79
FunctionLikeMacro() { this.getHead().regexpMatch("[_a-zA-Z0-9]+\\s*\\([^\\)]*?\\)") }
810

911
string getParameter(int i) {
1012
result =
11-
this.getHead().regexpCapture("[_a-zA-Z0-9]+\\s*\\(([^\\)]*)\\)", 1).splitAt(",", i).trim()
13+
this.getHead()
14+
.regexpCapture("[_a-zA-Z0-9]+\\s*\\(([^\\)]*)\\)", 1)
15+
.splitAt(",", i)
16+
.trim()
17+
.replaceAll("...", "") and
18+
not result = ""
1219
}
1320

1421
string getAParameter() { result = getParameter(_) }
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import codeql.util.Numbers
2+
3+
/**
4+
* Provides properties of a Unicode code point, where the property is of 'enumeration', 'catalog',
5+
* or 'string-valued' type, however, the only supported property is `NFC_QC`.
6+
*
7+
* For example, `Block` is an enumeration property, `Line_Break` is a catalog property, and
8+
* `Uppercase_Mapping` is a string-valued property.
9+
*
10+
* For boolean properties, see `unicodeHasBooleanProperty`, and for numeric properties, see
11+
* `unicodeHasNumericProperty`.
12+
*/
13+
extensible predicate unicodeHasProperty(int codePoint, string propertyName, string propertyValue);
14+
15+
/**
16+
* Holds when the Unicode code point's boolean property of the given name is true.
17+
*
18+
* For example, `Alphabetic` is a boolean property that can be true or false for a code point.
19+
*
20+
* For other types of properties, see `unicodeHasProperty`.
21+
*/
22+
extensible predicate unicodeHasBooleanProperty(int codePoint, string propertyName);
23+
24+
bindingset[input]
25+
int unescapedCodePointAt(string input, int index) {
26+
exists(string match |
27+
match = input.regexpFind("(\\\\u[0-9a-fA-F]{4}|.)", index, _) and
28+
if match.matches("\\u%")
29+
then result = parseHexInt(match.substring(2, match.length()))
30+
else result = match.codePointAt(0)
31+
)
32+
}
33+
34+
bindingset[input]
35+
string unescapeUnicode(string input) {
36+
result =
37+
concat(int code, int idx |
38+
code = unescapedCodePointAt(input, idx)
39+
|
40+
code.toUnicode() order by idx
41+
)
42+
}
43+
44+
bindingset[id]
45+
predicate nonUax44IdentifierCodepoint(string id, int index) {
46+
exists(int codePoint |
47+
codePoint = id.codePointAt(index) and
48+
(
49+
not unicodeHasBooleanProperty(codePoint, "XID_Start") and
50+
not unicodeHasBooleanProperty(codePoint, "XID_Continue")
51+
or
52+
index = 0 and
53+
not unicodeHasBooleanProperty(codePoint, "XID_Start")
54+
)
55+
)
56+
}
57+
58+
bindingset[id]
59+
predicate nonNfcNormalizedCodepoint(string id, int index, string noOrMaybe) {
60+
exists(int codePoint |
61+
codePoint = id.codePointAt(index) and
62+
unicodeHasProperty(codePoint, "NFC_QC", noOrMaybe) and
63+
noOrMaybe = ["N", "M"]
64+
)
65+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Classes2Query =
7+
TVirtualInheritanceNotAllowedQuery() or
8+
TMemberSpecifiersNotUsedAppropriatelyQuery() or
9+
TPrivateAndPublicDataMembersMixedQuery() or
10+
TInvalidSignatureForSpecialMemberFunctionQuery() or
11+
TNonExplicitConversionMemberQuery() or
12+
TLogicalAndAndLogicalOrOperatorsOverloadedQuery() or
13+
TInvalidOperatorOverloadedAsMemberFunctionQuery()
14+
15+
predicate isClasses2QueryMetadata(Query query, string queryId, string ruleId, string category) {
16+
query =
17+
// `Query` instance for the `virtualInheritanceNotAllowed` query
18+
Classes2Package::virtualInheritanceNotAllowedQuery() and
19+
queryId =
20+
// `@id` for the `virtualInheritanceNotAllowed` query
21+
"cpp/misra/virtual-inheritance-not-allowed" and
22+
ruleId = "RULE-13-1-1" and
23+
category = "advisory"
24+
or
25+
query =
26+
// `Query` instance for the `memberSpecifiersNotUsedAppropriately` query
27+
Classes2Package::memberSpecifiersNotUsedAppropriatelyQuery() and
28+
queryId =
29+
// `@id` for the `memberSpecifiersNotUsedAppropriately` query
30+
"cpp/misra/member-specifiers-not-used-appropriately" and
31+
ruleId = "RULE-13-3-1" and
32+
category = "required"
33+
or
34+
query =
35+
// `Query` instance for the `privateAndPublicDataMembersMixed` query
36+
Classes2Package::privateAndPublicDataMembersMixedQuery() and
37+
queryId =
38+
// `@id` for the `privateAndPublicDataMembersMixed` query
39+
"cpp/misra/private-and-public-data-members-mixed" and
40+
ruleId = "RULE-14-1-1" and
41+
category = "advisory"
42+
or
43+
query =
44+
// `Query` instance for the `invalidSignatureForSpecialMemberFunction` query
45+
Classes2Package::invalidSignatureForSpecialMemberFunctionQuery() and
46+
queryId =
47+
// `@id` for the `invalidSignatureForSpecialMemberFunction` query
48+
"cpp/misra/invalid-signature-for-special-member-function" and
49+
ruleId = "RULE-15-0-2" and
50+
category = "advisory"
51+
or
52+
query =
53+
// `Query` instance for the `nonExplicitConversionMember` query
54+
Classes2Package::nonExplicitConversionMemberQuery() and
55+
queryId =
56+
// `@id` for the `nonExplicitConversionMember` query
57+
"cpp/misra/non-explicit-conversion-member" and
58+
ruleId = "RULE-15-1-3" and
59+
category = "required"
60+
or
61+
query =
62+
// `Query` instance for the `logicalAndAndLogicalOrOperatorsOverloaded` query
63+
Classes2Package::logicalAndAndLogicalOrOperatorsOverloadedQuery() and
64+
queryId =
65+
// `@id` for the `logicalAndAndLogicalOrOperatorsOverloaded` query
66+
"cpp/misra/logical-and-and-logical-or-operators-overloaded" and
67+
ruleId = "RULE-16-5-1" and
68+
category = "required"
69+
or
70+
query =
71+
// `Query` instance for the `invalidOperatorOverloadedAsMemberFunction` query
72+
Classes2Package::invalidOperatorOverloadedAsMemberFunctionQuery() and
73+
queryId =
74+
// `@id` for the `invalidOperatorOverloadedAsMemberFunction` query
75+
"cpp/misra/invalid-operator-overloaded-as-member-function" and
76+
ruleId = "RULE-16-6-1" and
77+
category = "advisory"
78+
}
79+
80+
module Classes2Package {
81+
Query virtualInheritanceNotAllowedQuery() {
82+
//autogenerate `Query` type
83+
result =
84+
// `Query` type for `virtualInheritanceNotAllowed` query
85+
TQueryCPP(TClasses2PackageQuery(TVirtualInheritanceNotAllowedQuery()))
86+
}
87+
88+
Query memberSpecifiersNotUsedAppropriatelyQuery() {
89+
//autogenerate `Query` type
90+
result =
91+
// `Query` type for `memberSpecifiersNotUsedAppropriately` query
92+
TQueryCPP(TClasses2PackageQuery(TMemberSpecifiersNotUsedAppropriatelyQuery()))
93+
}
94+
95+
Query privateAndPublicDataMembersMixedQuery() {
96+
//autogenerate `Query` type
97+
result =
98+
// `Query` type for `privateAndPublicDataMembersMixed` query
99+
TQueryCPP(TClasses2PackageQuery(TPrivateAndPublicDataMembersMixedQuery()))
100+
}
101+
102+
Query invalidSignatureForSpecialMemberFunctionQuery() {
103+
//autogenerate `Query` type
104+
result =
105+
// `Query` type for `invalidSignatureForSpecialMemberFunction` query
106+
TQueryCPP(TClasses2PackageQuery(TInvalidSignatureForSpecialMemberFunctionQuery()))
107+
}
108+
109+
Query nonExplicitConversionMemberQuery() {
110+
//autogenerate `Query` type
111+
result =
112+
// `Query` type for `nonExplicitConversionMember` query
113+
TQueryCPP(TClasses2PackageQuery(TNonExplicitConversionMemberQuery()))
114+
}
115+
116+
Query logicalAndAndLogicalOrOperatorsOverloadedQuery() {
117+
//autogenerate `Query` type
118+
result =
119+
// `Query` type for `logicalAndAndLogicalOrOperatorsOverloaded` query
120+
TQueryCPP(TClasses2PackageQuery(TLogicalAndAndLogicalOrOperatorsOverloadedQuery()))
121+
}
122+
123+
Query invalidOperatorOverloadedAsMemberFunctionQuery() {
124+
//autogenerate `Query` type
125+
result =
126+
// `Query` type for `invalidOperatorOverloadedAsMemberFunction` query
127+
TQueryCPP(TClasses2PackageQuery(TInvalidOperatorOverloadedAsMemberFunctionQuery()))
128+
}
129+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Naming2Query = TPoorlyFormedIdentifierQuery()
7+
8+
predicate isNaming2QueryMetadata(Query query, string queryId, string ruleId, string category) {
9+
query =
10+
// `Query` instance for the `poorlyFormedIdentifier` query
11+
Naming2Package::poorlyFormedIdentifierQuery() and
12+
queryId =
13+
// `@id` for the `poorlyFormedIdentifier` query
14+
"cpp/misra/poorly-formed-identifier" and
15+
ruleId = "RULE-5-10-1" and
16+
category = "required"
17+
}
18+
19+
module Naming2Package {
20+
Query poorlyFormedIdentifierQuery() {
21+
//autogenerate `Query` type
22+
result =
23+
// `Query` type for `poorlyFormedIdentifier` query
24+
TQueryCPP(TNaming2PackageQuery(TPoorlyFormedIdentifierQuery()))
25+
}
26+
}

cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import BannedLibraries
99
import BannedSyntax
1010
import BannedTypes
1111
import Classes
12+
import Classes2
1213
import Comments
1314
import Concurrency
1415
import Conditionals
@@ -45,6 +46,7 @@ import Memory2
4546
import Memory3
4647
import MoveForward
4748
import Naming
49+
import Naming2
4850
import Null
4951
import OperatorInvariants
5052
import Operators
@@ -78,6 +80,7 @@ newtype TCPPQuery =
7880
TBannedSyntaxPackageQuery(BannedSyntaxQuery q) or
7981
TBannedTypesPackageQuery(BannedTypesQuery q) or
8082
TClassesPackageQuery(ClassesQuery q) or
83+
TClasses2PackageQuery(Classes2Query q) or
8184
TCommentsPackageQuery(CommentsQuery q) or
8285
TConcurrencyPackageQuery(ConcurrencyQuery q) or
8386
TConditionalsPackageQuery(ConditionalsQuery q) or
@@ -114,6 +117,7 @@ newtype TCPPQuery =
114117
TMemory3PackageQuery(Memory3Query q) or
115118
TMoveForwardPackageQuery(MoveForwardQuery q) or
116119
TNamingPackageQuery(NamingQuery q) or
120+
TNaming2PackageQuery(Naming2Query q) or
117121
TNullPackageQuery(NullQuery q) or
118122
TOperatorInvariantsPackageQuery(OperatorInvariantsQuery q) or
119123
TOperatorsPackageQuery(OperatorsQuery q) or
@@ -147,6 +151,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
147151
isBannedSyntaxQueryMetadata(query, queryId, ruleId, category) or
148152
isBannedTypesQueryMetadata(query, queryId, ruleId, category) or
149153
isClassesQueryMetadata(query, queryId, ruleId, category) or
154+
isClasses2QueryMetadata(query, queryId, ruleId, category) or
150155
isCommentsQueryMetadata(query, queryId, ruleId, category) or
151156
isConcurrencyQueryMetadata(query, queryId, ruleId, category) or
152157
isConditionalsQueryMetadata(query, queryId, ruleId, category) or
@@ -183,6 +188,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
183188
isMemory3QueryMetadata(query, queryId, ruleId, category) or
184189
isMoveForwardQueryMetadata(query, queryId, ruleId, category) or
185190
isNamingQueryMetadata(query, queryId, ruleId, category) or
191+
isNaming2QueryMetadata(query, queryId, ruleId, category) or
186192
isNullQueryMetadata(query, queryId, ruleId, category) or
187193
isOperatorInvariantsQueryMetadata(query, queryId, ruleId, category) or
188194
isOperatorsQueryMetadata(query, queryId, ruleId, category) or

0 commit comments

Comments
 (0)