File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 39
39
(
40
40
conditionAlwaysFalse ( expr )
41
41
or
42
- conditionAlwaysTrue ( expr )
42
+ conditionAlwaysTrue ( expr ) and
43
+ // Exception allows for infinite loops, but we only permit that for literals like `true`
44
+ not expr instanceof Literal
43
45
)
44
46
) and
45
47
message = "Controlling expression in loop statement has invariant value."
53
55
) and
54
56
message = "Controlling expression in switch statement has invariant value."
55
57
) and
56
- // Exclude macros, which may generate seemingly invariant expressions
58
+ // Exclude cases where the controlling expressions is affected by a macro, because they can appear
59
+ // invariant in a particular invocation, but be variant between invocations.
57
60
not expr .isAffectedByMacro ( )
58
61
select expr , message
Original file line number Diff line number Diff line change 1
- | test.c:2:7:2:11 | ... > ... | Controlling expression in if statement has invariant value. |
2
- | test.c:13:10:13:16 | ... > ... | Controlling expression in loop statement has invariant value. |
3
- | test.c:14:9:14:13 | ... > ... | Controlling expression in if statement has invariant value. |
4
- | test.c:18:20:18:24 | ... < ... | Controlling expression in loop statement has invariant value. |
1
+ | test.c:4:7:4:11 | ... > ... | Controlling expression in if statement has invariant value. |
2
+ | test.c:15:10:15:16 | ... > ... | Controlling expression in loop statement has invariant value. |
3
+ | test.c:16:9:16:13 | ... > ... | Controlling expression in if statement has invariant value. |
4
+ | test.c:20:20:20:24 | ... < ... | Controlling expression in loop statement has invariant value. |
5
+ | test.c:27:10:27:14 | ... < ... | Controlling expression in loop statement has invariant value. |
Original file line number Diff line number Diff line change
1
+ #include <stdbool.h>
2
+
1
3
void f1 (int p1 ) {
2
4
if (2 > 3 ) { // NON_COMPLIANT
3
5
}
@@ -18,3 +20,10 @@ void f2() {
18
20
for (int i = 10 ; i < 5 ; i ++ ) { // NON_COMPLIANT
19
21
}
20
22
}
23
+
24
+ void f3 () {
25
+ while (true) { // Permitted by exception
26
+ }
27
+ while (1 < 2 ) { // NON_COMPLIANT - likely an indication of a bug
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments