Skip to content

Commit e7b53b2

Browse files
Implement Rule-1-4's rule amendment from Amendment4 (also amended in Amdt3)
1 parent eedca61 commit e7b53b2

File tree

5 files changed

+9
-31
lines changed

5 files changed

+9
-31
lines changed

amendments.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ c,MISRA-C-2012,Amendment4,RULE-8-9,Yes,Clarification,Yes,Import
2424
c,MISRA-C-2012,Amendment4,RULE-9-4,Yes,Clarification,Yes,Import
2525
c,MISRA-C-2012,Amendment4,RULE-10-1,Yes,Clarification,Yes,Import
2626
c,MISRA-C-2012,Amendment4,RULE-18-3,Yes,Clarification,Yes,Import
27-
c,MISRA-C-2012,Amendment4,RULE-1-4,Yes,Replace,No,Easy
27+
c,MISRA-C-2012,Amendment4,RULE-1-4,Yes,Replace,Yes,Easy
2828
c,MISRA-C-2012,Amendment4,RULE-9-1,Yes,Refine,Yes,Easy
2929
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,Yes,Import
3030
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,Yes,Easy
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
| test.c:2:1:2:22 | #include <stdatomic.h> | Usage of emergent language feature. |
2-
| test.c:4:1:4:20 | #include <threads.h> | Usage of emergent language feature. |
31
| test.c:7:1:7:32 | #define __STDC_WANT_LIB_EXT1__ 1 | Usage of emergent language feature. |
4-
| test.c:12:26:12:40 | atomic_new_type | Usage of emergent language feature. |
5-
| test.c:17:15:17:15 | i | Usage of emergent language feature. |
6-
| test.c:24:27:24:28 | i3 | Usage of emergent language feature. |
7-
| test.c:25:28:25:29 | i4 | Usage of emergent language feature. |

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include <stdalign.h> //COMPLIANT
2-
#include <stdatomic.h> //NON_COMPLIANT
2+
#include <stdatomic.h> //COMPLIANT
33
#include <stdnoreturn.h> //COMPLIANT
4-
#include <threads.h> //NON_COMPLIANT
4+
#include <threads.h> //COMPLIANT
55

6-
#define MACRO(x) _Generic((x), int : 0, long : 1) // NON_COMPLIANT
6+
#define MACRO(x) _Generic((x), int : 0, long : 1) // COMPLIANT
77
#define __STDC_WANT_LIB_EXT1__ 1 // NON_COMPLIANT
88

99
_Noreturn void f0(); // COMPLIANT
1010

1111
typedef int new_type; // COMPLIANT
12-
typedef _Atomic new_type atomic_new_type; // NON_COMPLIANT
12+
typedef _Atomic new_type atomic_new_type; // COMPLIANT
1313

1414
void f(int p) {
1515
int i0 = _Generic(p, int : 0, long : 1); // COMPLIANT
@@ -21,6 +21,6 @@ void f(int p) {
2121
int a = _Alignof(int); // COMPLIANT
2222
int a1 = alignof(int); // COMPLIANT
2323

24-
static thread_local int i3; // NON_COMPLIANT
25-
static _Thread_local int i4; // NON_COMPLIANT
24+
static thread_local int i3; // COMPLIANT
25+
static _Thread_local int i4; // COMPLIANT
2626
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `RULE-1-4` - `EmergentLanguageFeaturesUsed.ql`:
2+
- Allow usage of atomics, `thread.h`, and `_Thread_local` as per Misra C 2012 Amendment 4.

cpp/common/src/codingstandards/cpp/Emergent.qll

-18
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,6 @@ import cpp
66
module C11 {
77
abstract class EmergentLanguageFeature extends Element { }
88

9-
class AtomicVariableSpecifier extends EmergentLanguageFeature, Variable {
10-
AtomicVariableSpecifier() {
11-
getType().(DerivedType).getBaseType*().getASpecifier().getName() = "atomic"
12-
}
13-
}
14-
15-
class AtomicDeclaration extends EmergentLanguageFeature, Declaration {
16-
AtomicDeclaration() { getASpecifier().getName() = "atomic" }
17-
}
18-
19-
class ThreadLocalDeclaration extends EmergentLanguageFeature, Declaration {
20-
ThreadLocalDeclaration() { getASpecifier().getName() = "is_thread_local" }
21-
}
22-
23-
class EmergentHeader extends EmergentLanguageFeature, Include {
24-
EmergentHeader() { getIncludedFile().getBaseName() = ["stdatomic.h", "threads.h"] }
25-
}
26-
279
class LibExt1Macro extends EmergentLanguageFeature, Macro {
2810
LibExt1Macro() {
2911
getName() = "__STDC_WANT_LIB_EXT1__" and

0 commit comments

Comments
 (0)