Skip to content

Commit d70ea29

Browse files
Address feedback
1 parent 99af17c commit d70ea29

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

c/misra/src/rules/RULE-11-10/AtomicQualifierAppliedToVoid.ql

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,33 @@ class AtomicVoidType extends Type {
2323
}
2424
}
2525

26-
Type getNestedType(Type root) {
27-
result = root
26+
predicate usesAtomicVoid(Type root) {
27+
root instanceof AtomicVoidType
2828
or
29-
exists(DerivedType derived | derived = root | result = getNestedType(derived.getBaseType()))
29+
usesAtomicVoid(root.(DerivedType).getBaseType())
30+
or
31+
usesAtomicVoid(root.(RoutineType).getReturnType())
32+
or
33+
usesAtomicVoid(root.(RoutineType).getAParameterType())
34+
or
35+
usesAtomicVoid(root.(FunctionPointerType).getReturnType())
36+
or
37+
usesAtomicVoid(root.(FunctionPointerType).getAParameterType())
38+
or
39+
usesAtomicVoid(root.(TypedefType).getBaseType())
40+
}
41+
42+
class ExplicitType extends Type {
43+
Element getDeclaration(string description) {
44+
result.(DeclarationEntry).getType() = this and description = result.(DeclarationEntry).getName()
45+
or
46+
result.(CStyleCast).getType() = this and description = "Cast"
47+
}
3048
}
3149

32-
from DeclarationEntry decl, AtomicVoidType atomicVoid
50+
from Element decl, ExplicitType explicitType, string elementDescription
3351
where
3452
not isExcluded(decl, Declarations9Package::atomicQualifierAppliedToVoidQuery()) and
35-
atomicVoid = getNestedType(decl.getType())
36-
select decl, decl.getName() + " declared with an atomic void type."
53+
decl = explicitType.getDeclaration(elementDescription) and
54+
usesAtomicVoid(explicitType)
55+
select decl, elementDescription + " declared with an atomic void type."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
| test.c:3:15:3:16 | definition of g3 | g3 declared with an atomic void type. |
22
| test.c:10:17:10:18 | definition of m3 | m3 declared with an atomic void type. |
33
| test.c:15:22:15:23 | definition of p2 | p2 declared with an atomic void type. |
4+
| test.c:20:23:20:24 | declaration of f2 | f2 declared with an atomic void type. |
5+
| test.c:21:25:21:26 | declaration of f3 | f3 declared with an atomic void type. |
6+
| test.c:22:14:22:15 | declaration of f4 | f4 declared with an atomic void type. |
7+
| test.c:23:16:23:17 | declaration of f5 | f5 declared with an atomic void type. |
8+
| test.c:27:3:27:19 | (_Atomic(void) *)... | Cast declared with an atomic void type. |

c/misra/test/rules/RULE-11-10/test.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ void f(_Atomic int p1, // COMPLIANT
1515
_Atomic void *p2 // NON_COMPLIANT
1616
// _Atomic void p3[] // doesn't compile, even though it perhaps should as
1717
// it is adjusted to void*.
18-
) {}
18+
) {}
19+
20+
typedef _Atomic void *f2(void); // NON_COMPLIANT
21+
typedef _Atomic void *(*f3)(void); // NON_COMPLIANT
22+
typedef void f4(_Atomic void *); // NON_COMPLIANT
23+
typedef void (*f5)(_Atomic void *); // NON_COMPLIANT
24+
25+
void f6() {
26+
(void *)0; // COMPLIANT
27+
(_Atomic void *)0; // NON_COMPLIANT
28+
}

0 commit comments

Comments
 (0)