Commit 25f3131
committed
copilot-c99: Pass output arrays as arguments to trigger argument functions. Refs #431.
Copilot's C99 backend generates incorrect code for trigger argument functions
that return constant arrays. Currently, the code will return a pointer to a
stack-allocated array. That memory may be used for something else after the
call to the trigger argument function, so it may be overwritten or freed by the
time the array is used. This may lead to the array holding incorrect values.
This is almost the same issue that was noticed in #386, except that #386 was
specifically about stream generator functions, whereas this issue is
specifically about trigger argument functions.
This commit changes array trigger argument functions so that they receive a
pointer to an array for the output argument. The part of the generated code
that applies the trigger argument functions has also been updated accordingly
such that when the argument has an array type, the output array is passed
directly as an argument (e.g., `f_arg0(temp_array)`) rather than being assigned
(e.g., `temp_array = f_arg0()`).
Because we pass output arrays directly to trigger argument functions, we no
longer have to have a special case in the code for declaring temporary
variables for output arrays as pointers (e.g., `int* temp_array;`). Instead, we
can declare these temporary variables directly as arrays (e.g., `int
temp_array[2];`). This makes the intent clearer and simplifies the
implementation in `copilot-c99`.1 parent 907d5bb commit 25f3131
2 files changed
+19
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
| 253 | + | |
| 254 | + | |
269 | 255 | | |
270 | 256 | | |
271 | 257 | | |
| |||
283 | 269 | | |
284 | 270 | | |
285 | 271 | | |
286 | | - | |
| 272 | + | |
287 | 273 | | |
288 | | - | |
289 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
290 | 284 | | |
291 | | - | |
292 | | - | |
| 285 | + | |
| 286 | + | |
293 | 287 | | |
294 | 288 | | |
295 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
134 | 137 | | |
135 | 138 | | |
136 | 139 | | |
| |||
0 commit comments