[cfe-dev] (no subject)

Matthijs van Duin matthijsvanduin at gmail.com
Wed Aug 5 05:03:25 PDT 2015


When compiling without optimization it will depend entirely on whatever
happens to be on the stack where the object is allocated, hence on whatever
was left behind by the initialization code that executed before main was
invoked. (If the init code never reached that stack depth, then
consistently getting zero is expected since the stack is zero-initialized
by the OS.)

Example: http://melpon.org/wandbox/permlink/7BlNvpS6Hq34fqTi

Note how the second invocation of foo() prints the value left behind by the
first invocation of foo().

Of course even if it consistently printed zero, that would still not be a
sound way to detect unnecessary zero-initialization, since if it is
uninitialized then the value that is printed is undefined, in which case
consistently printing zero is just as reasonable as any other value. (Also,
even it it *did* perform zero-initialization, this would be inefficient but
not incorrect, hence it doesn't actually make sense to perform this test
without optimization enabled.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150805/a211d2a3/attachment.html>


More information about the cfe-dev mailing list