Skip to content

Commit 55c9f23

Browse files
authored
Merge branch 'main' into lcartey/language-extensions-improvements
2 parents cbc6388 + 76de855 commit 55c9f23

File tree

103 files changed

+1452
-142
lines changed

Some content is hidden

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

103 files changed

+1452
-142
lines changed

.github/workflows/codeql_unit_tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,16 @@ jobs:
160160

161161
validate-test-results:
162162
name: Validate test results
163+
if: ${{ always() }}
163164
needs: run-test-suites
164165
runs-on: ubuntu-22.04
165166
steps:
167+
- name: Check if run-test-suites job failed to complete, if so fail
168+
if: ${{ needs.run-test-suites.result == 'failure' }}
169+
uses: actions/github-script@v3
170+
with:
171+
script: |
172+
core.setFailed('Test run job failed')
166173
- name: Collect test results
167174
uses: actions/download-artifact@v3
168175

.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/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/validate-package-files.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ jobs:
5656
find rule_packages/$LANGUAGE -name \*.json -exec basename {} .json \; | xargs python scripts/generate_rules/generate_package_files.py $LANGUAGE
5757
git diff
5858
git diff --compact-summary
59-
git diff --quiet
59+
git diff --quiet
60+
61+
- name: Validate Amendments
62+
env:
63+
LANGUAGE: ${{ matrix.language }}
64+
run: |
65+
python scripts/validate-amendments-csv.py $LANGUAGE

.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

amendments.csv

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
language,standard,amendment,rule_id,supportable,implementation_category,implemented,difficulty
2+
c,MISRA-C-2012,Amendment3,DIR-4-6,Yes,Expand,No,Easy
3+
c,MISRA-C-2012,Amendment3,DIR-4-9,Yes,Refine,No,Easy
4+
c,MISRA-C-2012,Amendment3,DIR-4-11,Yes,Refine,No,Import
5+
c,MISRA-C-2012,Amendment3,RULE-1-4,Yes,Replace,No,Easy
6+
c,MISRA-C-2012,Amendment3,RULE-10-1,Yes,Replace,No,Easy
7+
c,MISRA-C-2012,Amendment3,RULE-10-3,Yes,Refine,No,Easy
8+
c,MISRA-C-2012,Amendment3,RULE-10-4,Yes,Refine,No,Import
9+
c,MISRA-C-2012,Amendment3,RULE-10-5,Yes,Expand,No,Easy
10+
c,MISRA-C-2012,Amendment3,RULE-10-7,Yes,Refine,No,Import
11+
c,MISRA-C-2012,Amendment3,RULE-10-8,Yes,Refine,No,Import
12+
c,MISRA-C-2012,Amendment3,RULE-21-11,Yes,Clarification,No,Import
13+
c,MISRA-C-2012,Amendment3,RULE-21-12,Yes,Replace,No,Easy
14+
c,MISRA-C-2012,Amendment4,RULE-11-3,Yes,Expand,No,Easy
15+
c,MISRA-C-2012,Amendment4,RULE-11-8,Yes,Expand,No,Easy
16+
c,MISRA-C-2012,Amendment4,RULE-13-2,Yes,Expand,No,Very Hard
17+
c,MISRA-C-2012,Amendment4,RULE-18-6,Yes,Expand,No,Medium
18+
c,MISRA-C-2012,Amendment4,RULE-18-8,Yes,Split,No,Easy
19+
c,MISRA-C-2012,Corrigendum2,RULE-2-2,Yes,Clarification,No,Import
20+
c,MISRA-C-2012,Corrigendum2,RULE-2-7,Yes,Clarification,No,Import
21+
c,MISRA-C-2012,Corrigendum2,RULE-3-1,Yes,Refine,No,Easy
22+
c,MISRA-C-2012,Corrigendum2,RULE-8-6,Yes,Clarification,No,Import
23+
c,MISRA-C-2012,Corrigendum2,RULE-8-9,Yes,Clarification,No,Import
24+
c,MISRA-C-2012,Corrigendum2,RULE-9-4,Yes,Clarification,No,Import
25+
c,MISRA-C-2012,Corrigendum2,RULE-10-1,Yes,Clarification,No,Import
26+
c,MISRA-C-2012,Corrigendum2,RULE-18-3,Yes,Clarification,No,Import
27+
c,MISRA-C-2012,Corrigendum2,RULE-1-4,Yes,Replace,No,Easy
28+
c,MISRA-C-2012,Corrigendum2,RULE-9-1,Yes,Refine,No,Easy
29+
c,MISRA-C-2012,Corrigendum2,RULE-9-2,Yes,Refine,No,Import
30+
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,No,Import
31+
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,No,Easy
32+
c,MISRA-C-2012,Corrigendum2,RULE-8-2,Yes,Clarification,No,Import
33+
c,MISRA-C-2012,Corrigendum2,RULE-8-3,Yes,Refine,No,Easy
34+
c,MISRA-C-2012,Corrigendum2,RULE-8-7,Yes,Clarification,No,Import
35+
c,MISRA-C-2012,Corrigendum2,RULE-10-2,Yes,Refine,No,Easy
36+
c,MISRA-C-2012,Corrigendum2,RULE-10-3,Yes,Clarification,No,Import
37+
c,MISRA-C-2012,Corrigendum2,RULE-11-3,Yes,Clarification,No,Import
38+
c,MISRA-C-2012,Corrigendum2,RULE-11-6,Yes,Clarification,No,Import
39+
c,MISRA-C-2012,Corrigendum2,RULE-13-2,Yes,Clarification,No,Import
40+
c,MISRA-C-2012,Corrigendum2,RULE-13-6,Yes,Clarification,No,Import
41+
c,MISRA-C-2012,Corrigendum2,RULE-14-3,Yes,Refine,No,Easy
42+
c,MISRA-C-2012,Corrigendum2,RULE-15-7,Yes,Clarification,No,Import
43+
c,MISRA-C-2012,Corrigendum2,RULE-17-4,Yes,Clarification,No,Import
44+
c,MISRA-C-2012,Corrigendum2,RULE-17-5,Yes,Clarification,No,Import
45+
c,MISRA-C-2012,Corrigendum2,RULE-18-1,Yes,Refine,No,Easy
46+
c,MISRA-C-2012,Corrigendum2,RULE-20-14,No,Clarification,No,Import
47+
c,MISRA-C-2012,Corrigendum2,RULE-21-19,Yes,Clarification,No,Import
48+
c,MISRA-C-2012,Corrigendum2,RULE-21-20,Yes,Refine,No,Easy
49+
c,MISRA-C-2012,Corrigendum2,RULE-22-9,Yes,Clarification,No,Import

c/cert/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards
2-
version: 2.35.0-dev
2+
version: 2.36.0-dev
33
description: CERT C 2016
44
suites: codeql-suites
55
license: MIT

c/cert/src/rules/SIG31-C/DoNotAccessSharedObjectsInSignalHandlers.ql

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ import codingstandards.c.Signal
2121
*/
2222
class UnsafeSharedVariableAccess extends VariableAccess {
2323
UnsafeSharedVariableAccess() {
24-
// static or thread local storage duration
25-
(
26-
this.getTarget() instanceof StaticStorageDurationVariable or
27-
this.getTarget().isThreadLocal()
28-
) and
2924
// excluding `volatile sig_atomic_t` type
3025
not this.getType().(SigAtomicType).isVolatile() and
31-
// excluding lock-free atomic objects
32-
not exists(MacroInvocation mi, VariableAccess va |
33-
mi.getMacroName() = "atomic_is_lock_free" and
34-
mi.getExpr().getChild(0) = va.getEnclosingElement*() and
35-
va.getTarget() = this.getTarget()
26+
exists(Variable target | target = this.getTarget() |
27+
// static or thread local storage duration
28+
(
29+
target instanceof StaticStorageDurationVariable or
30+
target.isThreadLocal()
31+
) and
32+
// excluding lock-free atomic objects
33+
not exists(MacroInvocation mi, VariableAccess va | va.getTarget() = target |
34+
mi.getMacroName() = "atomic_is_lock_free" and
35+
mi.getExpr().getChild(0) = va.getEnclosingElement*()
36+
)
3637
)
3738
}
3839
}

c/cert/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cert-c-coding-standards-tests
2-
version: 2.35.0-dev
2+
version: 2.36.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:

c/common/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards
2-
version: 2.35.0-dev
2+
version: 2.36.0-dev
33
license: MIT
44
dependencies:
55
codeql/common-cpp-coding-standards: '*'

c/common/test/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/common-c-coding-standards-tests
2-
version: 2.35.0-dev
2+
version: 2.36.0-dev
33
extractor: cpp
44
license: MIT
55
dependencies:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.c:9:16:9:31 | test_noreturn_f2 | The function test_noreturn_f2 declared with attribute _Noreturn returns a value. |
2+
| test.c:34:16:34:31 | test_noreturn_f5 | The function test_noreturn_f5 declared with attribute _Noreturn returns a value. |
3+
| test.c:49:32:49:47 | test_noreturn_f7 | The function test_noreturn_f7 declared with attribute _Noreturn returns a value. |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.functionnoreturnattributecondition.FunctionNoReturnAttributeCondition
3+
4+
class TestFileQuery extends FunctionNoReturnAttributeConditionSharedQuery, TestQuery { }
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include "setjmp.h"
2+
#include "stdlib.h"
3+
#include "threads.h"
4+
5+
_Noreturn void test_noreturn_f1(int i) { // COMPLIANT
6+
abort();
7+
}
8+
9+
_Noreturn void test_noreturn_f2(int i) { // NON_COMPLIANT
10+
if (i > 0) {
11+
abort();
12+
}
13+
if (i < 0) {
14+
abort();
15+
}
16+
}
17+
18+
_Noreturn void test_noreturn_f3(int i) { // COMPLIANT
19+
if (i > 0) {
20+
abort();
21+
}
22+
exit(1);
23+
}
24+
25+
void test_noreturn_f4(int i) { // COMPLIANT
26+
if (i > 0) {
27+
abort();
28+
}
29+
if (i < 0) {
30+
abort();
31+
}
32+
}
33+
34+
_Noreturn void test_noreturn_f5(int i) { // NON_COMPLIANT
35+
if (i > 0) {
36+
abort();
37+
}
38+
}
39+
40+
_Noreturn void test_noreturn_f6(int i) { // COMPLIANT
41+
if (i > 0) {
42+
abort();
43+
}
44+
while (1) {
45+
i = 5;
46+
}
47+
}
48+
49+
__attribute__((noreturn)) void test_noreturn_f7(int i) { // NON_COMPLIANT
50+
if (i > 0) {
51+
abort();
52+
}
53+
}
54+
55+
__attribute__((noreturn)) void test_noreturn_f8(int i) { // COMPLIANT
56+
abort();
57+
}
58+
59+
_Noreturn void test_noreturn_f9(int i) { // COMPLIANT
60+
test_noreturn_f1(i);
61+
}
62+
63+
_Noreturn void test_noreturn_f10(int i) { // COMPLIANT
64+
switch (i) {
65+
case 0:
66+
abort();
67+
break;
68+
case 1:
69+
exit(0);
70+
break;
71+
case 2:
72+
_Exit(0);
73+
break;
74+
case 3:
75+
quick_exit(0);
76+
break;
77+
case 4:
78+
thrd_exit(0);
79+
break;
80+
default:
81+
jmp_buf jb;
82+
longjmp(jb, 0);
83+
}
84+
}
85+
86+
_Noreturn void test_noreturn_f11(int i) { // COMPLIANT
87+
return test_noreturn_f11(i);
88+
}

c/misra/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/misra-c-coding-standards
2-
version: 2.35.0-dev
2+
version: 2.36.0-dev
33
description: MISRA C 2012
44
suites: codeql-suites
55
license: MIT

c/misra/src/rules/RULE-10-7/ImplicitConversionOfCompositeExpression.ql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import codingstandards.c.misra
1818
import codingstandards.c.misra.EssentialTypes
1919
import codingstandards.c.misra.MisraExpressions
2020

21+
bindingset[essentialTypeLeft, essentialTypeRight]
22+
pragma[inline_late]
23+
predicate isSameEssentialTypeCategory(Type essentialTypeLeft, Type essentialTypeRight) {
24+
getEssentialTypeCategory(essentialTypeLeft) = getEssentialTypeCategory(essentialTypeRight)
25+
}
26+
2127
from
2228
OperationWithUsualArithmeticConversions arith, CompositeExpression compositeOp, Expr otherOp,
2329
Type compositeEssentialType, Type otherOpEssentialType
@@ -32,7 +38,7 @@ where
3238
// Operands of a different type category in an operation with the usual arithmetic conversions is
3339
// prohibited by Rule 10.4, so we only report cases here where the essential type categories are
3440
// the same
35-
getEssentialTypeCategory(compositeEssentialType) = getEssentialTypeCategory(otherOpEssentialType)
41+
isSameEssentialTypeCategory(compositeEssentialType, otherOpEssentialType)
3642
select arith,
3743
"Implicit conversion of $@ from " + compositeEssentialType + " to " + otherOpEssentialType,
3844
compositeOp, "composite op"

0 commit comments

Comments
 (0)