On Thu, 4 Jun 2020, Ville Voutilainen wrote:

Right, I was just wondering whether we can reasonably verify in a test that the whole shebang is not zeroed. That may need a tree-dump scan in the test, and probably should go into PR86173 anyway, so I'm not saying such a thing needs to be a part of this fix.

The optimized dumps changed with the patch:

-  <retval> = {};
+  MEM[(struct optional *)&<retval>] ={v} {CLOBBER};
   MEM[(union _Storage *)&<retval>] ={v} {CLOBBER};
+  MEM[(struct _Optional_payload_base *)&<retval>]._M_engaged = 0;
   return <retval>;

checking for the absence of "<retval> = {}", or the presence of _M_engaged, may be robust enough across platforms. It doesn't really guarantee that nothing writes to the buffer though.

Maybe create a buffer, fill it with some non-zero values (-1?), then call placement new, and read some value in the middle of the buffer, possibly with some protection against optimizations? Ah, no, actual constructors are fine, it is only the inlined initialization that happens with the defaulted constructor that zeroes things.

--
Marc Glisse

Reply via email to