Skip to content

Commit db37944

Browse files
authored
Merge branch 'main' into rp/m0-1-10-711
2 parents 97bf53a + baa6ecd commit db37944

File tree

304 files changed

+1895
-621
lines changed

Some content is hidden

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

304 files changed

+1895
-621
lines changed

.github/workflows/codeql_unit_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
file.close()
152152
153153
- name: Upload test results
154-
uses: actions/upload-artifact@v3
154+
uses: actions/upload-artifact@v4
155155
with:
156156
name: ${{ matrix.language }}-test-results-${{ runner.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }}
157157
path: |
@@ -171,7 +171,7 @@ jobs:
171171
script: |
172172
core.setFailed('Test run job failed')
173173
- name: Collect test results
174-
uses: actions/download-artifact@v3
174+
uses: actions/download-artifact@v4
175175

176176
- name: Validate test results
177177
run: |

.github/workflows/dispatch-matrix-check.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ jobs:
2020
with:
2121
minimum-permission: "write"
2222

23+
- name: Generate token
24+
id: generate-token
25+
uses: actions/create-github-app-token@v1
26+
with:
27+
app-id: ${{ vars.AUTOMATION_APP_ID }}
28+
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}
29+
owner: ${{ github.repository_owner }}
30+
repositories: "codeql-coding-standards-release-engineering"
31+
2332
- name: Dispatch Matrix Testing Job
2433
if: steps.check-write-permission.outputs.has-permission
2534
uses: peter-evans/repository-dispatch@v2
2635
with:
27-
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
36+
token: ${{ steps.generate-token.outputs.token }}
2837
repository: github/codeql-coding-standards-release-engineering
2938
event-type: matrix-test
3039
client-payload: '{"pr": "${{ github.event.number }}"}'

.github/workflows/dispatch-matrix-test-on-comment.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ jobs:
1717
with:
1818
minimum-permission: "write"
1919

20+
- name: Generate token
21+
id: generate-token
22+
uses: actions/create-github-app-token@v1
23+
with:
24+
app-id: ${{ vars.AUTOMATION_APP_ID }}
25+
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}
26+
owner: ${{ github.repository_owner }}
27+
repositories: "codeql-coding-standards-release-engineering"
28+
2029
- name: Dispatch Matrix Testing Job
2130
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-matrix') && steps.check-write-permission.outputs.has-permission }}
2231
uses: peter-evans/repository-dispatch@v2
2332
with:
24-
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
33+
token: ${{ steps.generate-token.outputs.token }}
2534
repository: github/codeql-coding-standards-release-engineering
2635
event-type: matrix-test
2736
client-payload: '{"pr": "${{ github.event.issue.number }}"}'

.github/workflows/dispatch-release-performance-check.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ jobs:
1717
with:
1818
minimum-permission: "write"
1919

20+
- name: Generate token
21+
id: generate-token
22+
uses: actions/create-github-app-token@v1
23+
with:
24+
app-id: ${{ vars.AUTOMATION_APP_ID }}
25+
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}
26+
owner: ${{ github.repository_owner }}
27+
repositories: "codeql-coding-standards-release-engineering"
28+
2029
- name: Dispatch Performance Testing Job
2130
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/test-performance') && steps.check-write-permission.outputs.has-permission }}
2231
uses: peter-evans/repository-dispatch@v2
2332
with:
24-
token: ${{ secrets.RELEASE_ENGINEERING_TOKEN }}
33+
token: ${{ steps.generate-token.outputs.token }}
2534
repository: github/codeql-coding-standards-release-engineering
2635
event-type: performance-test
2736
client-payload: '{"pr": "${{ github.event.issue.number }}"}'

.github/workflows/finalize-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
- name: Generate token
104104
if: env.HOTFIX_RELEASE == 'false'
105105
id: generate-token
106-
uses: actions/create-github-app-token@eaddb9eb7e4226c68cf4b39f167c83e5bd132b3e
106+
uses: actions/create-github-app-token@v1
107107
with:
108108
app-id: ${{ vars.AUTOMATION_APP_ID }}
109109
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}

.github/workflows/prepare-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143
144144
- name: Generate token
145145
id: generate-token
146-
uses: actions/create-github-app-token@eaddb9eb7e4226c68cf4b39f167c83e5bd132b3e
146+
uses: actions/create-github-app-token@v1
147147
with:
148148
app-id: ${{ vars.AUTOMATION_APP_ID }}
149149
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}

.github/workflows/standard_library_upgrade_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143
}, test_summary_file)
144144
145145
- name: Upload test results
146-
uses: actions/upload-artifact@v3
146+
uses: actions/upload-artifact@v4
147147
with:
148148
name: test-results-${{runner.os}}-${{matrix.codeql_cli}}-${{matrix.codeql_standard_library_ident}}
149149
path: |
@@ -162,7 +162,7 @@ jobs:
162162
python-version: "3.9"
163163

164164
- name: Collect test results
165-
uses: actions/download-artifact@v2
165+
uses: actions/download-artifact@v4
166166

167167
- name: Validate test results
168168
shell: python

.github/workflows/update-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
- name: Generate token
4545
id: generate-token
46-
uses: actions/create-github-app-token@eaddb9eb7e4226c68cf4b39f167c83e5bd132b3e
46+
uses: actions/create-github-app-token@v1
4747
with:
4848
app-id: ${{ vars.AUTOMATION_APP_ID }}
4949
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}

.github/workflows/upgrade_codeql_dependencies.yml

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ jobs:
1818
runs-on: ubuntu-22.04
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v2
21+
uses: actions/checkout@v4
22+
23+
- name: Fetch CodeQL
24+
env:
25+
GITHUB_TOKEN: ${{ github.token }}
26+
RUNNER_TEMP: ${{ runner.temp }}
27+
run: |
28+
cd $RUNNER_TEMP
29+
gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip
30+
unzip -q codeql-linux64.zip
31+
echo "$RUNNER_TEMP/codeql/" >> $GITHUB_PATH
2232
2333
- name: Install Python
24-
uses: actions/setup-python@v4
34+
uses: actions/setup-python@v5
2535
with:
2636
python-version: "3.9"
2737

@@ -35,27 +45,27 @@ jobs:
3545
run: |
3646
python3 scripts/upgrade-codeql-dependencies/upgrade-codeql-dependencies.py --cli-version "$CODEQL_CLI_VERSION"
3747
38-
- name: Fetch CodeQL
39-
env:
40-
GITHUB_TOKEN: ${{ github.token }}
41-
RUNNER_TEMP: ${{ runner.temp }}
42-
run: |
43-
cd $RUNNER_TEMP
44-
gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip
45-
unzip -q codeql-linux64.zip
46-
4748
- name: Update CodeQL formatting based on new CLI version
4849
env:
4950
RUNNER_TEMP: ${{ runner.temp }}
5051
run: |
51-
find cpp \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" $RUNNER_TEMP/codeql/codeql query format --in-place
52-
find c \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" $RUNNER_TEMP/codeql/codeql query format --in-place
52+
find cpp \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
53+
find c \( -name '*.ql' -or -name '*.qll' \) -print0 | xargs -0 --max-procs "$XARGS_MAX_PROCS" codeql query format --in-place
5354
5455
- name: Create Pull Request
55-
uses: peter-evans/create-pull-request@v3
56+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
5657
with:
57-
title: "Upgrading `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}"
58-
body: "This PR upgrades the CodeQL CLI version to ${{ github.event.inputs.codeql_cli_version }}."
58+
title: "Upgrade `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}"
59+
body: |
60+
This PR upgrades the CodeQL CLI version to ${{ github.event.inputs.codeql_cli_version }}.
61+
62+
## CodeQL dependency upgrade checklist:
63+
64+
- [ ] Confirm the code has been correctly reformatted according to the new CodeQL CLI.
65+
- [ ] Identify any CodeQL compiler warnings and errors, and update queries as required.
66+
- [ ] Validate that the `github/codeql` test cases succeed.
67+
- [ ] Address any CodeQL test failures in the `github/codeql-coding-standards` repository.
68+
- [ ] Validate performance vs pre-upgrade, using /test-performance
5969
commit-message: "Upgrading `github/codeql` dependency to ${{ github.event.inputs.codeql_cli_version }}"
6070
delete-branch: true
6171
branch: "codeql/upgrade-to-${{ github.event.inputs.codeql_cli_version }}"

.github/workflows/validate-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
steps:
4141
- name: Generate token
4242
id: generate-token
43-
uses: actions/create-github-app-token@eaddb9eb7e4226c68cf4b39f167c83e5bd132b3e
43+
uses: actions/create-github-app-token@v1
4444
with:
4545
app-id: ${{ vars.AUTOMATION_APP_ID }}
4646
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}
@@ -108,7 +108,7 @@ jobs:
108108
steps:
109109
- name: Generate token
110110
id: generate-token
111-
uses: actions/create-github-app-token@eaddb9eb7e4226c68cf4b39f167c83e5bd132b3e
111+
uses: actions/create-github-app-token@v1
112112
with:
113113
app-id: ${{ vars.AUTOMATION_APP_ID }}
114114
private-key: ${{ secrets.AUTOMATION_PRIVATE_KEY }}

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ The following coding standards are supported:
1818

1919
## :construction: Standards under development :construction:
2020

21-
- [MISRA C++ 2023](https://misra.org.uk/product/misra-cpp2023/) - under development _scheduled for release 2024 Q4_.
21+
The following standards are under active development:
22+
23+
- [MISRA C++ 2023](https://misra.org.uk/product/misra-cpp2023/) - under development - _scheduled for release 2025 Q1_
24+
- [MISRA C 2023](https://misra.org.uk/product/misra-c2023/) - under development - _scheduled for release 2025 Q1_
25+
- This includes the development of [MISRA C 2012 Amendment 3](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD3.pdf) and [MISRA C 2012 Amendment 4](https://misra.org.uk/app/uploads/2021/06/MISRA-C-2012-AMD4.pdf), which are incorporated into MISRA C 2023.
2226

2327
## How do I use the CodeQL Coding Standards Queries?
2428

c/common/src/codingstandards/c/Extensions.qll

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,28 @@ import codingstandards.cpp.Extensions
44
/**
55
* Common base class for modeling compiler extensions.
66
*/
7-
abstract class CCompilerExtension extends CompilerExtension { }
7+
abstract class CCompilerExtension extends CompilerExtension {
8+
abstract string getMessage();
9+
}
810

911
// Reference: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#Other-Builtins
1012
abstract class CConditionalDefineExtension extends CCompilerExtension, PreprocessorIfdef {
13+
string feature;
14+
1115
CConditionalDefineExtension() {
12-
exists(toString().indexOf("__has_builtin")) or
13-
exists(toString().indexOf("__has_constexpr_builtin")) or
14-
exists(toString().indexOf("__has_feature")) or
15-
exists(toString().indexOf("__has_extension")) or
16-
exists(toString().indexOf("__has_attribute")) or
17-
exists(toString().indexOf("__has_declspec_attribute")) or
18-
exists(toString().indexOf("__is_identifier")) or
19-
exists(toString().indexOf("__has_include")) or
20-
exists(toString().indexOf("__has_include_next")) or
21-
exists(toString().indexOf("__has_warning"))
16+
feature =
17+
[
18+
"__has_builtin", "__has_constexpr_builtin", "__has_feature", "__has_extension",
19+
"__has_attribute", "__has_declspec_attribute", "__is_identifier", "__has_include",
20+
"__has_include_next", "__has_warning"
21+
] and
22+
exists(toString().indexOf(feature))
23+
}
24+
25+
override string getMessage() {
26+
result =
27+
"Call to builtin function '" + feature +
28+
"' is a compiler extension and is not portable to other compilers."
2229
}
2330
}
2431

@@ -31,6 +38,12 @@ class CMacroBasedExtension extends CCompilerExtension, Macro {
3138
"__clang_version__", "__clang_literal_encoding__", "__clang_wide_literal_encoding__"
3239
]
3340
}
41+
42+
override string getMessage() {
43+
result =
44+
"Use of builtin macro '" + getBody() +
45+
"' is a compiler extension and is not portable to other compilers."
46+
}
3447
}
3548

3649
// Reference: https://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html#Variable-Attributes
@@ -41,6 +54,12 @@ class CAttributeExtension extends CCompilerExtension, Attribute {
4154
"fallthrough", "read_only", "alias"
4255
]
4356
}
57+
58+
override string getMessage() {
59+
result =
60+
"Use of attribute '" + getName() +
61+
"' is a compiler extension and is not portable to other compilers."
62+
}
4463
}
4564

4665
// Reference: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html#g_t_005f_005fsync-Builtins
@@ -61,21 +80,41 @@ class CFunctionExtension extends CCompilerExtension, FunctionCall {
6180
// the built-in extensions
6281
getTarget().getName().indexOf("__builtin_") = 0
6382
}
83+
84+
override string getMessage() {
85+
result =
86+
"Call to builtin function '" + getTarget().getName() +
87+
"' is a compiler extension and is not portable to other compilers."
88+
}
6489
}
6590

6691
// Reference: https://gcc.gnu.org/onlinedocs/gcc/Alignment.html#Alignment
6792
class CFunctionLikeExtension extends CCompilerExtension, AlignofExprOperator {
6893
CFunctionLikeExtension() { exists(getValueText().indexOf("__alignof__")) }
94+
95+
override string getMessage() {
96+
result = "'__alignof__' is a compiler extension and is not portable to other compilers."
97+
}
6998
}
7099

71100
// Reference: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs
72-
class CStmtExprExtension extends CCompilerExtension, StmtExpr { }
101+
class CStmtExprExtension extends CCompilerExtension, StmtExpr {
102+
override string getMessage() {
103+
result =
104+
"Statement expressions are a compiler extension and are not portable to other compilers."
105+
}
106+
}
73107

74108
// Use of ternary like the following: `int a = 0 ?: 0;` where the
75109
// one of the branches is omitted
76110
// Reference: https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html#Conditionals
77111
class CTerseTernaryExtension extends CCompilerExtension, ConditionalExpr {
78112
CTerseTernaryExtension() { getCondition() = getElse() or getCondition() = getThen() }
113+
114+
override string getMessage() {
115+
result =
116+
"Ternaries with omitted middle operands are a compiler extension and is not portable to other compilers."
117+
}
79118
}
80119

81120
// Reference: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html#g_t_005f_005fint128
@@ -87,31 +126,63 @@ class CRealTypeExtensionExtension extends CCompilerExtension, DeclarationEntry {
87126
getType() instanceof Decimal64Type or
88127
getType() instanceof Float128Type
89128
}
129+
130+
override string getMessage() {
131+
result = "Decimal floats are a compiler extension and are not portable to other compilers."
132+
}
90133
}
91134

92135
// Reference: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html#g_t_005f_005fint128
93136
class CIntegerTypeExtension extends CCompilerExtension, DeclarationEntry {
94137
CIntegerTypeExtension() { getType() instanceof Int128Type }
138+
139+
override string getMessage() {
140+
result = "128-bit integers are a compiler extension and are not portable to other compilers."
141+
}
95142
}
96143

97144
// Reference: https://gcc.gnu.org/onlinedocs/gcc/Long-Long.html#Long-Long
98145
class CLongLongType extends CCompilerExtension, DeclarationEntry {
99146
CLongLongType() { getType() instanceof LongLongType }
147+
148+
override string getMessage() {
149+
result =
150+
"Double-Word integers are a compiler extension and are not portable to other compilers."
151+
}
100152
}
101153

102154
class CZeroLengthArraysExtension extends CCompilerExtension, DeclarationEntry {
103155
CZeroLengthArraysExtension() { getType().(ArrayType).getArraySize() = 0 }
156+
157+
override string getMessage() {
158+
result = "Zero length arrays are a compiler extension and are not portable to other compilers."
159+
}
104160
}
105161

106162
// Reference: https://gcc.gnu.org/onlinedocs/gcc/Empty-Structures.html#Empty-Structures
107163
class CEmptyStructExtension extends CCompilerExtension, Struct {
108164
CEmptyStructExtension() { not exists(getAMember(_)) }
165+
166+
override string getMessage() {
167+
result = "Empty structures are a compiler extension and are not portable to other compilers."
168+
}
109169
}
110170

111171
// Reference: https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html#Variable-Length
112-
class CVariableLengthArraysExtension extends CCompilerExtension, DeclarationEntry {
172+
class CVariableLengthArraysExtension extends CCompilerExtension, Field {
113173
CVariableLengthArraysExtension() {
114174
getType() instanceof ArrayType and
115-
not getType().(ArrayType).hasArraySize()
175+
not getType().(ArrayType).hasArraySize() and
176+
// Not the final member of the struct, which is allowed to be variably sized
177+
not exists(int lastIndex, Class declaringStruct |
178+
declaringStruct = getDeclaringType() and
179+
lastIndex = count(declaringStruct.getACanonicalMember()) - 1 and
180+
this = declaringStruct.getCanonicalMember(lastIndex)
181+
)
182+
}
183+
184+
override string getMessage() {
185+
result =
186+
"Variable length arrays are a compiler extension and are not portable to other compilers."
116187
}
117188
}

0 commit comments

Comments
 (0)