Skip to content

Commit 7cd152e

Browse files
authored
Merge branch 'main' into rc/2.11
2 parents b1074c6 + cb22393 commit 7cd152e

File tree

209 files changed

+9155
-1214
lines changed

Some content is hidden

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

209 files changed

+9155
-1214
lines changed

.github/touch

-1
This file was deleted.

.github/workflows/code-scanning-pack-gen.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
codeql query compile --search-path c --search-path cpp --threads 0 c
8787
8888
cd ..
89-
zip -r codeql-coding-standards/code-scanning-cpp-query-pack.zip codeql-coding-standards/c/ codeql-coding-standards/cpp/ codeql-coding-standards/.codeqlmanifest.json codeql-coding-standards/supported_codeql_configs.json codeql-coding-standards/scripts/deviations codeql-coding-standards/scripts/reports
89+
zip -r codeql-coding-standards/code-scanning-cpp-query-pack.zip codeql-coding-standards/c/ codeql-coding-standards/cpp/ codeql-coding-standards/.codeqlmanifest.json codeql-coding-standards/supported_codeql_configs.json codeql-coding-standards/scripts/configuration codeql-coding-standards/scripts/reports codeql-coding-standards/scripts/shared codeql-coding-standards/scripts/guideline_recategorization codeql-coding-standards/scripts/shared codeql-coding-standards/scripts/schemas
9090
9191
- name: Upload GHAS Query Pack
9292
uses: actions/upload-artifact@v2
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: 🧰 Tooling unit tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- "rc/**"
8+
- next
9+
pull_request:
10+
branches:
11+
- main
12+
- "rc/**"
13+
- next
14+
15+
jobs:
16+
prepare-supported-codeql-env-matrix:
17+
name: Prepare supported CodeQL environment matrix
18+
runs-on: ubuntu-latest
19+
outputs:
20+
matrix: ${{ steps.export-supported-codeql-env-matrix.outputs.matrix }}
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v2
24+
25+
- name: Export supported CodeQL environment matrix
26+
id: export-supported-codeql-env-matrix
27+
run: |
28+
echo "::set-output name=matrix::$(
29+
jq --compact-output '.supported_environment | {include: .}' supported_codeql_configs.json
30+
)"
31+
32+
analysis-report-tests:
33+
name: Run analysis report tests
34+
needs: prepare-supported-codeql-env-matrix
35+
runs-on: ubuntu-latest
36+
strategy:
37+
fail-fast: false
38+
matrix: ${{ fromJSON(needs.prepare-supported-codeql-env-matrix.outputs.matrix) }}
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v2
42+
43+
- name: Install Python
44+
uses: actions/setup-python@v4
45+
with:
46+
python-version: "3.9"
47+
48+
- name: Install Python dependencies
49+
run: pip install -r scripts/reports/requirements.txt
50+
51+
- name: Cache CodeQL
52+
id: cache-codeql
53+
uses: actions/[email protected]
54+
with:
55+
path: ${{ github.workspace }}/codeql_home
56+
key: codeql-home-${{ matrix.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library }}
57+
58+
- name: Install CodeQL
59+
if: steps.cache-codeql.outputs.cache-hit != 'true'
60+
uses: ./.github/actions/install-codeql
61+
with:
62+
codeql-cli-version: ${{ matrix.codeql_cli }}
63+
codeql-stdlib-version: ${{ matrix.codeql_standard_library }}
64+
codeql-home: ${{ github.workspace }}/codeql_home
65+
add-to-path: false
66+
67+
- name: Run PyTest
68+
env:
69+
CODEQL_HOME: ${{ github.workspace }}/codeql_home
70+
run: |
71+
PATH=$PATH:$CODEQL_HOME/codeql
72+
pytest scripts/reports/analysis_report_test.py
73+
74+
recategorization-tests:
75+
name: Run Guideline Recategorization tests
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Checkout
79+
uses: actions/checkout@v2
80+
81+
- name: Install Python
82+
uses: actions/setup-python@v4
83+
with:
84+
python-version: "3.9"
85+
86+
- name: Install Python dependencies
87+
run: pip install -r scripts/guideline_recategorization/requirements.txt
88+
89+
- name: Run PyTest
90+
run: |
91+
pytest scripts/guideline_recategorization/recategorize_test.py

.github/workflows/validate-coding-standards.yml

+18-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ jobs:
2828
with:
2929
python-version: "3.9"
3030

31+
- name: Install CodeQL
32+
run: |
33+
VERSION="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
34+
gh extensions install github/gh-codeql
35+
gh codeql set-version "$VERSION"
36+
gh codeql install-stub
37+
env:
38+
GITHUB_TOKEN: ${{ github.token }}
39+
3140
- name: Install generate_package_files.py dependencies
3241
run: pip install -r scripts/requirements.txt
3342

@@ -49,14 +58,14 @@ jobs:
4958
5059
- name: Validate Package Files (CPP)
5160
run: |
52-
find rule_packages/cpp -name \*.json -exec basename {} .json \; | xargs --max-procs "$XARGS_MAX_PROCS" --max-args 1 python scripts/generate_rules/generate_package_files.py cpp
61+
find rule_packages/cpp -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py cpp
5362
git diff
5463
git diff --compact-summary
5564
git diff --quiet
5665
5766
- name: Validate Package Files (C)
5867
run: |
59-
find rule_packages/c -name \*.json -exec basename {} .json \; | xargs --max-procs "$XARGS_MAX_PROCS" --max-args 1 python scripts/generate_rules/generate_package_files.py c
68+
find rule_packages/c -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py c
6069
git diff
6170
git diff --compact-summary
6271
git diff --quiet
@@ -68,25 +77,26 @@ jobs:
6877
- name: Checkout
6978
uses: actions/checkout@v2
7079

71-
- name: Fetch CodeQL
80+
- name: Install CodeQL
7281
run: |
73-
TAG="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
74-
gh release download $TAG --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip
75-
unzip -q codeql-linux64.zip
82+
VERSION="v$( jq -r '.supported_environment | .[0] | .codeql_cli' supported_codeql_configs.json)"
83+
gh extensions install github/gh-codeql
84+
gh codeql set-version "$VERSION"
85+
gh codeql install-stub
7686
env:
7787
GITHUB_TOKEN: ${{ github.token }}
7888

7989
- name: Validate CodeQL Format (CPP)
8090
run: |
81-
find cpp -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql/codeql query format --in-place
91+
find cpp -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
8292
8393
git diff
8494
git diff --compact-summary
8595
git diff --quiet
8696
8797
- name: Validate CodeQL Format (C)
8898
run: |
89-
find c -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql/codeql query format --in-place
99+
find c -name \*.ql -or -name \*.qll -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
90100
91101
git diff
92102
git diff --compact-summary

.vscode/tasks.json

+2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
"Iterators",
223223
"Lambdas",
224224
"Language1",
225+
"Language2",
225226
"Literals",
226227
"Loops",
227228
"Macros",
@@ -253,6 +254,7 @@
253254
"Preprocessor3",
254255
"Preprocessor4",
255256
"Preprocessor5",
257+
"Preprocessor6",
256258
"IntegerConversion",
257259
"Expressions",
258260
"DeadCode",

c/cert/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: cert-c-coding-standards
2-
version: 2.11.0
2+
version: 2.13.0-dev
33
suites: codeql-suites
44
libraryPathDependencies: common-c-coding-standards

c/cert/src/rules/EXP30-C/DependenceOnOrderOfFunctionArgumentsForSideEffects.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import codingstandards.c.cert
1616
import codingstandards.cpp.SideEffect
1717
import semmle.code.cpp.dataflow.DataFlow
1818
import semmle.code.cpp.dataflow.TaintTracking
19-
import semmle.code.cpp.valuenumbering.GlobalValueNumberingImpl
19+
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
2020

2121
/** Holds if the function's return value is derived from the `AliasParamter` p. */
2222
predicate returnValueDependsOnAliasParameter(AliasParameter p) {

c/cert/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: cert-c-coding-standards-tests
2-
version: 2.11.0
2+
version: 2.13.0-dev
33
libraryPathDependencies: cert-c-coding-standards
44
extractor: cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import cpp
2+
import codingstandards.cpp.Macro
3+
import codingstandards.cpp.Naming
4+
5+
/**
6+
* Macros that cannot be replaced by functions
7+
*/
8+
abstract class IrreplaceableFunctionLikeMacro extends FunctionLikeMacro { }
9+
10+
/** A function like macro that contains the use of a stringize or tokenize operator should not be replaced by a function. */
11+
private class StringizeOrTokenizeMacro extends IrreplaceableFunctionLikeMacro {
12+
StringizeOrTokenizeMacro() {
13+
exists(TokenPastingOperator t | t.getMacro() = this) or
14+
exists(StringizingOperator s | s.getMacro() = this)
15+
}
16+
}
17+
18+
/** A standard library function like macro that should not be replaced by a function. */
19+
private class StandardLibraryFunctionLikeMacro extends IrreplaceableFunctionLikeMacro {
20+
StandardLibraryFunctionLikeMacro() { Naming::Cpp14::hasStandardLibraryMacroName(this.getName()) }
21+
}
22+
23+
/** A function like macro invocation as an `asm` argument cannot be replaced by a function. */
24+
private class AsmArgumentInvoked extends IrreplaceableFunctionLikeMacro {
25+
AsmArgumentInvoked() {
26+
any(AsmStmt s).getLocation().subsumes(this.getAnInvocation().getLocation())
27+
}
28+
}
29+
30+
/** A macro that is only invoked with constant arguments is more likely to be compile-time evaluated than a function call so do not suggest replacement. */
31+
private class OnlyConstantArgsInvoked extends IrreplaceableFunctionLikeMacro {
32+
OnlyConstantArgsInvoked() {
33+
forex(MacroInvocation mi | mi = this.getAnInvocation() |
34+
//int/float literals
35+
mi.getUnexpandedArgument(_).regexpMatch("\\d+")
36+
or
37+
//char literal or string literal, which is a literal surrounded by single quotes or double quotes
38+
mi.getUnexpandedArgument(_).regexpMatch("('[^']*'|\"[^\"]*\")")
39+
)
40+
}
41+
}
42+
43+
/** A function like macro invoked to initialize an object with static storage that cannot be replaced with a function call. */
44+
private class UsedToStaticInitialize extends IrreplaceableFunctionLikeMacro {
45+
UsedToStaticInitialize() {
46+
any(StaticStorageDurationVariable v).getInitializer().getExpr() =
47+
this.getAnInvocation().getExpr()
48+
}
49+
}
50+
51+
/** A function like macro that is called with an argument that is an operator that cannot be replaced with a function call. */
52+
private class FunctionLikeMacroWithOperatorArgument extends IrreplaceableFunctionLikeMacro {
53+
FunctionLikeMacroWithOperatorArgument() {
54+
exists(MacroInvocation mi | mi.getMacro() = this |
55+
mi.getUnexpandedArgument(_) = any(Operation op).getOperator()
56+
)
57+
}
58+
}

c/common/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name: common-c-coding-standards
2-
version: 2.11.0
2+
version: 2.13.0-dev
33
libraryPathDependencies: common-cpp-coding-standards

c/common/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: common-c-coding-standards-tests
2-
version: 2.11.0
2+
version: 2.13.0-dev
33
libraryPathDependencies: common-c-coding-standards
44
extractor: cpp

c/misra/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: misra-c-coding-standards
2-
version: 2.11.0
2+
version: 2.13.0-dev
33
suites: codeql-suites
44
libraryPathDependencies: common-c-coding-standards
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/misra/usage-of-assembly-language-should-be-documented
3+
* @name DIR-4-2: All usage of assembly language should be documented
4+
* @description Assembly language is not portable and should be documented.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity warning
8+
* @tags external/misra/id/dir-4-2
9+
* maintainability
10+
* readability
11+
* external/misra/obligation/advisory
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented
17+
18+
class UsageOfAssemblyLanguageShouldBeDocumentedQuery extends UsageOfAssemblerNotDocumentedSharedQuery {
19+
UsageOfAssemblyLanguageShouldBeDocumentedQuery() {
20+
this = Language2Package::usageOfAssemblyLanguageShouldBeDocumentedQuery()
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @id c/misra/function-over-function-like-macro
3+
* @name DIR-4-9: A function should be used in preference to a function-like macro where they are interchangeable
4+
* @description Using a function-like macro instead of a function can lead to unexpected program
5+
* behaviour.
6+
* @kind problem
7+
* @precision medium
8+
* @problem.severity recommendation
9+
* @tags external/misra/id/dir-4-9
10+
* external/misra/audit
11+
* maintainability
12+
* readability
13+
* external/misra/obligation/advisory
14+
*/
15+
16+
import cpp
17+
import codingstandards.c.misra
18+
import codingstandards.c.IrreplaceableFunctionLikeMacro
19+
20+
predicate partOfConstantExpr(MacroInvocation i) {
21+
exists(Expr e |
22+
e.isConstant() and
23+
not i.getExpr() = e and
24+
i.getExpr().getParent+() = e
25+
)
26+
}
27+
28+
from FunctionLikeMacro m
29+
where
30+
not isExcluded(m, Preprocessor6Package::functionOverFunctionLikeMacroQuery()) and
31+
not m instanceof IrreplaceableFunctionLikeMacro and
32+
//macros can have empty body
33+
not m.getBody().length() = 0 and
34+
//function call not allowed in a constant expression (where constant expr is parent)
35+
forall(MacroInvocation i | i = m.getAnInvocation() | not partOfConstantExpr(i))
36+
select m, "Macro used instead of a function."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @id c/misra/emergent-language-features-used
3+
* @name RULE-1-4: Emergent language features shall not be used
4+
* @description Emergent language features may have unpredictable behavior and should not be used.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity warning
8+
* @tags external/misra/id/rule-1-4
9+
* maintainability
10+
* readability
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.Emergent
17+
18+
from C11::EmergentLanguageFeature ef
19+
where not isExcluded(ef, Language2Package::emergentLanguageFeaturesUsedQuery())
20+
select ef, "Usage of emergent language feature."
21+

c/misra/test/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: misra-c-coding-standards-tests
2-
version: 2.11.0
2+
version: 2.13.0-dev
33
libraryPathDependencies: misra-c-coding-standards
44
extractor: cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.c:6:1:6:25 | #define MACRO4(x) (x + 1) | Macro used instead of a function. |
2+
| test.c:11:1:11:48 | #define MACRO9() printf_custom("output = %d", 7) | Macro used instead of a function. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/DIR-4-9/FunctionOverFunctionLikeMacro.ql

0 commit comments

Comments
 (0)