Serious bug in C compiler of DDE 27 related to memset()
André Timmermans (100) 655 posts |
After recompiling !KinoAmp with the new compiler, I found out that it could not display its OSD. After some debugging I found the origin of the problem: here is the C code
and the generated assembler:
as I indicate in the generated code, after the inlined memset(), the code attempts to use R12 to reset R0 to the start of the structure but R12 does not contain its original value anymore, the loop decreased it to 0. The C compiler options used are: |
Jeffrey Lee (213) 6048 posts |
Ouch! Some testing here suggests that this is a pretty old bug – stretching at least as far back as cc 5.65 from 2006. Experimenting with the size of player_t suggests that the bug is triggered whenever the structure becomes so large that it can’t use an immediate constant in the “SUB R0,R0,xxx”, at which point it switches to using R12 under the false assumption that it still holds the correct value. So it will probably start happening whenever the size is greater than 4K. I guess a safe workaround would be to create a function that wraps memset, so that the compiler will never see any direct calls to memset with a constant size parameter. I’ve added this to the bug tracker, so hopefully it will be fixed by the time the next DDE release rolls round. |
André Timmermans (100) 655 posts |
Hope the release a quick fix soon, in the mean time its back to the my old compiler on my RiscPC. I don’t want to track down and work around all the potentially broken memset() in my modules and applications, maybe with the exception of KinoAmp for which I add in mind toying with some NEON optimised routines at some point. Looking back at the generated code, I also hope that the compiler has a way to ensure that the pointer given on entry is word aligned before using such an inlined STM loop. |
Jeff Doggett (257) 234 posts |
I don’t think that it does. I came unstuck in Fat32fs with an inlined memset (or it may have been memcpy) used on an unaligned pointer. I ended up having to ensure that the pointer was aligned. I also hope that the compiler can be made to realise that (in the example given above ) that R4 has what it wants. |
Jeffrey Lee (213) 6048 posts |
It looks like the compiler takes into account the expected alignment of the type when deciding if it should inline the memset. memset of a |