This is an archive of the discontinued LLVM Phabricator instance.

More on adding sized deallocation functions in libc++
ClosedPublic

Authored by lvoufo on Feb 17 2015, 3:33 PM.

Details

Summary

Continuing from r229281, this adds version guards and test cases.

Diff Detail

Event Timeline

lvoufo updated this revision to Diff 20117.Feb 17 2015, 3:33 PM
lvoufo retitled this revision from to More on adding sized deallocation functions in libc++.
lvoufo updated this object.
lvoufo edited the test plan for this revision. (Show Details)
lvoufo added reviewers: rsmith, mclow.lists.
lvoufo added a subscriber: Unknown Object (MLST).

This extends D7799, excluding the _LIBCPP_BUILDING_NEW guard.

lvoufo updated this revision to Diff 20120.Feb 17 2015, 3:46 PM

Adding _LIBCPP_BUILDING_NEW guards.

lvoufo updated this revision to Diff 20121.Feb 17 2015, 3:49 PM

Fix a typo in new.cpp

rsmith edited edge metadata.Feb 17 2015, 6:43 PM

Remove the _LIBCPP_BUILDING_NEW guard. If people want the useless C++14 declarations, they can build in C++14 mode...

src/new.cpp
134

Remove this #if/#endif pair and define the weak version unconditionally. The contents of the standard library should not depend on the -std= flag passed when bulding it. Because this function is weak, this won't break valid C++11 and earlier code that happens to be defining such a function.

164

Likewise.

test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array.pass.cpp
54

This is not guaranteed to work; your calls to operator new and operator delete are elidable. Directly call operator delete here. (That also lets you run this test in all language modes, not just C++14 mode.)

test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_nothrow.pass.cpp
30

It's questionable to assume that memory allocated by libc++'s operator new can be freed by std::free. I would suggest either replacing operator new[] too, or just leaking the memory.

mclow.lists added inline comments.Feb 17 2015, 9:01 PM
src/new.cpp
134

Exactly correct. There should be no requirement to coordinate the -std= flag used to build the library and the flag used to build programs that use the library.

test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_nothrow.pass.cpp
30

I would prefer replacing operator new[] as well.

49

Shouldn't this be A* ap = new (std::nothrow) A [3]; ??

I am uploading an update in a few minutes...

src/new.cpp
134

Done.

134

Ok.

164

Done.

test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array.pass.cpp
54

Ok, on the extension of the test in all language modes.
As far as guaranteeing that this works, I would like to keep these passes
(1) consistent with the current design (in {new, new_nothrow, new_array, new_array_nothrow}.pass.cpp), and
(2) more focused on changes in delete than in new,
(3) as resulting from using new/delete expressions rather than new/delete operator function calls (which, as confirmed by some quick tests, happen to follow different lookup paths).
So, I think I'll just define a new handler similarly to the passes in (1).

This incidentally highlights something we may have missed in the standard on sized nothrow deallocation (see FIXMEs on related test cases below).

test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array_nothrow.pass.cpp
30

For the reasons I gave above, I would rather provide a new handler, similarly to the current tests' design, than replace new.

49

Right. I find it strange that the libcxx test system did not catch this error, and several others below. I actually took a closer and replaced the value of 'config.std' in my test/lit.site.cfg file from "c++11" to "c++1y".
Then, running make check-libcxx with this change led to the following unexpected failures.
I wonder if these might happen to be false negatives somehow... How do we normally test "c++14" mode in libcxx?

Failing Tests (11):

libc++ :: std/experimental/string.view/string.view.find/find_last_not_of_char_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.find/find_last_not_of_pointer_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.find/find_last_not_of_pointer_size_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.find/find_last_of_pointer_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.find/find_last_of_pointer_size_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.find/rfind_pointer_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.find/rfind_pointer_size_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.find/rfind_string_view_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.ops/compare.pointer_size.pass.cpp
libc++ :: std/experimental/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp
libc++ :: std/experimental/utilities/time/header.chrono.synop/treat_as_floating_point_v.pass.cpp
lvoufo updated this revision to Diff 20245.Feb 18 2015, 5:46 PM
lvoufo edited edge metadata.

Updated with better tests and based on previous reviewers' comments.

I need to push this in for now, for some time-pressing tests.
This should be safe since it is passing all regression tests and not breaking anything.
We can always roll back later if anything else comes up.

In r229968.

mclow.lists accepted this revision.Mar 17 2015, 8:00 AM
mclow.lists edited edge metadata.
This revision is now accepted and ready to land.Mar 17 2015, 8:00 AM
mclow.lists closed this revision.Jun 16 2015, 6:26 PM