On Fri, Oct 18, 2019 at 11:25:53AM +0100, Richard Earnshaw (lists) wrote: > > Ah, yes. Looking at some libc sources it puts an explicit optimization > attribute onto the memset (and similar mem... functions) to disable > -ftree-loop-distribute-patterns for such functions. So something like > > void * > __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) > memset (void *s, int c, size_t n) > { > int i; > for (i=0; i<n; i++) > ((char *)s)[i] = c; > > return s; > } > > Though, of course, it's wrapped up in a macro to make it look a bit prettier > ;-) Thanks, Richard! This finally fixes the crashes! But Umm... Honestly, this solution looks pretty wired to me. When the compiler decides to replace code by a call to some function, shouldn't it make sure not to replace _all_ occurences of such code (and thus the final implementation of it) also? To me, this looks as if the compiler failed to implement the base case of the recursion. Instead, the user is expected to specify obscure attributes. What if the next -fsuper-duper-optimization flag again starts doing such replacements? > This is just one of those gotchas that you have to be aware of when > implementing the standard library. I am not implementing the standard library. I am just trying to get rid of it. I need just a couple of functions from the stdlib, and I was happy with simple/lightwight re-implementations of those functions for decades. -- Josef Wolf jw@xxxxxxxxxxxxx