This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Fix MSVC warning C6001 "Using uninitialized memory".
AbandonedPublic

Authored by STL_MSFT on Dec 7 2016, 5:35 PM.

Details

Summary

[libcxx] [test] Fix MSVC warning C6001 "Using uninitialized memory".

/analyze sees array::size() being called on arrays with garbage-inited doubles,
and complains. It doesn't know that size() doesn't actually care about the
contents of the array. There's a simple way to sidestep this issue - just use
std::string, which has a default constructor.

Diff Detail

Event Timeline

STL_MSFT updated this revision to Diff 80695.Dec 7 2016, 5:35 PM
STL_MSFT retitled this revision from to [libcxx] [test] Fix MSVC warning C6001 "Using uninitialized memory"..
STL_MSFT updated this object.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.
EricWF edited edge metadata.Dec 7 2016, 11:21 PM

Are you planning on fixing this in your compiler?

It was debatable to me whether this was actually a compiler bug, but I suppose that it can see size()'s definition and should be able to notice that the elements aren't accessed. I've filed VSO#300037 "Bogus warning C6001 "Using uninitialized memory" for array::size()".

I'd still like to have this workaround upstreamed; I've made a note to myself to revert it when the compiler bug is fixed. (We're locking down for VS 2017 RTM, so that may not happen quickly, but fortunately only this one simple test is affected.)

EricWF accepted this revision.Dec 10 2016, 6:06 PM
EricWF edited edge metadata.

I'm happy to work around this one issue but in general I dislike initializing memory to avoid compile-time warnings. Doing so prevents the sanitizers from catching actual uninitialized memory bugs. For this reason I think the warning is an actual compiler bug because it hinders sanitizer usage and possibly hides bugs.

This revision is now accepted and ready to land.Dec 10 2016, 6:06 PM

Hmm, would a pragma guarded by _MSC_VER be better? I can easily do that. I've tried to avoid cluttering the test with VC-specific pragmas, but I understand your concern about initializing too much memory.

Actually, the compiler bug was resolved as fixed earlier today. Verifying...

STL_MSFT abandoned this revision.Dec 12 2016, 12:42 PM

Verified compiler fix. Abandoning this patch - nothing has been committed.