Skip to content

Commit fea9922

Browse files
authored
Merge branch 'main' into rdmarsh2/allocation-expr-instanceof
2 parents 798a350 + 19c5636 commit fea9922

20 files changed

+275
-14
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
"Iterators",
223223
"Lambdas",
224224
"Language1",
225+
"Language2",
225226
"Literals",
226227
"Loops",
227228
"Macros",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @id c/misra/usage-of-assembly-language-should-be-documented
3+
* @name DIR-4-2: All usage of assembly language should be documented
4+
* @description Assembly language is not portable and should be documented.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity warning
8+
* @tags external/misra/id/dir-4-2
9+
* maintainability
10+
* readability
11+
* external/misra/obligation/advisory
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented
17+
18+
class UsageOfAssemblyLanguageShouldBeDocumentedQuery extends UsageOfAssemblerNotDocumentedSharedQuery {
19+
UsageOfAssemblyLanguageShouldBeDocumentedQuery() {
20+
this = Language2Package::usageOfAssemblyLanguageShouldBeDocumentedQuery()
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @id c/misra/emergent-language-features-used
3+
* @name RULE-1-4: Emergent language features shall not be used
4+
* @description Emergent language features may have unpredictable behavior and should not be used.
5+
* @kind problem
6+
* @precision very-high
7+
* @problem.severity warning
8+
* @tags external/misra/id/rule-1-4
9+
* maintainability
10+
* readability
11+
* external/misra/obligation/required
12+
*/
13+
14+
import cpp
15+
import codingstandards.c.misra
16+
import codingstandards.cpp.Emergent
17+
18+
from C11::EmergentLanguageFeature ef
19+
where not isExcluded(ef, Language2Package::emergentLanguageFeaturesUsedQuery())
20+
select ef, "Usage of emergent language feature."
21+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
| test.c:1:1:1:21 | #include <stdalign.h> | Usage of emergent language feature. |
2+
| test.c:2:1:2:22 | #include <stdatomic.h> | Usage of emergent language feature. |
3+
| test.c:3:1:3:24 | #include <stdnoreturn.h> | Usage of emergent language feature. |
4+
| test.c:4:1:4:20 | #include <threads.h> | Usage of emergent language feature. |
5+
| test.c:6:1:6:49 | #define MACRO(x) _Generic((x), int : 0, long : 1) | Usage of emergent language feature. |
6+
| test.c:7:1:7:32 | #define __STDC_WANT_LIB_EXT1__ 1 | Usage of emergent language feature. |
7+
| test.c:9:16:9:17 | f0 | Usage of emergent language feature. |
8+
| test.c:12:26:12:40 | atomic_new_type | Usage of emergent language feature. |
9+
| test.c:17:15:17:15 | i | Usage of emergent language feature. |
10+
| test.c:19:3:19:10 | alignas(...) | Usage of emergent language feature. |
11+
| test.c:20:3:20:9 | alignas(...) | Usage of emergent language feature. |
12+
| test.c:21:11:21:23 | alignof(int) | Usage of emergent language feature. |
13+
| test.c:22:12:22:23 | alignof(int) | Usage of emergent language feature. |
14+
| test.c:24:27:24:28 | i3 | Usage of emergent language feature. |
15+
| test.c:25:28:25:29 | i4 | Usage of emergent language feature. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-1-4/EmergentLanguageFeaturesUsed.ql

c/misra/test/rules/RULE-1-4/test.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdalign.h> //NON_COMPLIANT
2+
#include <stdatomic.h> //NON_COMPLIANT
3+
#include <stdnoreturn.h> //NON_COMPLIANT
4+
#include <threads.h> //NON_COMPLIANT
5+
6+
#define MACRO(x) _Generic((x), int : 0, long : 1) // NON_COMPLIANT
7+
#define __STDC_WANT_LIB_EXT1__ 1 // NON_COMPLIANT
8+
9+
_Noreturn void f0(); // NON_COMPLIANT
10+
11+
typedef int new_type; // COMPLIANT
12+
typedef _Atomic new_type atomic_new_type; // NON_COMPLIANT
13+
14+
void f(int p) {
15+
int i0 = _Generic(p, int : 0, long : 1); // NON_COMPLIANT[FALSE_NEGATIVE]
16+
17+
_Atomic int i; // NON_COMPLIANT
18+
19+
_Alignas(4) int i1; // NON_COMPLIANT
20+
alignas(4) int i2; // NON_COMPLIANT
21+
int a = _Alignof(int); // NON_COMPLIANT
22+
int a1 = alignof(int); // NON_COMPLIANT
23+
24+
static thread_local int i3; // NON_COMPLIANT
25+
static _Thread_local int i4; // NON_COMPLIANT
26+
}

cpp/autosar/src/rules/M7-4-1/UsageOfAssemblerNotDocumented.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
import cpp
1919
import codingstandards.cpp.autosar
20+
import codingstandards.cpp.rules.usageofassemblernotdocumented.UsageOfAssemblerNotDocumented
2021

21-
from AsmStmt a
22-
where
23-
not isExcluded(a, BannedLibrariesPackage::usageOfAssemblerNotDocumentedQuery()) and
24-
not exists(Comment c | c.getCommentedElement() = a) and
25-
not a.isAffectedByMacro()
26-
select a, "Use of assembler is not documented."
22+
class UsageOfAssemblerNotDocumentedQuery extends UsageOfAssemblerNotDocumentedSharedQuery {
23+
UsageOfAssemblerNotDocumentedQuery() {
24+
this = BannedLibrariesPackage::usageOfAssemblerNotDocumentedQuery()
25+
}
26+
}

cpp/autosar/test/rules/M7-4-1/UsageOfAssemblerNotDocumented.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpp/common/test/rules/usageofassemblernotdocumented/UsageOfAssemblerNotDocumented.ql

0 commit comments

Comments
 (0)