adlint 1.16.0 → 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/ChangeLog +471 -0
  2. data/MANIFEST +35 -8
  3. data/NEWS +50 -4
  4. data/bin/adlint +7 -7
  5. data/bin/adlint_chk +7 -7
  6. data/bin/adlint_cma +7 -7
  7. data/bin/adlint_sma +7 -7
  8. data/bin/adlintize +5 -5
  9. data/etc/mesg.d/en_US/messages.yml +3 -3
  10. data/etc/mesg.d/ja_JP/messages.yml +3 -3
  11. data/features/message_detection/E0013.feature +34 -0
  12. data/features/message_detection/W0007.feature +2 -0
  13. data/features/message_detection/W0583.feature +1 -2
  14. data/features/message_detection/W0641.feature +132 -0
  15. data/features/message_detection/W0643.feature +1 -1
  16. data/features/message_detection/W0644.feature +529 -0
  17. data/features/message_detection/W0645.feature +1 -1
  18. data/features/message_detection/W0649.feature +277 -0
  19. data/features/message_detection/W0650.feature +208 -0
  20. data/features/message_detection/W0697.feature +6 -0
  21. data/features/message_detection/W0705.feature +350 -0
  22. data/features/message_detection/W0707.feature +223 -0
  23. data/features/message_detection/W0711.feature +113 -0
  24. data/features/message_detection/W0712.feature +113 -0
  25. data/features/message_detection/W0713.feature +110 -0
  26. data/features/message_detection/W0714.feature +118 -0
  27. data/features/message_detection/W0715.feature +118 -0
  28. data/features/message_detection/W0716.feature +1 -0
  29. data/features/message_detection/W0717.feature +1 -0
  30. data/features/message_detection/W0718.feature +1 -0
  31. data/features/message_detection/W0719.feature +154 -0
  32. data/features/message_detection/W0723.feature +1 -2
  33. data/features/message_detection/W0732.feature +3 -0
  34. data/features/message_detection/W0733.feature +3 -0
  35. data/features/message_detection/W0734.feature +4 -0
  36. data/features/message_detection/W0735.feature +4 -0
  37. data/features/message_detection/W0745.feature +132 -0
  38. data/features/message_detection/W0780.feature +68 -0
  39. data/features/message_detection/W0783.feature +95 -0
  40. data/features/message_detection/W0792.feature +124 -0
  41. data/features/message_detection/W0793.feature +153 -0
  42. data/features/message_detection/W0794.feature +90 -0
  43. data/features/message_detection/W0830.feature +65 -0
  44. data/features/message_detection/W0833.feature +220 -0
  45. data/features/message_detection/W0834.feature +189 -0
  46. data/features/message_detection/W1026.feature +105 -0
  47. data/features/message_detection/W1031.feature +17 -34
  48. data/features/message_detection/W1039.feature +268 -0
  49. data/features/message_detection/W1047.feature +163 -0
  50. data/features/message_detection/W1066.feature +1 -0
  51. data/features/message_detection/W1067.feature +1 -0
  52. data/features/message_detection/W1068.feature +1 -0
  53. data/features/message_detection/W1069.feature +5 -0
  54. data/features/message_detection/W1070.feature +5 -0
  55. data/features/message_detection/W1071.feature +83 -0
  56. data/features/message_detection/W1073.feature +3 -2
  57. data/features/message_detection/W9003.feature +7 -12
  58. data/features/step_definitions/message_detection_steps.rb +4 -31
  59. data/features/support/env.rb +117 -2
  60. data/lib/adlint/c/branch.rb +0 -2
  61. data/lib/adlint/c/ctrlexpr.rb +33 -0
  62. data/lib/adlint/c/expr.rb +119 -31
  63. data/lib/adlint/c/interp.rb +44 -3
  64. data/lib/adlint/c/message.rb +1411 -29
  65. data/lib/adlint/c/object.rb +16 -2
  66. data/lib/adlint/c/option.rb +1 -0
  67. data/lib/adlint/c/parser.rb +101 -100
  68. data/lib/adlint/c/parser.y +3 -2
  69. data/lib/adlint/c/phase.rb +18 -0
  70. data/lib/adlint/c/resolver.rb +23 -0
  71. data/lib/adlint/c/syntax.rb +90 -4
  72. data/lib/adlint/c/type.rb +177 -110
  73. data/lib/adlint/cpp/macro.rb +4 -4
  74. data/lib/adlint/version.rb +2 -2
  75. data/share/demo/bad_include/test/"1/".h +0 -0
  76. data/share/doc/developers_guide_ja.html +3 -3
  77. data/share/doc/developers_guide_ja.texi +1 -1
  78. data/share/doc/users_guide_en.html +467 -506
  79. data/share/doc/users_guide_en.texi +95 -125
  80. data/share/doc/users_guide_ja.html +471 -518
  81. data/share/doc/users_guide_ja.texi +95 -133
  82. data/spec/spec_helper.rb +6 -0
  83. metadata +37 -10
@@ -0,0 +1,163 @@
1
+ Feature: W1047
2
+
3
+ W1047 detects that an initializer of struct, union or array variable contains
4
+ non-constant expressions.
5
+
6
+ Scenario: initializing array with non-constant expressions
7
+ Given a target source named "W1047.c" with:
8
+ """
9
+ int foo(int i, int j)
10
+ {
11
+ int a[] = { 0, i, j }; /* W1047 */
12
+ return a[1];
13
+ }
14
+ """
15
+ When I successfully run `adlint W1047.c` on noarch
16
+ Then the output should exactly match with:
17
+ | mesg | line | column |
18
+ | W0117 | 1 | 5 |
19
+ | W1047 | 3 | 9 |
20
+ | W0100 | 3 | 9 |
21
+ | W0104 | 1 | 13 |
22
+ | W0104 | 1 | 20 |
23
+ | W0628 | 1 | 5 |
24
+
25
+ Scenario: initializing struct with non-constant expressions
26
+ Given a target source named "W1047.c" with:
27
+ """
28
+ struct Coord {
29
+ int x;
30
+ int y;
31
+ int z;
32
+ };
33
+
34
+ int foo(int i, int j)
35
+ {
36
+ struct Coord c = { i, j, 0 }; /* W1047 */
37
+ return c.y;
38
+ }
39
+ """
40
+ When I successfully run `adlint W1047.c` on noarch
41
+ Then the output should exactly match with:
42
+ | mesg | line | column |
43
+ | W0117 | 7 | 5 |
44
+ | W1047 | 9 | 18 |
45
+ | W0100 | 9 | 18 |
46
+ | W0104 | 7 | 13 |
47
+ | W0104 | 7 | 20 |
48
+ | W0628 | 7 | 5 |
49
+
50
+ Scenario: initializing union with non-constant expressions
51
+ Given a target source named "W1047.c" with:
52
+ """
53
+ struct Color {
54
+ int r;
55
+ int g;
56
+ int b;
57
+ };
58
+
59
+ struct Coord {
60
+ int x;
61
+ int y;
62
+ };
63
+
64
+ struct Event {
65
+ int type;
66
+ union {
67
+ struct Color color;
68
+ struct Coord coord;
69
+ } body;
70
+ };
71
+
72
+ int foo(int i, int j)
73
+ {
74
+ struct Event ev = { 0, { i, j, 0 } }; /* W1047 */
75
+ return ev.body.color.g;
76
+ }
77
+ """
78
+ When I successfully run `adlint W1047.c` on noarch
79
+ Then the output should exactly match with:
80
+ | mesg | line | column |
81
+ | W0117 | 20 | 5 |
82
+ | W1047 | 22 | 18 |
83
+ | W0100 | 22 | 18 |
84
+ | W0104 | 20 | 13 |
85
+ | W0104 | 20 | 20 |
86
+ | W0551 | 14 | 5 |
87
+ | W0628 | 20 | 5 |
88
+
89
+ Scenario: initializing array with all constant expressions
90
+ Given a target source named "W1047.c" with:
91
+ """
92
+ int foo(void)
93
+ {
94
+ int a[] = { 0, 1, 2 }; /* OK */
95
+ return a[1];
96
+ }
97
+ """
98
+ When I successfully run `adlint W1047.c` on noarch
99
+ Then the output should exactly match with:
100
+ | mesg | line | column |
101
+ | W0117 | 1 | 5 |
102
+ | W0100 | 3 | 9 |
103
+ | W0628 | 1 | 5 |
104
+
105
+ Scenario: initializing struct with all constant expressions
106
+ Given a target source named "W1047.c" with:
107
+ """
108
+ struct Coord {
109
+ int x;
110
+ int y;
111
+ int z;
112
+ };
113
+
114
+ int foo(void)
115
+ {
116
+ struct Coord c = { 2, 1, 0 }; /* OK */
117
+ return c.y;
118
+ }
119
+ """
120
+ When I successfully run `adlint W1047.c` on noarch
121
+ Then the output should exactly match with:
122
+ | mesg | line | column |
123
+ | W0117 | 7 | 5 |
124
+ | W0100 | 9 | 18 |
125
+ | W0628 | 7 | 5 |
126
+
127
+ Scenario: initializing union with all constant expressions
128
+ Given a target source named "W1047.c" with:
129
+ """
130
+ struct Color {
131
+ int r;
132
+ int g;
133
+ int b;
134
+ };
135
+
136
+ struct Coord {
137
+ int x;
138
+ int y;
139
+ };
140
+
141
+ struct Event {
142
+ int type;
143
+ union {
144
+ struct Color color;
145
+ struct Coord coord;
146
+ } body;
147
+ };
148
+
149
+ int foo(void)
150
+ {
151
+ struct Event ev = { 0, { 2, 1, 0 } }; /* OK */
152
+ return ev.body.color.g;
153
+ }
154
+ """
155
+ When I successfully run `adlint W1047.c` on noarch
156
+ Then the output should exactly match with:
157
+ | mesg | line | column |
158
+ | W0117 | 20 | 5 |
159
+ | W0100 | 22 | 18 |
160
+ | W0551 | 14 | 5 |
161
+ | W0628 | 20 | 5 |
162
+
163
+ # vim:ts=2:sw=2:sts=2:et:
@@ -53,6 +53,7 @@ Feature: W1066
53
53
  | W0093 | 4 | 21 |
54
54
  | W0570 | 6 | 21 |
55
55
  | W0572 | 6 | 21 |
56
+ | W0794 | 6 | 21 |
56
57
  | W0572 | 7 | 21 |
57
58
  | W0104 | 1 | 24 |
58
59
  | W0104 | 1 | 33 |
@@ -53,6 +53,7 @@ Feature: W1067
53
53
  | W0093 | 4 | 26 |
54
54
  | W0570 | 6 | 26 |
55
55
  | W0572 | 6 | 26 |
56
+ | W0794 | 6 | 26 |
56
57
  | W0572 | 7 | 26 |
57
58
  | W0104 | 1 | 24 |
58
59
  | W0104 | 1 | 33 |
@@ -53,6 +53,7 @@ Feature: W1068
53
53
  | W0093 | 4 | 26 |
54
54
  | W0570 | 6 | 26 |
55
55
  | W0572 | 6 | 26 |
56
+ | W0794 | 6 | 26 |
56
57
  | W0572 | 7 | 26 |
57
58
  | W0104 | 1 | 25 |
58
59
  | W0104 | 1 | 35 |
@@ -22,6 +22,7 @@ Feature: W1069
22
22
  | mesg | line | column |
23
23
  | W1076 | 1 | 12 |
24
24
  | W0104 | 1 | 21 |
25
+ | W1071 | 1 | 12 |
25
26
  | W0629 | 1 | 12 |
26
27
  | W1069 | 3 | 5 |
27
28
  | W0628 | 1 | 12 |
@@ -48,6 +49,7 @@ Feature: W1069
48
49
  | mesg | line | column |
49
50
  | W1076 | 1 | 12 |
50
51
  | W0104 | 1 | 21 |
52
+ | W1071 | 1 | 12 |
51
53
  | W0629 | 1 | 12 |
52
54
  | W1069 | 3 | 5 |
53
55
  | W0628 | 1 | 12 |
@@ -76,6 +78,7 @@ Feature: W1069
76
78
  | mesg | line | column |
77
79
  | W1076 | 1 | 12 |
78
80
  | W0104 | 1 | 21 |
81
+ | W1071 | 1 | 12 |
79
82
  | W0629 | 1 | 12 |
80
83
  | W0628 | 1 | 12 |
81
84
 
@@ -95,6 +98,7 @@ Feature: W1069
95
98
  | mesg | line | column |
96
99
  | W1076 | 1 | 12 |
97
100
  | W0104 | 1 | 21 |
101
+ | W1071 | 1 | 12 |
98
102
  | W0629 | 1 | 12 |
99
103
  | W0628 | 1 | 12 |
100
104
 
@@ -119,6 +123,7 @@ Feature: W1069
119
123
  | mesg | line | column |
120
124
  | W1076 | 1 | 12 |
121
125
  | W0104 | 1 | 21 |
126
+ | W1071 | 1 | 12 |
122
127
  | W0629 | 1 | 12 |
123
128
  | W0628 | 1 | 12 |
124
129
 
@@ -20,6 +20,7 @@ Feature: W1070
20
20
  Then the output should exactly match with:
21
21
  | mesg | line | column |
22
22
  | W1076 | 1 | 12 |
23
+ | W1071 | 1 | 12 |
23
24
  | W0629 | 1 | 12 |
24
25
  | W1070 | 3 | 5 |
25
26
  | W0628 | 1 | 12 |
@@ -43,6 +44,7 @@ Feature: W1070
43
44
  Then the output should exactly match with:
44
45
  | mesg | line | column |
45
46
  | W1076 | 1 | 12 |
47
+ | W1071 | 1 | 12 |
46
48
  | W0629 | 1 | 12 |
47
49
  | W0003 | 3 | 5 |
48
50
  | W1070 | 3 | 5 |
@@ -69,6 +71,7 @@ Feature: W1070
69
71
  Then the output should exactly match with:
70
72
  | mesg | line | column |
71
73
  | W1076 | 1 | 12 |
74
+ | W1071 | 1 | 12 |
72
75
  | W0629 | 1 | 12 |
73
76
  | W9001 | 5 | 9 |
74
77
  | W9001 | 6 | 13 |
@@ -118,6 +121,7 @@ Feature: W1070
118
121
  Then the output should exactly match with:
119
122
  | mesg | line | column |
120
123
  | W1076 | 1 | 12 |
124
+ | W1071 | 1 | 12 |
121
125
  | W0629 | 1 | 12 |
122
126
  | W9001 | 5 | 9 |
123
127
  | W9001 | 6 | 13 |
@@ -145,6 +149,7 @@ Feature: W1070
145
149
  Then the output should exactly match with:
146
150
  | mesg | line | column |
147
151
  | W1076 | 1 | 12 |
152
+ | W1071 | 1 | 12 |
148
153
  | W0629 | 1 | 12 |
149
154
  | W0628 | 1 | 12 |
150
155
 
@@ -0,0 +1,83 @@
1
+ Feature: W1071
2
+
3
+ W1071 detects that a function has multiple termination points.
4
+
5
+ Scenario: explicit returns and implicit return
6
+ Given a target source named "W1071.c" with:
7
+ """
8
+ void foo(int i) /* W1071 */
9
+ {
10
+ if (i == 0) {
11
+ return;
12
+ }
13
+ }
14
+ """
15
+ When I successfully run `adlint W1071.c` on noarch
16
+ Then the output should exactly match with:
17
+ | mesg | line | column |
18
+ | W0117 | 1 | 6 |
19
+ | W0104 | 1 | 14 |
20
+ | W1071 | 1 | 6 |
21
+ | W0628 | 1 | 6 |
22
+
23
+ Scenario: explicit return and no implicit return
24
+ Given a target source named "W1071.c" with:
25
+ """
26
+ void foo(int i) /* OK */
27
+ {
28
+ switch (i) {
29
+ default:
30
+ return;
31
+ }
32
+ }
33
+ """
34
+ When I successfully run `adlint W1071.c` on noarch
35
+ Then the output should exactly match with:
36
+ | mesg | line | column |
37
+ | W0117 | 1 | 6 |
38
+ | W0104 | 1 | 14 |
39
+ | W0781 | 3 | 5 |
40
+ | W0628 | 1 | 6 |
41
+
42
+ Scenario: dead explicit return and implicit return
43
+ Given a target source named "W1071.c" with:
44
+ """
45
+ void foo(unsigned int ui) /* OK */
46
+ {
47
+ if (ui < 0U) {
48
+ return; /* dead-code */
49
+ }
50
+ }
51
+ """
52
+ When I successfully run `adlint W1071.c` on noarch
53
+ Then the output should exactly match with:
54
+ | mesg | line | column |
55
+ | W0117 | 1 | 6 |
56
+ | W0613 | 3 | 12 |
57
+ | W0610 | 3 | 12 |
58
+ | W0104 | 1 | 23 |
59
+ | W9001 | 4 | 9 |
60
+ | W0628 | 1 | 6 |
61
+
62
+ Scenario: explicit returns and no implicit return
63
+ Given a target source named "W1071.c" with:
64
+ """
65
+ int foo(int i) /* W1071 */
66
+ {
67
+ if (i == 0) {
68
+ return 0;
69
+ }
70
+ else {
71
+ return 1;
72
+ }
73
+ }
74
+ """
75
+ When I successfully run `adlint W1071.c` on noarch
76
+ Then the output should exactly match with:
77
+ | mesg | line | column |
78
+ | W0117 | 1 | 5 |
79
+ | W0104 | 1 | 13 |
80
+ | W1071 | 1 | 5 |
81
+ | W0628 | 1 | 5 |
82
+
83
+ # vim:ts=2:sw=2:sts=2:et:
@@ -41,7 +41,7 @@ Feature: W1073
41
41
  Given a target source named "W1073.c" with:
42
42
  """
43
43
  extern int bar(void);
44
- extern void baz(void);
44
+ extern int baz(void);
45
45
  static void foo(void)
46
46
  {
47
47
  int i;
@@ -52,7 +52,7 @@ Feature: W1073
52
52
  Then the output should exactly match with:
53
53
  | mesg | line | column |
54
54
  | W0118 | 1 | 12 |
55
- | W0118 | 2 | 13 |
55
+ | W0118 | 2 | 12 |
56
56
  | W1076 | 3 | 13 |
57
57
  | W0100 | 5 | 9 |
58
58
  | W1073 | 6 | 13 |
@@ -100,6 +100,7 @@ Feature: W1073
100
100
  | mesg | line | column |
101
101
  | W0118 | 1 | 12 |
102
102
  | W1076 | 2 | 13 |
103
+ | W1071 | 2 | 13 |
103
104
  | W0629 | 2 | 13 |
104
105
  | W0628 | 2 | 13 |
105
106
 
@@ -18,8 +18,7 @@ Feature: W9003
18
18
  }
19
19
  """
20
20
  When I successfully run `adlint W9003.c` on noarch
21
- Then the output should match with /8:.*:W9003/
22
- And the output should exactly match with:
21
+ Then the output should exactly match with:
23
22
  | mesg | line | column |
24
23
  | W0118 | 4 | 13 |
25
24
  | W1076 | 6 | 13 |
@@ -41,8 +40,7 @@ Feature: W9003
41
40
  }
42
41
  """
43
42
  When I successfully run `adlint W9003.c` on noarch
44
- Then the output should match with /7:.*:W9003/
45
- And the output should exactly match with:
43
+ Then the output should exactly match with:
46
44
  | mesg | line | column |
47
45
  | W0118 | 3 | 13 |
48
46
  | W1076 | 5 | 13 |
@@ -64,8 +62,7 @@ Feature: W9003
64
62
  }
65
63
  """
66
64
  When I successfully run `adlint W9003.c` on noarch
67
- Then the output should match with /7:.*:W9003/
68
- And the output should exactly match with:
65
+ Then the output should exactly match with:
69
66
  | mesg | line | column |
70
67
  | W0118 | 3 | 13 |
71
68
  | W1076 | 5 | 13 |
@@ -81,8 +78,7 @@ Feature: W9003
81
78
  int i = RED; /* W9003 */
82
79
  """
83
80
  When I successfully run `adlint W9003.c` on noarch
84
- Then the output should match with /2:.*:W9003/
85
- And the output should exactly match with:
81
+ Then the output should exactly match with:
86
82
  | mesg | line | column |
87
83
  | W9003 | 2 | 9 |
88
84
  | W0117 | 2 | 5 |
@@ -94,8 +90,7 @@ Feature: W9003
94
90
  enum Color c = 1; /* W9003 */
95
91
  """
96
92
  When I successfully run `adlint W9003.c` on noarch
97
- Then the output should match with /2:.*:W9003/
98
- And the output should exactly match with:
93
+ Then the output should exactly match with:
99
94
  | mesg | line | column |
100
95
  | W9003 | 2 | 16 |
101
96
  | W0117 | 2 | 12 |
@@ -116,8 +111,7 @@ Feature: W9003
116
111
  }
117
112
  """
118
113
  When I successfully run `adlint W9003.c` on noarch
119
- Then the output should match with /6:.*:W9003/
120
- And the output should exactly match with:
114
+ Then the output should exactly match with:
121
115
  | mesg | line | column |
122
116
  | W1076 | 3 | 12 |
123
117
  | W0727 | 6 | 20 |
@@ -125,6 +119,7 @@ Feature: W9003
125
119
  | W9003 | 6 | 18 |
126
120
  | W1060 | 6 | 18 |
127
121
  | W0104 | 3 | 27 |
122
+ | W1071 | 3 | 12 |
128
123
  | W0629 | 3 | 12 |
129
124
  | W0490 | 5 | 9 |
130
125
  | W0497 | 5 | 9 |
@@ -1,41 +1,14 @@
1
1
  Given /^a target source named "(.*)" with:$/ do |src_name, content|
2
- write_file(src_name, content + "\n")
3
- end
4
-
5
- Given /^expected messages of "(.*)" are:$/ do |src_name, mesg_table|
6
- write_file("#{src_name}.expected", mesg_table.hashes.map { |row|
7
- "#{row[:mesg]} #{row[:line]} #{row[:column]}" }.join("\n"))
2
+ create_src_file(src_name, content)
8
3
  end
9
4
 
10
5
  When /^I successfully run `(.*)` on noarch$/ do |abbrev_cmd|
11
- write_file("noarch_traits.yml", NOARCH_TRAITS)
12
- write_file("empty_pinit.h", "\n")
13
- write_file("empty_cinit.h", "\n")
14
- run_simple(unescape(abbrev_cmd + " -t noarch_traits.yml"))
15
- end
16
-
17
- Then /^the output should match with \/(.*)\/$/ do |pattern|
18
- all_output.should =~ /#{pattern}/
19
- end
20
-
21
- Then /^the output should not match with \/(.*)\/$/ do |pattern|
22
- all_output.should_not =~ /#{pattern}/
23
- end
24
-
25
- Then /^the output should match with expected messages of "(.*)"$/ do |src_name|
26
- prep_for_fs_check do
27
- expected = File.read("#{src_name}.expected").each_line.map { |line|
28
- fields = line.chomp.split(" ")
29
- /#{fields[1]}:#{fields[2]}:.*:#{fields[0]}/
30
- }
31
- all_output.each_line.zip(expected).each do |line, pattern|
32
- line.should =~ pattern
33
- end
34
- end
6
+ cmd, src = abbrev_cmd.split
7
+ run_adlint(cmd, src, "-t", "noarch_traits.yml")
35
8
  end
36
9
 
37
10
  Then /^the output should exactly match with:$/ do |mesg_table|
38
- all_output.each_line.zip(mesg_table.hashes).each do |line, row|
11
+ $all_output.each_line.zip(mesg_table.hashes).each do |line, row|
39
12
  if row
40
13
  line.should =~ /#{row[:line]}:#{row[:column]}:.*:#{row[:mesg]}/
41
14
  else