Skip to content

Commit 6266fd5

Browse files
authored
Merge pull request #103 from jsinglet/jsinglet/language1
Language 1
2 parents bbdfbe4 + 8a0d36e commit 6266fd5

File tree

9 files changed

+168
-1
lines changed

9 files changed

+168
-1
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
"Invariants",
221221
"Iterators",
222222
"Lambdas",
223+
"Language1",
223224
"Literals",
224225
"Loops",
225226
"Macros",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @id c/misra/language-not-encapsulated-and-isolated
3+
* @name DIR-4-3: Assembly language shall be encapsulated and isolated
4+
* @description Failing to encapsulate assembly language limits the portability, reliability, and
5+
* readability of programs.
6+
* @kind problem
7+
* @precision very-high
8+
* @problem.severity error
9+
* @tags external/misra/id/dir-4-3
10+
* maintainability
11+
* readability
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.misra
17+
18+
from AsmStmt asm
19+
where
20+
not isExcluded(asm, Language1Package::languageNotEncapsulatedAndIsolatedQuery()) and
21+
not exists(asm.getEnclosingFunction())
22+
or
23+
// in concept statements within the body constitute intermingling assembly,
24+
// rather than expressions and are more general.
25+
exists(Stmt sp | sp = asm.getEnclosingFunction().getEntryPoint().getASuccessor*() |
26+
not sp instanceof AsmStmt and not sp instanceof ReturnStmt and not sp instanceof BlockStmt
27+
)
28+
select asm, "Usage of non-isolated and non-encapsulated assembly language."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| test.c:6:3:6:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
2+
| test.c:11:3:11:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
3+
| test.c:32:3:32:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
4+
| test.c:37:3:37:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
5+
| test.c:58:3:58:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/DIR-4-3/LanguageNotEncapsulatedAndIsolated.ql

c/misra/test/rules/DIR-4-3/test.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#define N1 asm("HCF")
2+
#define N2 __asm__("HCF")
3+
4+
void f1() {
5+
int a;
6+
N1; // NON_COMPLIANT
7+
}
8+
9+
void f2() {
10+
int a;
11+
N2; // NON_COMPLIANT
12+
}
13+
14+
void f3() {
15+
N1; // COMPLIANT
16+
}
17+
18+
void f4() {
19+
N2; // COMPLIANT
20+
}
21+
22+
void f5() {
23+
__asm__("HCF"); // COMPLIANT
24+
}
25+
26+
void f6() {
27+
asm("HCF"); // COMPLIANT
28+
}
29+
30+
inline void f7() {
31+
int a;
32+
N1; // NON_COMPLIANT
33+
}
34+
35+
inline void f8() {
36+
int a;
37+
N2; // NON_COMPLIANT
38+
}
39+
40+
inline void f9() {
41+
N1; // COMPLIANT
42+
}
43+
44+
inline void f10() {
45+
N2; // COMPLIANT
46+
}
47+
48+
inline void f11() {
49+
__asm__("HCF"); // COMPLIANT
50+
}
51+
52+
inline void f12() {
53+
asm("HCF"); // COMPLIANT
54+
}
55+
56+
inline int f13() {
57+
int a;
58+
N2; // NON_COMPLIANT
59+
return 0;
60+
}
61+
62+
inline int f14() {
63+
N1; // COMPLIANT
64+
return 0;
65+
}
66+
67+
inline int f15() {
68+
N2; // COMPLIANT
69+
return 0;
70+
}
71+
72+
inline int f16() {
73+
__asm__("HCF"); // COMPLIANT
74+
return 0;
75+
}
76+
77+
inline int f17() {
78+
asm("HCF"); // COMPLIANT
79+
return 0;
80+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
2+
import cpp
3+
import RuleMetadata
4+
import codingstandards.cpp.exclusions.RuleMetadata
5+
6+
newtype Language1Query = TLanguageNotEncapsulatedAndIsolatedQuery()
7+
8+
predicate isLanguage1QueryMetadata(Query query, string queryId, string ruleId) {
9+
query =
10+
// `Query` instance for the `languageNotEncapsulatedAndIsolated` query
11+
Language1Package::languageNotEncapsulatedAndIsolatedQuery() and
12+
queryId =
13+
// `@id` for the `languageNotEncapsulatedAndIsolated` query
14+
"c/misra/language-not-encapsulated-and-isolated" and
15+
ruleId = "DIR-4-3"
16+
}
17+
18+
module Language1Package {
19+
Query languageNotEncapsulatedAndIsolatedQuery() {
20+
//autogenerate `Query` type
21+
result =
22+
// `Query` type for `languageNotEncapsulatedAndIsolated` query
23+
TQueryC(TLanguage1PackageQuery(TLanguageNotEncapsulatedAndIsolatedQuery()))
24+
}
25+
}

cpp/common/src/codingstandards/cpp/exclusions/c/RuleMetadata.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import IO1
1818
import IO2
1919
import IO3
2020
import IO4
21+
import Language1
2122
import Misc
2223
import Pointers1
2324
import Pointers2
@@ -51,6 +52,7 @@ newtype TCQuery =
5152
TIO2PackageQuery(IO2Query q) or
5253
TIO3PackageQuery(IO3Query q) or
5354
TIO4PackageQuery(IO4Query q) or
55+
TLanguage1PackageQuery(Language1Query q) or
5456
TMiscPackageQuery(MiscQuery q) or
5557
TPointers1PackageQuery(Pointers1Query q) or
5658
TPointers2PackageQuery(Pointers2Query q) or
@@ -84,6 +86,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId) {
8486
isIO2QueryMetadata(query, queryId, ruleId) or
8587
isIO3QueryMetadata(query, queryId, ruleId) or
8688
isIO4QueryMetadata(query, queryId, ruleId) or
89+
isLanguage1QueryMetadata(query, queryId, ruleId) or
8790
isMiscQueryMetadata(query, queryId, ruleId) or
8891
isPointers1QueryMetadata(query, queryId, ruleId) or
8992
isPointers2QueryMetadata(query, queryId, ruleId) or

rule_packages/c/Language1.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"MISRA-C-2012": {
3+
"DIR-4-3": {
4+
"properties": {
5+
"obligation": "required"
6+
},
7+
"queries": [
8+
{
9+
"description": "Failing to encapsulate assembly language limits the portability, reliability, and readability of programs.",
10+
"kind": "problem",
11+
"name": "Assembly language shall be encapsulated and isolated",
12+
"precision": "very-high",
13+
"severity": "error",
14+
"short_name": "LanguageNotEncapsulatedAndIsolated",
15+
"tags": [
16+
"maintainability",
17+
"readability"
18+
]
19+
}
20+
],
21+
"title": "Assembly language shall be encapsulated and isolated"
22+
}
23+
}
24+
}

rules.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ c,MISRA-C-2012,RULE-2-1,Yes,Required,,,All source files shall compile without an
604604
c,MISRA-C-2012,RULE-3-1,No,Required,,,All code shall be traceable to documented requirements,,,,
605605
c,MISRA-C-2012,RULE-4-1,No,Required,,,Run-time failures shall be minimized,,,,
606606
c,MISRA-C-2012,RULE-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language,Import,
607-
c,MISRA-C-2012,RULE-4-3,Yes,Required,,,Assembly language shall be encapsulated and isolated,,Language,Medium,
607+
c,MISRA-C-2012,DIR-4-3,Yes,Required,,,Assembly language shall be encapsulated and isolated,,Language1,Medium,
608608
c,MISRA-C-2012,RULE-4-4,Yes,Advisory,,,Sections of code should not be commented out,A2-7-2,Syntax,Import,
609609
c,MISRA-C-2012,DIR-4-5,Yes,Advisory,,,Identifiers in the same name space with overlapping visibility should be typographically unambiguous,M2-10-1,Syntax,Easy,
610610
c,MISRA-C-2012,RULE-4-6,Yes,Advisory,,,typedefs that indicate size and signedness should be used in place of the basic numerical types,,Types,Hard,

0 commit comments

Comments
 (0)