Skip to content

Commit 722dc6a

Browse files
Remove 17-13, simpler implementation for 17-12.
1 parent 982c597 commit 722dc6a

File tree

9 files changed

+27
-317
lines changed

9 files changed

+27
-317
lines changed

c/misra/src/rules/RULE-17-12/FunctionAddressesShouldAddressOperator.ql

Lines changed: 9 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,15 @@
1414
import cpp
1515
import codingstandards.c.misra
1616

17-
abstract class AddressOfFunction extends Expr {
18-
abstract predicate isImplicitlyAddressed();
19-
20-
abstract string getFuncName();
21-
}
22-
23-
class FunctionTypeAccess extends FunctionAccess, AddressOfFunction {
24-
25-
predicate isImmediatelyParenthesized() {
26-
exists(ParenthesisExpr parens | parens.getExpr() = this)
27-
}
28-
29-
predicate isExplicitlyAddressed() {
30-
getParent() instanceof AddressOfExpr and
31-
not isImmediatelyParenthesized()
32-
}
33-
34-
override predicate isImplicitlyAddressed() {
35-
not isExplicitlyAddressed()
36-
}
37-
38-
override string getFuncName() {
39-
result = getTarget().getName()
40-
}
41-
}
42-
43-
/*
44-
class IndirectFunctionCall extends FunctionCall, AddressOfFunction {
45-
override predicate isImplicitlyAddressed() {
46-
getConversion+() instanceof ParenthesisExpr
47-
}
48-
49-
override string getFuncName() {
50-
result = getTarget().getName()
51-
}
52-
}
53-
*/
54-
55-
class MacroArgTakesFunction extends AddressOfFunction {
56-
MacroInvocation m;
57-
MacroArgTakesFunction() {
58-
m.getExpr() = this
59-
}
60-
61-
override predicate isImplicitlyAddressed() {
62-
any()
63-
}
64-
65-
string getProp() {
66-
result = m.getExpandedArgument(_)
67-
and this.get
68-
}
69-
70-
override string getFuncName() {
71-
result = "a macro argument"
72-
}
73-
17+
predicate isImplicitlyAddressed(FunctionAccess access) {
18+
not access.getParent() instanceof AddressOfExpr or
19+
exists(ParenthesisExpr parens | parens.getExpr() = access)
7420
}
7521

76-
from AddressOfFunction funcAddr
22+
from FunctionAccess funcAccess
7723
where
78-
not isExcluded(funcAddr, FunctionTypesPackage::functionAddressesShouldAddressOperatorQuery()) and
79-
//not funcAccess.isImmediatelyCalled() and
80-
//not funcAccess.isExplicitlyAddressed()
81-
funcAddr.isImplicitlyAddressed()
82-
select
83-
funcAddr, "The address of function " + funcAddr.getFuncName() + " is taken without the & operator."
24+
not isExcluded(funcAccess, FunctionTypesPackage::functionAddressesShouldAddressOperatorQuery()) and
25+
isImplicitlyAddressed(funcAccess)
26+
select funcAccess,
27+
"The address of function " + funcAccess.getTarget().getName() +
28+
" is taken without the & operator."

c/misra/src/rules/RULE-17-13/DisallowedFunctionTypeQualifier.ql

Lines changed: 0 additions & 147 deletions
This file was deleted.
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
| test.c:15:25:15:29 | func2 | The address of function func2 is taken without the & operator. |
22
| test.c:16:27:16:31 | func3 | The address of function func3 is taken without the & operator. |
33
| test.c:22:16:22:20 | func1 | The address of function func1 is taken without the & operator. |
4-
| test.c:38:5:38:9 | func1 | The address of function func1 is taken without the & operator. |
5-
| test.c:39:5:39:9 | func2 | The address of function func2 is taken without the & operator. |
6-
| test.c:47:7:47:11 | func1 | The address of function func1 is taken without the & operator. |
7-
| test.c:48:7:48:11 | func2 | The address of function func2 is taken without the & operator. |
8-
| test.c:57:15:57:19 | func1 | The address of function func1 is taken without the & operator. |
9-
| test.c:58:23:58:27 | func2 | The address of function func2 is taken without the & operator. |
10-
| test.c:59:15:59:19 | func1 | The address of function func1 is taken without the & operator. |
11-
| test.c:59:22:59:26 | func2 | The address of function func2 is taken without the & operator. |
12-
| test.c:67:13:67:17 | func1 | The address of function func1 is taken without the & operator. |
13-
| test.c:68:14:68:18 | func1 | The address of function func1 is taken without the & operator. |
4+
| test.c:39:5:39:9 | func1 | The address of function func1 is taken without the & operator. |
5+
| test.c:40:5:40:9 | func2 | The address of function func2 is taken without the & operator. |
6+
| test.c:48:7:48:11 | func1 | The address of function func1 is taken without the & operator. |
7+
| test.c:49:7:49:11 | func2 | The address of function func2 is taken without the & operator. |
8+
| test.c:58:15:58:19 | func1 | The address of function func1 is taken without the & operator. |
9+
| test.c:59:23:59:27 | func2 | The address of function func2 is taken without the & operator. |
10+
| test.c:60:15:60:19 | func1 | The address of function func1 is taken without the & operator. |
11+
| test.c:60:22:60:26 | func2 | The address of function func2 is taken without the & operator. |
12+
| test.c:68:13:68:17 | func1 | The address of function func1 is taken without the & operator. |
1413
| test.c:69:14:69:18 | func1 | The address of function func1 is taken without the & operator. |
15-
| test.c:71:20:71:24 | func1 | The address of function func1 is taken without the & operator. |
14+
| test.c:70:14:70:18 | func1 | The address of function func1 is taken without the & operator. |
1615
| test.c:72:20:72:24 | func1 | The address of function func1 is taken without the & operator. |
17-
| test.c:76:20:76:24 | func1 | The address of function func1 is taken without the & operator. |
18-
| test.c:77:20:77:24 | func1 | The address of function func1 is taken without the & operator. |

c/misra/test/rules/RULE-17-12/test.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func_ptr_t1 returns_func(int x) {
3030
#define MACRO_IDENTITY(f) (f)
3131
#define MACRO_INVOKE_RISKY(f) (f())
3232
#define MACRO_INVOKE_IMPROVED(f) ((f)())
33+
#define MACRO_INVOKE_AND_USE_AS_TOKEN(f) f(0, #f)
3334

3435
void test() {
3536
func1(); // COMPLIANT
@@ -69,14 +70,16 @@ void test() {
6970
((void*) func1); // NON-COMPLIANT
7071

7172
MACRO_IDENTITY(func1); // NON-COMPLIANT
72-
MACRO_IDENTITY(func1)(); // NON-COMPLIANT
73+
MACRO_IDENTITY(func1)(); // NON-COMPLIANT[FALSE NEGATIVE]
7374
MACRO_IDENTITY(&func1); // COMPLIANT
7475
MACRO_IDENTITY(&func1)(); // COMPLIANT
7576

76-
MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT
77-
MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT
77+
MACRO_INVOKE_RISKY(func3); // NON-COMPLIANT[FALSE NEGATIVE]
78+
MACRO_INVOKE_IMPROVED(func3); // NON-COMPLIANT[FALSE NEGATIVE]
7879
MACRO_INVOKE_IMPROVED(&func3); // COMPLIANT
7980

81+
MACRO_INVOKE_AND_USE_AS_TOKEN(func1); // COMPLIANT
82+
8083
// Function pointers are exempt from this rule.
8184
func_ptr1(); // COMPLIANT
8285
func_ptr2(1, "hello"); // COMPLIANT

c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.

c/misra/test/rules/RULE-17-13/DisallowedFunctionTypeQualifier.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

c/misra/test/rules/RULE-17-13/test.c

Lines changed: 0 additions & 56 deletions
This file was deleted.

cpp/common/src/codingstandards/cpp/exclusions/c/FunctionTypes.qll

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import cpp
33
import RuleMetadata
44
import codingstandards.cpp.exclusions.RuleMetadata
55

6-
newtype FunctionTypesQuery =
7-
TFunctionAddressesShouldAddressOperatorQuery() or
8-
TDisallowedFunctionTypeQualifierQuery()
6+
newtype FunctionTypesQuery = TFunctionAddressesShouldAddressOperatorQuery()
97

108
predicate isFunctionTypesQueryMetadata(Query query, string queryId, string ruleId, string category) {
119
query =
@@ -16,15 +14,6 @@ predicate isFunctionTypesQueryMetadata(Query query, string queryId, string ruleI
1614
"c/misra/function-addresses-should-address-operator" and
1715
ruleId = "RULE-17-12" and
1816
category = "advisory"
19-
or
20-
query =
21-
// `Query` instance for the `disallowedFunctionTypeQualifier` query
22-
FunctionTypesPackage::disallowedFunctionTypeQualifierQuery() and
23-
queryId =
24-
// `@id` for the `disallowedFunctionTypeQualifier` query
25-
"c/misra/disallowed-function-type-qualifier" and
26-
ruleId = "RULE-17-13" and
27-
category = "required"
2817
}
2918

3019
module FunctionTypesPackage {
@@ -34,11 +23,4 @@ module FunctionTypesPackage {
3423
// `Query` type for `functionAddressesShouldAddressOperator` query
3524
TQueryC(TFunctionTypesPackageQuery(TFunctionAddressesShouldAddressOperatorQuery()))
3625
}
37-
38-
Query disallowedFunctionTypeQualifierQuery() {
39-
//autogenerate `Query` type
40-
result =
41-
// `Query` type for `disallowedFunctionTypeQualifier` query
42-
TQueryC(TFunctionTypesPackageQuery(TDisallowedFunctionTypeQualifierQuery()))
43-
}
4426
}

0 commit comments

Comments
 (0)