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 3939 (
4040 conditionAlwaysFalse ( expr )
4141 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
4345 )
4446 ) and
4547 message = "Controlling expression in loop statement has invariant value."
5355 ) and
5456 message = "Controlling expression in switch statement has invariant value."
5557 ) 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.
5760 not expr .isAffectedByMacro ( )
5861select 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+
13void f1 (int p1 ) {
24 if (2 > 3 ) { // NON_COMPLIANT
35 }
@@ -18,3 +20,10 @@ void f2() {
1820 for (int i = 10 ; i < 5 ; i ++ ) { // NON_COMPLIANT
1921 }
2022}
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