Ticket #444 (Fixed)Wed Dec 13 18:05:55 UTC 2017
cc 5.72 abort on data transfer with __packed structs
Reported by: | Colin (478) | Severity: | Major |
Part: | RISC OS: C/C++ toolchain | Release: | |
Milestone: | Status | Fixed |
Details by Colin (478):
The following code causes an abort on data transfer error. If I remove the __packed keyword it works ok, if I uncomment ‘buf.size = buf.size’ it works ok or if I reverse the nested loop order so that s is outer and i is inner it works ok.
#include <stdint.h>
uint32_t array[] = {100, 200, 300, 400, 500, 600, 700, 800, 900};
#define ARRAYSIZE (sizeof(array) / sizeof(array[0]))
int main(void) { __packed struct { uint16_t size; struct { uint32_t min, max, res; } range[ARRAYSIZE]; } buf;
buf.size = 2;
for (unsigned i = 0; i < buf.size; i++) { for (int s = 0; s < ARRAYSIZE; s++) { // buf.size = buf.size; if (array[s] >= buf.range[i].min && array[s] <= buf.range[i].max) { break; } } } return 0; }
Changelog:
Modified by Sprow (202) Sun, December 17 2017 - 09:19:38 GMT
To clarify: it’s the resulting output code that aborts, not the compiler.
The abort is caused by trying to read a word from a non word aligned offset.
Uncommenting the line mentioned causes an (aligned) LDM to be used instead, so it at least doesn’t abort, but I’m not convinced it’s accounted for the offset of 2 correctly and might well be silently incorrect instead.
Modified by Sprow (202) Fri, December 29 2017 - 12:43:25 GMT
- Part changed from Unspecified to RISC OS: C/C++ toolchain
Modified by Bert (7232) Sat, January 12 2019 - 19:43:56 GMT
What happens if the range structure is also marked __packed? Any improvement?
Modified by Sprow (202) Sat, October 31 2020 - 09:02:24 GMT
- Status changed from Open to Fixed
Fixed in CC version 5.85 (also mentioned in the changelog with DDE30).