Skip to content

Commit 855de3c

Browse files
committed
Merge branch 'main' into knewbury01/Declarations5
2 parents a08270e + 4acb620 commit 855de3c

File tree

201 files changed

+8970
-1222
lines changed

Some content is hidden

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

201 files changed

+8970
-1222
lines changed

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

Lines changed: 1 addition & 1 deletion
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
Lines changed: 91 additions & 0 deletions
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/cache@v2.1.3
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

Lines changed: 18 additions & 8 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
"Iterators",
224224
"Lambdas",
225225
"Language1",
226+
"Language2",
226227
"Literals",
227228
"Loops",
228229
"Macros",

c/cert/src/qlpack.yml

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

c/cert/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: cert-c-coding-standards-tests
2-
version: 2.12.0-dev
2+
version: 2.13.0-dev
33
libraryPathDependencies: cert-c-coding-standards
44
extractor: cpp

c/common/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name: common-c-coding-standards
2-
version: 2.12.0-dev
2+
version: 2.13.0-dev
33
libraryPathDependencies: common-cpp-coding-standards

c/common/test/qlpack.yml

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

c/misra/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: misra-c-coding-standards
2-
version: 2.12.0-dev
2+
version: 2.13.0-dev
33
suites: codeql-suites
44
libraryPathDependencies: common-c-coding-standards
Lines changed: 22 additions & 0 deletions
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+
}
Lines changed: 21 additions & 0 deletions
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/src/rules/RULE-21-19/ValuesReturnedByLocaleSettingUsedAsPtrToConst.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @description The pointers returned by the Standard Library functions localeconv, getenv,
55
* setlocale or, strerror shall only be used as if they have pointer to const-qualified
66
* type.
7-
* @kind problem
7+
* @kind path-problem
88
* @precision very-high
99
* @problem.severity error
1010
* @tags external/misra/id/rule-21-19

c/misra/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: misra-c-coding-standards-tests
2-
version: 2.12.0-dev
2+
version: 2.13.0-dev
33
libraryPathDependencies: misra-c-coding-standards
44
extractor: cpp
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
| test.c:1:1:1:21 | #include <stdalign.h> | Usage of emergent language feature. |
2+
| test.c:2:1:2:22 | #include <stdatomic.h> | Usage of emergent language feature. |
3+
| test.c:3:1:3:24 | #include <stdnoreturn.h> | Usage of emergent language feature. |
4+
| test.c:4:1:4:20 | #include <threads.h> | Usage of emergent language feature. |
5+
| test.c:6:1:6:49 | #define MACRO(x) _Generic((x), int : 0, long : 1) | Usage of emergent language feature. |
6+
| test.c:7:1:7:32 | #define __STDC_WANT_LIB_EXT1__ 1 | Usage of emergent language feature. |
7+
| test.c:9:16:9:17 | f0 | Usage of emergent language feature. |
8+
| test.c:12:26:12:40 | atomic_new_type | Usage of emergent language feature. |
9+
| test.c:17:15:17:15 | i | Usage of emergent language feature. |
10+
| test.c:19:3:19:10 | alignas(...) | Usage of emergent language feature. |
11+
| test.c:20:3:20:9 | alignas(...) | Usage of emergent language feature. |
12+
| test.c:21:11:21:23 | alignof(int) | Usage of emergent language feature. |
13+
| test.c:22:12:22:23 | alignof(int) | Usage of emergent language feature. |
14+
| test.c:24:27:24:28 | i3 | Usage of emergent language feature. |
15+
| test.c:25:28:25:29 | i4 | Usage of emergent language feature. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql

c/misra/test/rules/RULE-1-4/test.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdalign.h> //NON_COMPLIANT
2+
#include <stdatomic.h> //NON_COMPLIANT
3+
#include <stdnoreturn.h> //NON_COMPLIANT
4+
#include <threads.h> //NON_COMPLIANT
5+
6+
#define MACRO(x) _Generic((x), int : 0, long : 1) // NON_COMPLIANT
7+
#define __STDC_WANT_LIB_EXT1__ 1 // NON_COMPLIANT
8+
9+
_Noreturn void f0(); // NON_COMPLIANT
10+
11+
typedef int new_type; // COMPLIANT
12+
typedef _Atomic new_type atomic_new_type; // NON_COMPLIANT
13+
14+
void f(int p) {
15+
int i0 = _Generic(p, int : 0, long : 1); // NON_COMPLIANT[FALSE_NEGATIVE]
16+
17+
_Atomic int i; // NON_COMPLIANT
18+
19+
_Alignas(4) int i1; // NON_COMPLIANT
20+
alignas(4) int i2; // NON_COMPLIANT
21+
int a = _Alignof(int); // NON_COMPLIANT
22+
int a1 = alignof(int); // NON_COMPLIANT
23+
24+
static thread_local int i3; // NON_COMPLIANT
25+
static _Thread_local int i4; // NON_COMPLIANT
26+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add the Python scripts under `scripts/guideline_recategorization` and the JSON schemas under `schemas`.
2+
- Add the Python scripts under `scripts/shared` relied upon by the analysis report generation.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- `M27-0-1`
2+
- `CstdioTypesUsed.ql` - Exclude `size_t` from this rule, as it can be provided by headers other than `<cstdio>`.
3+
- `CstdioMacrosUsed.ql` - Exclude `NULL` from this rule, as it can be provided by headers other than `<cstdio>`.

cpp/autosar/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: autosar-cpp-coding-standards
2-
version: 2.12.0-dev
2+
version: 2.13.0-dev
33
suites: codeql-suites
44
libraryPathDependencies: common-cpp-coding-standards

cpp/autosar/src/rules/A18-5-8/UnnecessaryUseOfDynamicStorage.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ class MakeSharedOrUnique extends FunctionCall, CandidateFunctionLocalHeapAllocat
6464
* An `AllocationExpr` that allocates heap memory, where the memory is freed on at least one path
6565
* through the enclosing function.
6666
*/
67-
class AllocationExprFunctionLocal extends AllocationExpr, CandidateFunctionLocalHeapAllocationExpr {
67+
class AllocationExprFunctionLocal extends CandidateFunctionLocalHeapAllocationExpr instanceof AllocationExpr {
6868
AllocationExprFunctionLocal() {
6969
this.getSizeBytes() < 1024 and
7070
TaintTracking::localExprTaint(this, any(DeallocationExpr de).getFreedExpr())
7171
}
7272

73-
override int getHeapSizeBytes() { result = this.getSizeBytes() }
73+
override int getHeapSizeBytes() { result = super.getSizeBytes() }
7474

7575
DeallocationExpr getADeallocation() { TaintTracking::localExprTaint(this, result.getFreedExpr()) }
7676

cpp/autosar/src/rules/M27-0-1/CstdioMacrosUsed.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from MacroInvocation mi
2222
where
2323
not isExcluded(mi, BannedLibrariesPackage::cstdioMacrosUsedQuery()) and
2424
mi.getMacroName() in [
25-
"BUFSIZ", "EOF", "FILENAME_MAX", "FOPEN_MAX", "L_tmpnam", "NULL", "TMP_MAX", "_IOFBF",
26-
"IOLBF", "_IONBF", "SEEK_CUR", "SEEK_END", "SEEK_SET"
25+
"BUFSIZ", "EOF", "FILENAME_MAX", "FOPEN_MAX", "L_tmpnam", "TMP_MAX", "_IOFBF", "IOLBF",
26+
"_IONBF", "SEEK_CUR", "SEEK_END", "SEEK_SET"
2727
]
2828
select mi, "Use of <cstdio> macro '" + mi.getMacroName() + "'."

cpp/autosar/src/rules/M27-0-1/CstdioTypesUsed.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ from TypeMention tm, UserType ut
2222
where
2323
not isExcluded(tm, BannedLibrariesPackage::cstdioTypesUsedQuery()) and
2424
ut = tm.getMentionedType() and
25-
ut.hasGlobalOrStdName(["FILE", "fpos_t", "size_t"])
25+
ut.hasGlobalOrStdName(["FILE", "fpos_t"])
2626
select tm, "Use of <cstdio> type '" + ut.getQualifiedName() + "'."

cpp/autosar/src/rules/M7-4-1/UsageOfAssemblerNotDocumented.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
import cpp
1919
import codingstandards.cpp.autosar
20+
import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented
2021

21-
from AsmStmt a
22-
where
23-
not isExcluded(a, BannedLibrariesPackage::usageOfAssemblerNotDocumentedQuery()) and
24-
not exists(Comment c | c.getCommentedElement() = a) and
25-
not a.isAffectedByMacro()
26-
select a, "Use of assembler is not documented."
22+
class UsageOfAssemblerNotDocumentedQuery extends UsageOfAssemblerNotDocumentedSharedQuery {
23+
UsageOfAssemblerNotDocumentedQuery() {
24+
this = BannedLibrariesPackage::usageOfAssemblerNotDocumentedQuery()
25+
}
26+
}

cpp/autosar/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: autosar-cpp-coding-standards-tests
2-
version: 2.12.0-dev
2+
version: 2.13.0-dev
33
libraryPathDependencies: autosar-cpp-coding-standards
44
extractor: cpp

cpp/autosar/test/rules/M27-0-1/CstdioMacrosUsed.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
| test.cpp:30:29:30:37 | FOPEN_MAX | Use of <cstdio> macro 'FOPEN_MAX'. |
88
| test.cpp:41:14:41:16 | EOF | Use of <cstdio> macro 'EOF'. |
99
| test.cpp:50:24:50:31 | SEEK_SET | Use of <cstdio> macro 'SEEK_SET'. |
10-
| test.cpp:60:10:60:13 | NULL | Use of <cstdio> macro 'NULL'. |
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
| test.cpp:4:8:4:11 | type mention | Use of <cstdio> type 'std::FILE'. |
22
| test.cpp:6:8:6:13 | type mention | Use of <cstdio> type 'std::fpos_t'. |
3-
| test.cpp:20:18:20:23 | type mention | Use of <cstdio> type 'size_t'. |
4-
| test.cpp:21:18:21:23 | type mention | Use of <cstdio> type 'size_t'. |
53
| test.cpp:34:3:34:6 | type mention | Use of <cstdio> type 'FILE'. |
64
| test.cpp:36:3:36:8 | type mention | Use of <cstdio> type 'fpos_t'. |
7-
| test.cpp:50:14:50:19 | type mention | Use of <cstdio> type 'size_t'. |

0 commit comments

Comments
 (0)