Libc++'s default allocator uses __builtin_operator_new and __builtin_operator_delete in order to allow the calls to new/delete to be ellided. However, libc++ now needs to support over-aligned types in the default allocator. In order to support this without disabling the existing optimization Clang needs to support calling the aligned new overloads from the builtins.
See llvm.org/PR22634 for more information about the libc++ bug.
This patch changes __builtin_operator_new/__builtin_operator_delete to call any usual operator new/operator delete function. It does this by performing overload resolution with the arguments passed to the builtin to determine which allocation function to call. If the selected function is not a usual allocation function a diagnostic is issued.
One open issue is if the align_val_t overloads should be considered "usual" when LangOpts::AlignedAllocation is disabled.
In order to allow libc++ to detect this new behavior the value for __has_builtin(__builtin_operator_new) has been updated to 201802.
Can we leave this code alone and set the builtin expression's type to exactly match the type of the chosen function? I really don't want to be special-casing aligned allocation here. (This change should also cover sized delete and any future extensions to builtin operator new/delete.)