This is an archive of the discontinued LLVM Phabricator instance.

Generate warning when over-aligned new call is required but not supported.
AcceptedPublic

Authored by EricWF on Mar 28 2018, 7:37 PM.

Details

Summary

Currently libc++ silently ignores over-aligned allocation requests
made through __libcpp_allocate when aligned new/delete is not available.

This patch uses the diagnose_if attribute to generate a warning in that
case instead of being silent.

The change required converting __is_overaligned_for_new to a macro
so that the diagnose_if condition is still a potential constant expression in C++03.

Diff Detail

Event Timeline

EricWF created this revision.Mar 28 2018, 7:37 PM

Does it make sense to have a warning for __libcpp_deallocate and get_temporary_buffer too? Not sure about deallocate as you have allocated memory already and allocation has a warning. So for deallocation a warning can be too noisy. But for get_temporary_buffer the warning seems reasonable, unless I'm missing something.

Does it make sense to have a warning for __libcpp_deallocate and get_temporary_buffer too? Not sure about deallocate as you have allocated memory already and allocation has a warning. So for deallocation a warning can be too noisy. But for get_temporary_buffer the warning seems reasonable, unless I'm missing something.

get_temporary_buffer shouldn't return a temporary buffer when the request is over-aligned and aligned allocation isn't available; so I don't think we should warn on it.

vsapsai accepted this revision.Apr 2 2018, 3:54 PM

Does it make sense to have a warning for __libcpp_deallocate and get_temporary_buffer too? Not sure about deallocate as you have allocated memory already and allocation has a warning. So for deallocation a warning can be too noisy. But for get_temporary_buffer the warning seems reasonable, unless I'm missing something.

get_temporary_buffer shouldn't return a temporary buffer when the request is over-aligned and aligned allocation isn't available; so I don't think we should warn on it.

OK. Makes sense. We don't have data indicating it is a widespread issue that developers forget to address, so no need for the warning. Also get_temporary_buffer is deprecated in C++17, so there is not much value in investing into it.

Overall the change looks good to me, just a few minor NFC tweaks.

include/memory
2030

Is the indentation for these 2 ifs correct? They seem to be aligned with #if and not with while. Don't know if that is intentional.

include/new
235–239

Seems non-critical, maybe put __align in parentheses like (__align) > ...? But I don't know what is libc++ style regarding macro arguments.

This revision is now accepted and ready to land.Apr 2 2018, 3:54 PM