Commit ca738f7
committed
Merge branch 'develop-misra-2012'. Close #472.
**Description**
The code generated by Copilot is not fully compliant with MISRA C. At
present, it complies with all but one rules, and all but two directives
of MISRA C 2012.
Due to the nature of this project and the environment where it is meant
to be used, we want to have compliance with all MISRA C rules, and if
possible with all MISRA C directives.
Any deviations should be properly justified and documented.
**Type**
- Feature: Compliance with MISRA C 2012.
**Additional context**
None.
**Requester**
- Patrick Quach (NASA)
**Method to check presence of bug**
Not applicable (not a bug).
**Expected result**
The code produced by Copilot complies with all rules in MISRA C 2012.
Any deviations from any rules or directives are documented and
justified.
**Solution implemented**
Modify `copilot-c99` to add keyword `static` to guards and generator
functions. That requires using language-c99-simple >= 0.3.
Modify `copilot-c99` backend to explicitly cast constants to `size_t` in
manipulations of the ring buffers.
Add a tool to the CI process that checks for compliance with the standard.
**Further notes**
The solution includes a new test in the CI setup that uses cppcheck to
check that a Copilot-generated C file complies with MISRA C. The test is
being executed by the CI setup (see:
https://app.travis-ci.com/github/Copilot-Language/copilot/jobs/615908458#L1976-L1978).
Furthermore, Parasoft has been used to manually check the same example
for compliance. Parasoft's tool reports a violation of one advisory
only: Directive 4.6. Complying with that recommendation would require
using specific types that indicate the size and signedness instead of
float and double. Although we could call those float32_t and float64_t,
there is in principle no guarantee that those will be the sizes in all
architectures, making such names potentially misleading. Since this is a
recommendation, we decide to accept non-compliance with this directive.
This change does not modify the README, contrary to the solution
originally proposed. This is intentional: there is no suitable place to
indicate information about compliance, or lack thereof, with MISRA C.
We decide to defer this change, and suggest extending the README to show
the features of Copilot more prominently. That will create the space to
talk about MISRA compliance and also list the advisory we do not
currently comply with.File tree
5 files changed
+41
-14
lines changed- copilot-c99
- src/Copilot/Compile/C99
- copilot
5 files changed
+41
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | 5 | | |
3 | 6 | | |
| |||
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| |||
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
| 104 | + | |
104 | 105 | | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
108 | 115 | | |
109 | 116 | | |
110 | 117 | | |
| |||
113 | 120 | | |
114 | 121 | | |
115 | 122 | | |
116 | | - | |
| 123 | + | |
| 124 | + | |
117 | 125 | | |
| 126 | + | |
118 | 127 | | |
119 | 128 | | |
120 | 129 | | |
121 | 130 | | |
122 | 131 | | |
123 | 132 | | |
124 | | - | |
| 133 | + | |
125 | 134 | | |
| 135 | + | |
126 | 136 | | |
127 | 137 | | |
128 | 138 | | |
| |||
145 | 155 | | |
146 | 156 | | |
147 | 157 | | |
148 | | - | |
| 158 | + | |
149 | 159 | | |
150 | 160 | | |
151 | 161 | | |
| |||
194 | 204 | | |
195 | 205 | | |
196 | 206 | | |
197 | | - | |
198 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
199 | 213 | | |
200 | 214 | | |
201 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
0 commit comments