Skip to content

Language 1 #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
"Invariants",
"Iterators",
"Lambdas",
"Language1",
"Literals",
"Loops",
"Macros",
Expand Down
28 changes: 28 additions & 0 deletions c/misra/src/rules/DIR-4-3/LanguageNotEncapsulatedAndIsolated.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @id c/misra/language-not-encapsulated-and-isolated
* @name DIR-4-3: Assembly language shall be encapsulated and isolated
* @description Failing to encapsulate assembly language limits the portability, reliability, and
* readability of programs.
* @kind problem
* @precision very-high
* @problem.severity error
* @tags external/misra/id/dir-4-3
* maintainability
* readability
* external/misra/obligation/required
*/

import cpp
import codingstandards.c.misra

from AsmStmt asm
where
not isExcluded(asm, Language1Package::languageNotEncapsulatedAndIsolatedQuery()) and
not exists(asm.getEnclosingFunction())
or
// in concept statements within the body constitute intermingling assembly,
// rather than expressions and are more general.
exists(Stmt sp | sp = asm.getEnclosingFunction().getEntryPoint().getASuccessor*() |
not sp instanceof AsmStmt and not sp instanceof ReturnStmt and not sp instanceof BlockStmt
)
select asm, "Usage of non-isolated and non-encapsulated assembly language."
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| test.c:6:3:6:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
| test.c:11:3:11:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
| test.c:32:3:32:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
| test.c:37:3:37:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
| test.c:58:3:58:5 | asm statement | Usage of non-isolated and non-encapsulated assembly language. |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules/DIR-4-3/LanguageNotEncapsulatedAndIsolated.ql
80 changes: 80 additions & 0 deletions c/misra/test/rules/DIR-4-3/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#define N1 asm("HCF")
#define N2 __asm__("HCF")

void f1() {
int a;
N1; // NON_COMPLIANT
}

void f2() {
int a;
N2; // NON_COMPLIANT
}

void f3() {
N1; // COMPLIANT
}

void f4() {
N2; // COMPLIANT
}

void f5() {
__asm__("HCF"); // COMPLIANT
}

void f6() {
asm("HCF"); // COMPLIANT
}

inline void f7() {
int a;
N1; // NON_COMPLIANT
}

inline void f8() {
int a;
N2; // NON_COMPLIANT
}

inline void f9() {
N1; // COMPLIANT
}

inline void f10() {
N2; // COMPLIANT
}

inline void f11() {
__asm__("HCF"); // COMPLIANT
}

inline void f12() {
asm("HCF"); // COMPLIANT
}

inline int f13() {
int a;
N2; // NON_COMPLIANT
return 0;
}

inline int f14() {
N1; // COMPLIANT
return 0;
}

inline int f15() {
N2; // COMPLIANT
return 0;
}

inline int f16() {
__asm__("HCF"); // COMPLIANT
return 0;
}

inline int f17() {
asm("HCF"); // COMPLIANT
return 0;
}
25 changes: 25 additions & 0 deletions cpp/common/src/codingstandards/cpp/exclusions/c/Language1.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
import cpp
import RuleMetadata
import codingstandards.cpp.exclusions.RuleMetadata

newtype Language1Query = TLanguageNotEncapsulatedAndIsolatedQuery()

predicate isLanguage1QueryMetadata(Query query, string queryId, string ruleId) {
query =
// `Query` instance for the `languageNotEncapsulatedAndIsolated` query
Language1Package::languageNotEncapsulatedAndIsolatedQuery() and
queryId =
// `@id` for the `languageNotEncapsulatedAndIsolated` query
"c/misra/language-not-encapsulated-and-isolated" and
ruleId = "DIR-4-3"
}

module Language1Package {
Query languageNotEncapsulatedAndIsolatedQuery() {
//autogenerate `Query` type
result =
// `Query` type for `languageNotEncapsulatedAndIsolated` query
TQueryC(TLanguage1PackageQuery(TLanguageNotEncapsulatedAndIsolatedQuery()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import IO1
import IO2
import IO3
import IO4
import Language1
import Misc
import Pointers1
import Pointers2
Expand Down Expand Up @@ -51,6 +52,7 @@ newtype TCQuery =
TIO2PackageQuery(IO2Query q) or
TIO3PackageQuery(IO3Query q) or
TIO4PackageQuery(IO4Query q) or
TLanguage1PackageQuery(Language1Query q) or
TMiscPackageQuery(MiscQuery q) or
TPointers1PackageQuery(Pointers1Query q) or
TPointers2PackageQuery(Pointers2Query q) or
Expand Down Expand Up @@ -84,6 +86,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId) {
isIO2QueryMetadata(query, queryId, ruleId) or
isIO3QueryMetadata(query, queryId, ruleId) or
isIO4QueryMetadata(query, queryId, ruleId) or
isLanguage1QueryMetadata(query, queryId, ruleId) or
isMiscQueryMetadata(query, queryId, ruleId) or
isPointers1QueryMetadata(query, queryId, ruleId) or
isPointers2QueryMetadata(query, queryId, ruleId) or
Expand Down
24 changes: 24 additions & 0 deletions rule_packages/c/Language1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"MISRA-C-2012": {
"DIR-4-3": {
"properties": {
"obligation": "required"
},
"queries": [
{
"description": "Failing to encapsulate assembly language limits the portability, reliability, and readability of programs.",
"kind": "problem",
"name": "Assembly language shall be encapsulated and isolated",
"precision": "very-high",
"severity": "error",
"short_name": "LanguageNotEncapsulatedAndIsolated",
"tags": [
"maintainability",
"readability"
]
}
],
"title": "Assembly language shall be encapsulated and isolated"
}
}
}
2 changes: 1 addition & 1 deletion rules.csv
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ c,MISRA-C-2012,RULE-2-1,Yes,Required,,,All source files shall compile without an
c,MISRA-C-2012,RULE-3-1,No,Required,,,All code shall be traceable to documented requirements,,,,
c,MISRA-C-2012,RULE-4-1,No,Required,,,Run-time failures shall be minimized,,,,
c,MISRA-C-2012,RULE-4-2,Yes,Advisory,,,All usage of assembly language should be documented,M7-4-1,Language,Import,
c,MISRA-C-2012,RULE-4-3,Yes,Required,,,Assembly language shall be encapsulated and isolated,,Language,Medium,
c,MISRA-C-2012,DIR-4-3,Yes,Required,,,Assembly language shall be encapsulated and isolated,,Language1,Medium,
c,MISRA-C-2012,RULE-4-4,Yes,Advisory,,,Sections of code should not be commented out,A2-7-2,Syntax,Import,
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,
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,
Expand Down