This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Enable aligned allocation based on feature test macro, irrespective of standard
ClosedPublic

Authored by ldionne on Aug 6 2018, 11:53 AM.

Details

Summary

The current code enables aligned allocation functions when compiling in C++17
and later. This is a problem because aligned allocation functions might not
be supported on the target platform, which leads to an error at link time.

Since r338934, Clang knows not to define __cpp_aligned_new when it's not
available on the target platform -- this commit takes advantage of that to
only use aligned allocation functions when they are available.

Event Timeline

ldionne created this revision.Aug 6 2018, 11:53 AM
vsapsai added inline comments.Aug 7 2018, 3:28 PM
libcxx/include/__config
993

I think I'd rather keep __cpp_aligned_new >= 201606 check. I don't know about cases where the smaller value is possible, Clang always had 201606 as far as I (and SVN) know. But it seems to be safer and more correct.

Don't have objective arguments for keeping the check, so if you think it's not worth it, I trust your judgement.

libcxx/include/new
111–116

Maybe move this to __config too? This way we'll have __cpp_aligned_new-related macros together.

libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
11

Initially with_system_cxx_lib made me suspicious because macro _LIBCPP_HAS_NO_ALIGNED_ALLOCATION doesn't need specific dylib. And XFAIL: availability=macosx10.12 seems to be working.

Documentation describes which feature should be used in different cases but in this case I cannot definitely say if test uses unavailable feature. I think it is acceptable to stick with with_system_cxx_lib but I decided to brought to your attention the alternative.

ldionne updated this revision to Diff 159903.Aug 9 2018, 5:26 AM
ldionne marked an inline comment as done.

Address vsapsai's comments

ldionne added inline comments.Aug 9 2018, 5:26 AM
libcxx/include/new
111–116

The big difference is that _LIBCPP_HAS_NO_BUILTIN_ALIGNED_OPERATOR_NEW_DELETE is only used in <new>, whereas _LIBCPP_HAS_NO_ALIGNED_ALLOCATION was used in other files as well. Hence, I feel like it makes more sense to lift _LIBCPP_HAS_NO_ALIGNED_ALLOCATION into <__config>, but not _LIBCPP_HAS_NO_BUILTIN_ALIGNED_OPERATOR_NEW_DELETE .

ldionne marked an inline comment as done.Aug 9 2018, 5:28 AM
ldionne added inline comments.
libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
11

My understanding is that the availability feature may not be there if we're not using availability macros, since they can be disabled entirely.

vsapsai accepted this revision.Aug 9 2018, 11:54 AM
vsapsai added inline comments.
libcxx/include/new
111–116

Agree with your reasoning.

libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
11

availability feature will be present when tests are invoked with use_system_cxx_lib. I suspect in this case both with_system_cxx_lib and availability will work, so let's keep with_system_cxx_lib.

This revision is now accepted and ready to land.Aug 9 2018, 11:54 AM
This revision was automatically updated to reflect the committed changes.
ldionne marked an inline comment as done.