@SpaceLifeForm You are confused. Passing 0 is not UB; it can merely be optimized away. Passing NULL is UB, and in this case the compiler is using the fact that the pointer cannot safely be NULL to optimize subsequent code.
Posts
-
Today's discovery: gcc will remove calls to memcpy() with a len of 0 (good), knows it's UB to call memcpy() with a dest of NULL (spec compliant), will assume that dest can't be NULL (fucking compilers, man), will combine both to engage in this UTTERLY ... -
Today's discovery: gcc will remove calls to memcpy() with a len of 0 (good), knows it's UB to call memcpy() with a dest of NULL (spec compliant), will assume that dest can't be NULL (fucking compilers, man), will combine both to engage in this UTTERLY ...@SpaceLifeForm The compiler can see the exact values passed and optimize for them. Ie the compiler can look for passing an obvious zero to memcpy, which it couldn’t do if it were just a variable passed across a translation unit boundary.
-
Today's discovery: gcc will remove calls to memcpy() with a len of 0 (good), knows it's UB to call memcpy() with a dest of NULL (spec compliant), will assume that dest can't be NULL (fucking compilers, man), will combine both to engage in this UTTERLY ...@SpaceLifeForm It’s inlined.
-
Thank you, Mastodon community!@Mastodon can we please not use a tip economy as a business model?