We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 12df863 + e7b53b2 commit 8d94339Copy full SHA for 8d94339
5 files changed
amendments.csv
@@ -24,7 +24,7 @@ c,MISRA-C-2012,Amendment4,RULE-8-9,Yes,Clarification,Yes,Import
24
c,MISRA-C-2012,Amendment4,RULE-9-4,Yes,Clarification,Yes,Import
25
c,MISRA-C-2012,Amendment4,RULE-10-1,Yes,Clarification,Yes,Import
26
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
+c,MISRA-C-2012,Amendment4,RULE-1-4,Yes,Replace,Yes,Easy
28
c,MISRA-C-2012,Amendment4,RULE-9-1,Yes,Refine,Yes,Easy
29
c,MISRA-C-2012,Corrigendum2,DIR-4-10,Yes,Clarification,Yes,Import
30
c,MISRA-C-2012,Corrigendum2,RULE-7-4,Yes,Refine,Yes,Easy
c/misra/test/rules/RULE-1-4/EmergentLanguageFeaturesUsed.expected
@@ -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. |
3
| 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
@@ -1,15 +1,15 @@
#include <stdalign.h> //COMPLIANT
-#include <stdatomic.h> //NON_COMPLIANT
+#include <stdatomic.h> //COMPLIANT
#include <stdnoreturn.h> //COMPLIANT
-#include <threads.h> //NON_COMPLIANT
+#include <threads.h> //COMPLIANT
-#define MACRO(x) _Generic((x), int : 0, long : 1) // NON_COMPLIANT
+#define MACRO(x) _Generic((x), int : 0, long : 1) // COMPLIANT
#define __STDC_WANT_LIB_EXT1__ 1 // NON_COMPLIANT
8
9
_Noreturn void f0(); // COMPLIANT
10
11
typedef int new_type; // COMPLIANT
12
-typedef _Atomic new_type atomic_new_type; // NON_COMPLIANT
+typedef _Atomic new_type atomic_new_type; // COMPLIANT
13
14
void f(int p) {
15
int i0 = _Generic(p, int : 0, long : 1); // COMPLIANT
@@ -21,6 +21,6 @@ void f(int p) {
21
int a = _Alignof(int); // COMPLIANT
22
int a1 = alignof(int); // COMPLIANT
23
- static thread_local int i3; // NON_COMPLIANT
- static _Thread_local int i4; // NON_COMPLIANT
+ static thread_local int i3; // COMPLIANT
+ static _Thread_local int i4; // COMPLIANT
}
change_notes/2025-03-31-allow-atomics-threads-and-threadlocals-in-misra-c.md
@@ -0,0 +1,2 @@
+ - `RULE-1-4` - `EmergentLanguageFeaturesUsed.ql`:
+ - Allow usage of atomics, `thread.h`, and `_Thread_local` as per Misra C 2012 Amendment 4.
cpp/common/src/codingstandards/cpp/Emergent.qll
@@ -6,24 +6,6 @@ import cpp
module C11 {
abstract class EmergentLanguageFeature extends Element { }
- class AtomicVariableSpecifier extends EmergentLanguageFeature, Variable {
- AtomicVariableSpecifier() {
- getType().(DerivedType).getBaseType*().getASpecifier().getName() = "atomic"
- }
-
- 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" }
- class EmergentHeader extends EmergentLanguageFeature, Include {
- EmergentHeader() { getIncludedFile().getBaseName() = ["stdatomic.h", "threads.h"] }
class LibExt1Macro extends EmergentLanguageFeature, Macro {
LibExt1Macro() {
getName() = "__STDC_WANT_LIB_EXT1__" and
0 commit comments