Skip to content

Commit 8746e00

Browse files
authored
Merge branch 'main' into codeql/upgrade-to-2.18.4
2 parents 741c372 + 76de855 commit 8746e00

File tree

46 files changed

+596
-22
lines changed

Some content is hidden

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

46 files changed

+596
-22
lines changed

.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-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

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+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id c/misra/non-void-return-type-of-noreturn-function
3+
* @name RULE-17-10: A function declared with _noreturn shall have a return type of void
4+
* @description Function declared with _noreturn will by definition not return a value, and should
5+
* be declared to return void.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity recommendation
9+
* @tags external/misra/id/rule-17-10
10+
* correctness
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.Noreturn
17+
18+
from NoreturnFunction f, Type returnType
19+
where
20+
not isExcluded(f, NoReturnPackage::nonVoidReturnTypeOfNoreturnFunctionQuery()) and
21+
returnType = f.getType() and
22+
not returnType instanceof VoidType and
23+
not f.isCompilerGenerated()
24+
select f,
25+
"The function " + f.getName() + " is declared _noreturn but has a return type of " +
26+
returnType.toString() + "."
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @id c/misra/function-with-no-returning-branch-should-be-noreturn
3+
* @name RULE-17-11: A function without a branch that returns shall be declared with _Noreturn
4+
* @description Functions which cannot return should be declared with _Noreturn.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity recommendation
8+
* @tags external/misra/id/rule-17-11
9+
* correctness
10+
* external/misra/obligation/advisory
11+
*/
12+
13+
import cpp
14+
import codingstandards.c.misra
15+
import codingstandards.cpp.Noreturn
16+
17+
from Function f
18+
where
19+
not isExcluded(f, NoReturnPackage::functionWithNoReturningBranchShouldBeNoreturnQuery()) and
20+
not f instanceof NoreturnFunction and
21+
not mayReturn(f) and
22+
f.hasDefinition() and
23+
not f.getName() = "main" and // Allowed exception; _Noreturn main() is undefined behavior.
24+
// Harden against c++ cases.
25+
not f.isFromUninstantiatedTemplate(_) and
26+
not f.isDeleted() and
27+
not f.isCompilerGenerated()
28+
select f, "The function " + f.getName() + " cannot return and should be declared as _Noreturn."
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @id c/misra/return-statement-in-noreturn-function
3+
* @name RULE-17-9: Verify that a function declared with _Noreturn does not return
4+
* @description Returning inside a function declared with _Noreturn is undefined behavior.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity error
8+
* @tags external/misra/id/rule-17-9
9+
* correctness
10+
* external/misra/obligation/mandatory
11+
*/
12+
13+
import cpp
14+
import codingstandards.c.misra
15+
import codingstandards.cpp.rules.functionnoreturnattributecondition.FunctionNoReturnAttributeCondition
16+
17+
class ReturnStatementInNoreturnFunctionQuery extends FunctionNoReturnAttributeConditionSharedQuery {
18+
ReturnStatementInNoreturnFunctionQuery() {
19+
this = NoReturnPackage::returnStatementInNoreturnFunctionQuery()
20+
}
21+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.c:6:15:6:16 | f4 | The function f4 is declared _noreturn but has a return type of int. |
2+
| test.c:19:15:19:16 | f8 | The function f8 is declared _noreturn but has a return type of int. |
3+
| test.c:24:17:24:18 | f9 | The function f9 is declared _noreturn but has a return type of void *. |
4+
| test.c:26:31:26:33 | f10 | The function f10 is declared _noreturn but has a return type of int. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-17-10/NonVoidReturnTypeOfNoreturnFunction.ql

c/misra/test/rules/RULE-17-10/test.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "stdlib.h"
2+
3+
void f1(); // COMPLIANT
4+
int f2(); // COMPLIANT
5+
_Noreturn void f3(); // COMPLIANT
6+
_Noreturn int f4(); // NON-COMPLIANT
7+
8+
void f5() { // COMPLIANT
9+
}
10+
11+
int f6() { // COMPLIANT
12+
return 0;
13+
}
14+
15+
_Noreturn void f7() { // COMPLIANT
16+
abort();
17+
}
18+
19+
_Noreturn int f8() { // NON-COMPLIANT
20+
abort();
21+
return 0;
22+
}
23+
24+
_Noreturn void *f9(); // NON-COMPLIANT
25+
26+
__attribute__((noreturn)) int f10(); // NON-COMPLIANT
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| test.c:7:6:7:21 | test_noreturn_f2 | The function test_noreturn_f2 cannot return and should be declared as _Noreturn. |
2+
| test.c:18:6:18:21 | test_noreturn_f4 | The function test_noreturn_f4 cannot return and should be declared as _Noreturn. |
3+
| test.c:47:6:47:21 | test_noreturn_f8 | The function test_noreturn_f8 cannot return and should be declared as _Noreturn. |
4+
| test.c:63:6:63:22 | test_noreturn_f10 | The function test_noreturn_f10 cannot return and should be declared as _Noreturn. |
5+
| test.c:97:6:97:22 | test_noreturn_f15 | The function test_noreturn_f15 cannot return and should be declared as _Noreturn. |
6+
| test.c:101:6:101:22 | test_noreturn_f16 | The function test_noreturn_f16 cannot return and should be declared as _Noreturn. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-17-11/FunctionWithNoReturningBranchShouldBeNoreturn.ql

0 commit comments

Comments
 (0)