[PATCH] D43047: [Builtins] Overload __builtin_operator_new/delete to accept an optional alignment parameter.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 7 14:48:54 PST 2018


EricWF created this revision.
EricWF added reviewers: rsmith, majnemer, aaron.ballman, erik.pilkington, bogner, ahatanak.

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 allow passing an optional alignment parameter. The two parameter overloads will forward to the aligned versions of `operator new` and `operator delete`.

Additionally, libc++ needs a way to detect these new overloads. There seems to be no great way to do this. This patch chooses to add the feature check `has_aligned_builtin_operator_new`. Suggestions on how to better handle this case are very welcome!


https://reviews.llvm.org/D43047

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Lex/PPMacroExpansion.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGenCXX/new.cpp
  test/Lexer/has_feature_aligned_builtin_new.cpp
  test/SemaCXX/builtin-operator-new-delete-alignment-disabled.cpp
  test/SemaCXX/builtin-operator-new-delete.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43047.133314.patch
Type: text/x-patch
Size: 16124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180207/ffe9c20d/attachment-0001.bin>


More information about the cfe-commits mailing list