This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Use stack buffers for uninitialized storage in tests.
ClosedPublic

Authored by var-const on Nov 1 2022, 1:00 PM.

Details

Summary

This makes the tests more minimal, and in particular it avoids relying on a complete <cstdlib>, which may not be available on all platforms.

Diff Detail

Event Timeline

var-const created this revision.Nov 1 2022, 1:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 1:00 PM
var-const published this revision for review.Nov 1 2022, 3:32 PM
var-const edited the summary of this revision. (Show Details)
var-const edited the summary of this revision. (Show Details)
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 3:33 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne accepted this revision.Nov 1 2022, 3:37 PM
This revision is now accepted and ready to land.Nov 1 2022, 3:37 PM
philnik accepted this revision.Nov 1 2022, 3:46 PM
philnik added a subscriber: philnik.

LGTM with the alignment bug fixed.

libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/construct_pair.pass.cpp
40–42

You could instead do

union { P p; };
a.construct(&p);

That would fix the alignment bug and avoid a reinterpret_cast.

var-const updated this revision to Diff 472438.Nov 1 2022, 4:02 PM

Fix alignment.

var-const marked an inline comment as done.Nov 1 2022, 4:03 PM
var-const added inline comments.
libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/construct_pair.pass.cpp
40–42

That doesn't work because the default constructors in question are non-trivial. How about using alignas instead?

philnik accepted this revision.Nov 1 2022, 4:06 PM
philnik added inline comments.
libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/construct_pair.pass.cpp
40–42

Ah, I missed that. Then alignas is probably the correct call.

This revision was automatically updated to reflect the committed changes.
var-const marked an inline comment as done.