Skip to content

Commit 35d2f56

Browse files
committed
Rule 2.2: Report dead function, if the op is a call
1 parent 0639b19 commit 35d2f56

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

c/misra/src/rules/RULE-2-2/DeadCode.ql

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ class DeadOperationInstance extends Expr {
7676

7777
class DeadOperation = HoldsForAllInstances<DeadOperationInstance, Expr>::LogicalResultElement;
7878

79-
from DeadOperation deadOperation
80-
where not isExcluded(deadOperation.getAnElementInstance(), DeadCodePackage::deadCodeQuery())
81-
select deadOperation, deadOperation.getAnElementInstance().getDescription() + "."
79+
from
80+
DeadOperation deadOperation, DeadOperationInstance instance, string message, Element explainer,
81+
string explainerDescription
82+
where
83+
not isExcluded(instance, DeadCodePackage::deadCodeQuery()) and
84+
instance = deadOperation.getAnElementInstance() and
85+
if instance instanceof FunctionCall
86+
then
87+
message = instance.getDescription() + " from call to function $@" and
88+
explainer = instance.(FunctionCall).getTarget() and
89+
explainerDescription = explainer.(Function).getName()
90+
else (
91+
message = instance.getDescription() and
92+
// Ignore the explainer
93+
explainer = instance and
94+
explainerDescription = ""
95+
)
96+
select deadOperation, message + ".", explainer, explainerDescription
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
| test.c:15:3:15:11 | ... = ... | Assignment to dead1 is unused and has no side effects. |
2-
| test.c:16:3:16:11 | ... = ... | Assignment to dead2 is unused and has no side effects. |
3-
| test.c:19:3:19:7 | ... + ... | Result of operation is unused and has no side effects. |
4-
| test.c:21:3:21:17 | call to no_side_effects | Result of operation is unused and has no side effects. |
5-
| test.c:23:3:23:30 | (int)... | Cast operation is unused. |
6-
| test.c:24:3:24:25 | (int)... | Cast operation is unused. |
7-
| test.c:27:4:27:18 | call to no_side_effects | Result of operation is unused and has no side effects. |
8-
| test.c:37:3:37:27 | call to no_side_effects | Result of operation is unused and has no side effects. |
9-
| test.c:38:7:38:31 | call to no_side_effects | Result of operation is unused and has no side effects. |
1+
| test.c:15:3:15:11 | ... = ... | Assignment to dead1 is unused and has no side effects. | test.c:15:3:15:11 | ... = ... | |
2+
| test.c:16:3:16:11 | ... = ... | Assignment to dead2 is unused and has no side effects. | test.c:16:3:16:11 | ... = ... | |
3+
| test.c:19:3:19:7 | ... + ... | Result of operation is unused and has no side effects. | test.c:19:3:19:7 | ... + ... | |
4+
| test.c:21:3:21:17 | call to no_side_effects | Result of operation is unused and has no side effects from call to function $@. | test.c:2:5:2:19 | no_side_effects | no_side_effects |
5+
| test.c:23:3:23:30 | (int)... | Cast operation is unused. | test.c:23:3:23:30 | (int)... | |
6+
| test.c:24:3:24:25 | (int)... | Cast operation is unused. | test.c:24:3:24:25 | (int)... | |
7+
| test.c:27:4:27:18 | call to no_side_effects | Result of operation is unused and has no side effects from call to function $@. | test.c:2:5:2:19 | no_side_effects | no_side_effects |
8+
| test.c:37:3:37:27 | call to no_side_effects | Result of operation is unused and has no side effects from call to function $@. | test.c:2:5:2:19 | no_side_effects | no_side_effects |
9+
| test.c:38:7:38:31 | call to no_side_effects | Result of operation is unused and has no side effects from call to function $@. | test.c:2:5:2:19 | no_side_effects | no_side_effects |

0 commit comments

Comments
 (0)