Example: write a function without side effects except writing to a local array whose address is returned. The entire function disappears.
-
-
Replying to @marcan42
@marcan42 compile with -fno-whole-program ?1 reply 0 retweets 0 likes -
Replying to @twoscomplement
@twoscomplement I'm compiling only, not linking, and that doesn't change anything. I'm using -O2. It doesn't delete the function with <=-O1.1 reply 0 retweets 0 likes -
Replying to @marcan42
@marcan42 Is the function marked static? It can't be deleted otherwise. I'm not seeing the same behavior with my gcc.2 replies 0 retweets 0 likes -
Replying to @twoscomplement
@twoscomplement Try: char *foo(const char *a) { char b[256]; memcpy(b,a,256); return b; } Watch the memcpy disappear.1 reply 0 retweets 0 likes -
Replying to @marcan42
@marcan42 The compiler can do whatever it likes with invalid input. Be thankful it didn't result in demons flying out of your nose :P1 reply 0 retweets 0 likes
@twoscomplement I know; I was trying to see whether it would optimize a particular detail out but cheated and got more than I bargained for.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.