Ticket #444 (Open)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 | Open |
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