Skip to content

Commit d327596

Browse files
committed
added RULE-16-1 and moved M6-4-3 to shared folder
1 parent 490b3fe commit d327596

26 files changed

+298
-116
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.c:5:3:24:3 | switch (...) ... | $@ statement not well formed because the first statement in a well formed switch statement must be a case clause. | test.c:5:3:24:3 | switch (...) ... | Switch |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.switchcasepositioncondition.SwitchCasePositionCondition
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
void f1(int p1);
2+
3+
void f2(int p1) {
4+
5+
switch (p1) {
6+
start:; // NON_COMPLIANT
7+
case 1:
8+
if (p1) {
9+
;
10+
};
11+
break;
12+
case 2:
13+
if (p1) {
14+
;
15+
}
16+
break;
17+
case 3:
18+
if (p1) {
19+
;
20+
}
21+
break;
22+
default:;
23+
break;
24+
}
25+
}
26+
void f3(int p1) {
27+
28+
switch (p1) { // COMPLIANT
29+
case 2:
30+
if (p1) {
31+
;
32+
}
33+
break;
34+
case 3:
35+
if (p1) {
36+
;
37+
}
38+
break;
39+
default:;
40+
break;
41+
}
42+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.c:4:3:10:3 | switch (...) ... | $@ statement not well formed because this $@ block uses a statement that is not allowed. | test.c:4:3:10:3 | switch (...) ... | Switch | test.c:5:3:5:9 | case ...: | case |
2+
| test.c:13:3:20:3 | switch (...) ... | $@ statement not well formed because this $@ block uses a statement that is not allowed. | test.c:13:3:20:3 | switch (...) ... | Switch | test.c:14:3:14:10 | case ...: | case |
3+
| test.c:25:3:30:3 | switch (...) ... | $@ statement not well formed because this $@ block uses a statement that is not allowed. | test.c:25:3:30:3 | switch (...) ... | Switch | test.c:26:3:26:9 | case ...: | case |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.switchnotwellformed.SwitchNotWellFormed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
void f1();
3+
void f2(int p1) {
4+
switch (p1) {
5+
case 1:
6+
int y = p1; // NON_COMPLIANT - `DeclStmt` whose parent
7+
// statement is the switch body
8+
f1();
9+
break;
10+
}
11+
}
12+
void f3(int p1) {
13+
switch (p1) {
14+
case 10:
15+
f1();
16+
goto L1; // NON_COMPLIANT - `JumpStmt` whose parent statement is the//
17+
// switch// body
18+
case 2:
19+
break;
20+
}
21+
L1:;
22+
}
23+
24+
void f4(int p1) {
25+
switch (p1) {
26+
case 1:
27+
L1:; // NON_COMPLIANT - `LabelStmt` whose parent statement is the
28+
// switch body
29+
break;
30+
}
31+
}
32+
33+
void f5(int p1) {
34+
switch (p1) {
35+
case 1: // COMPLIANT
36+
default:
37+
p1 = 0;
38+
break;
39+
}
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/misra/switch-case-start-condition
3+
* @name RULE-16-1: A well formed switch statement must start with a case clause
4+
* @description The switch statement syntax is weak and may lead to unspecified behaviour.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity recommendation
8+
* @tags external/misra/id/rule-16-1
9+
* maintainability
10+
* readability
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.switchcasepositioncondition.SwitchCasePositionCondition
17+
18+
class SwitchCaseStartConditionQuery extends SwitchCasePositionConditionSharedQuery {
19+
SwitchCaseStartConditionQuery() {
20+
this = Statements3Package::switchCaseStartConditionQuery()
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/misra/switch-stmt-not-well-formed
3+
* @name RULE-16-1: A well formed switch statement should only have expression, compound, selection, iteration or try statements within its body
4+
* @description The switch statement syntax is weak and may lead to unspecified behaviour.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity recommendation
8+
* @tags external/misra/id/rule-16-1
9+
* maintainability
10+
* readability
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.switchnotwellformed.SwitchNotWellFormed
17+
18+
class SwitchStmtNotWellFormedQuery extends SwitchNotWellFormedSharedQuery {
19+
SwitchStmtNotWellFormedQuery() {
20+
this = Statements3Package::switchStmtNotWellFormedQuery()
21+
}
22+
}

cpp/autosar/src/rules/M6-4-3/SwitchDoesNotStartWithCase.ql

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
import cpp
1818
import codingstandards.cpp.autosar
19-
import codingstandards.cpp.SwitchStatement
19+
import codingstandards.cpp.rules.switchcasepositioncondition.SwitchCasePositionCondition
2020

21-
from SwitchStmt switch, SwitchCase case
22-
where
23-
not isExcluded(switch, ConditionalsPackage::switchDoesNotStartWithCaseQuery()) and
24-
case = switch.getASwitchCase() and
25-
switchWithCaseNotFirst(switch)
26-
select switch,
27-
"$@ statement not well formed because the first statement in a well formed switch statement must be a case clause.",
28-
switch, "Switch"
21+
class SwitchDoesNotStartWithCaseQuery extends SwitchCasePositionConditionSharedQuery {
22+
SwitchDoesNotStartWithCaseQuery() {
23+
this = ConditionalsPackage::switchDoesNotStartWithCaseQuery()
24+
}
25+
}

cpp/autosar/src/rules/M6-4-3/SwitchStatementNotWellFormed.ql

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
import cpp
1818
import codingstandards.cpp.autosar
19-
import codingstandards.cpp.SwitchStatement
19+
import codingstandards.cpp.rules.switchnotwellformed.SwitchNotWellFormed
2020

21-
from SwitchStmt switch, SwitchCase case
22-
where
23-
not isExcluded(switch, ConditionalsPackage::switchStatementNotWellFormedQuery()) and
24-
case = switch.getASwitchCase() and
25-
switchCaseNotWellFormed(case)
26-
select switch,
27-
"$@ statement not well formed because this $@ block uses a statement that is not allowed.",
28-
switch, "Switch", case, "case"
21+
class SwitchStatementNotWellFormedQuery extends SwitchNotWellFormedSharedQuery {
22+
SwitchStatementNotWellFormedQuery() {
23+
this = ConditionalsPackage::switchStatementNotWellFormedQuery()
24+
}
25+
}

0 commit comments

Comments
 (0)