Re:Proposal for a Friendly Dialect of C
by DSMan195276 on Wednesday August 27, 2014 @03:58PM
(#8234424)
If you don't mind me taking a guess, is it because calling memcpy with NULL is undefined-behavior, thus GCC assumes p must be non-null and thus the if (p) is redundant and x must equal 1?
Re:Proposal for a Friendly Dialect of C
by pascal_cuoq on Wednesday August 27, 2014 @04:08PM
(#8234466)
Exactly. Propagating the information that p was passed as argument to memcpy and thus must be non-null is a new GCC 4.9 optimization (some discussion here: http://stackoverflow.com/questions/5243012/is-it-guaranteed-... ).
Despite this, a fortnight ago I was caught off-guard by GCC 4.9's choice of compiling the program in http://pastebin.com/raw.php?i=fRbGfQ6p to an executable that displays “p is non-null” followed by “p:(nil)”.
There has to be a way out of this. Seriously. Most C programmers neither asked for nor deserve this.