Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f3bbbb

Browse filesBrowse files
authored
Merge branch 'main' into jsinglet/automation-check-shared-rules
2 parents a669ecb + 48f7ef5 commit 7f3bbbb
Copy full SHA for 7f3bbbb

File tree

Expand file treeCollapse file tree

70 files changed

+1081
-197
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

70 files changed

+1081
-197
lines changed
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
| test.c:18:3:18:27 | declaration | This statement is dead code. |
2+
| test.c:19:3:19:12 | ExprStmt | This statement is dead code. |
3+
| test.c:20:3:20:12 | ExprStmt | This statement is dead code. |
4+
| test.c:22:3:24:3 | if (...) ... | This statement is dead code. |
5+
| test.c:34:3:35:3 | if (...) ... | This statement is dead code. |
6+
| test.c:37:3:37:4 | { ... } | This statement is dead code. |
7+
| test.c:38:3:40:3 | { ... } | This statement is dead code. |
8+
| test.c:54:6:55:3 | { ... } | This statement is dead code. |
9+
| test.c:65:46:66:3 | { ... } | This statement is dead code. |
10+
| test.c:69:3:69:8 | ExprStmt | This statement is dead code. |
11+
| test.c:71:3:71:21 | ExprStmt | This statement is dead code. |
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.deadcode.DeadCode

‎c/common/test/rules/deadcode/test.c

Copy file name to clipboard
+74Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND
2+
// CHANGES SHOULD BE REFLECTED THERE AS WELL.
3+
#include <stdbool.h>
4+
5+
int may_have_side_effects();
6+
int no_side_effects(int x) { return 1 + 2; }
7+
int no_side_effects_nondeterministic();
8+
9+
int test_dead_code(int x) {
10+
int live1 = may_have_side_effects(),
11+
live2 = may_have_side_effects(); // COMPLIANT
12+
int live3 = 0,
13+
live4 = may_have_side_effects(); // COMPLIANT
14+
int live5 = 0, live6 = 0; // COMPLIANT
15+
live5 = 1; // COMPLIANT
16+
live6 = 2; // COMPLIANT
17+
18+
int dead1 = 0, dead2 = 0; // NON_COMPLIANT
19+
dead1 = 1; // NON_COMPLIANT - useless assignment
20+
dead2 = 1; // NON_COMPLIANT - useless assignment
21+
22+
if (false) { // NON_COMPLIANT
23+
dead2 = 10; // Only used in dead or unreachable code
24+
}
25+
26+
if (true) { // COMPLIANT
27+
may_have_side_effects();
28+
}
29+
30+
if (may_have_side_effects()) { // COMPLIANT
31+
may_have_side_effects();
32+
}
33+
34+
if (true) { // NON_COMPLIANT
35+
}
36+
37+
{} // NON_COMPLIANT
38+
{ // NON_COMPLIANT
39+
1 + 2;
40+
}
41+
42+
{ // COMPLIANT
43+
may_have_side_effects();
44+
}
45+
46+
do { // COMPLIANT
47+
may_have_side_effects();
48+
} while (may_have_side_effects());
49+
50+
do { // COMPLIANT
51+
may_have_side_effects();
52+
} while (may_have_side_effects());
53+
54+
do { // NON_COMPLIANT
55+
} while (no_side_effects_nondeterministic());
56+
57+
while (may_have_side_effects()) { // COMPLIANT
58+
may_have_side_effects();
59+
}
60+
61+
while (may_have_side_effects()) { // COMPLIANT
62+
may_have_side_effects();
63+
}
64+
65+
while (no_side_effects_nondeterministic()) { // NON_COMPLIANT
66+
}
67+
68+
may_have_side_effects(); // COMPLIANT
69+
1 + 2; // NON_COMPLIANT
70+
71+
no_side_effects(x); // NON_COMPLIANT
72+
73+
return live5 + live6; // COMPLIANT
74+
}
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.c:17:3:17:12 | declaration | This statement in function $@ is unreachable. | test.c:15:5:15:21 | test_after_return | test_after_return |
2+
| test.c:21:10:22:12 | { ... } | This statement in function $@ is unreachable. | test.c:20:5:20:27 | test_constant_condition | test_constant_condition |
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.unreachablecode.UnreachableCode
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND
2+
// CHANGES SHOULD BE REFLECTED THERE AS WELL.
3+
4+
void test_switch(int p1) {
5+
int l1 = 0;
6+
switch (p1) {
7+
l1 = p1; // NON_COMPLIANT[FALSE_NEGATIVE]
8+
case 1:
9+
break;
10+
default:
11+
break;
12+
}
13+
}
14+
15+
int test_after_return() {
16+
return 0;
17+
int l1 = 0; // NON_COMPLIANT - function has returned by this point
18+
}
19+
20+
int test_constant_condition() {
21+
if (0) { // NON_COMPLIANT
22+
return 1;
23+
} else { // COMPLIANT
24+
return 2;
25+
}
26+
}
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.c:6:22:6:22 | x | Unused parameter 'x' for function $@. | test.c:6:6:6:16 | test_unused | test_unused |
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// GENERATED FILE - DO NOT MODIFY
2+
import codingstandards.cpp.rules.unusedparameter.UnusedParameter
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// NOTICE: THE TEST CASES BELOW ARE ALSO INCLUDED IN THE C++ TEST CASE AND
2+
// CHANGES SHOULD BE REFLECTED THERE AS WELL.
3+
4+
int test_used(int x) { return x; } // COMPLIANT
5+
6+
void test_unused(int x) {} // NON_COMPLIANT
7+
8+
void test_no_def(int x); // COMPLIANT - no definition, so cannot be "unused"
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| file://:0:0:0:0 | __va_list_tag | Type declaration __va_list_tag is not used. |
2+
| test.c:4:8:4:8 | A | Type declaration A is not used. |
3+
| test.c:7:18:7:18 | D | Type declaration D is not used. |
4+
| test.c:28:11:28:11 | R | Type declaration R is not used. |
5+
| test.c:41:12:41:12 | struct <unnamed> | Type declaration struct <unnamed> is not used. |

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.