[PATCH] D73380: [clang] Annotating C++'s `operator new` with more attributes

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 24 13:23:05 PST 2020


lebedev.ri created this revision.
lebedev.ri added reviewers: rsandifo, erichkeane, rjmccall, jdoerfert, eugenis.
lebedev.ri added a project: LLVM.
Herald added subscribers: atanasyan, jrtc27.
Herald added a project: clang.
lebedev.ri added a parent revision: D73020: [Sema] Perform call checking when building CXXNewExpr.
lebedev.ri edited reviewers, added: rsmith; removed: rsandifo.

Right now we annotate C++'s `operator new` with `noalias` attribute,
which very much is healthy for optimizations.

However as per `[basic.stc.dynamic.allocation]` <http://eel.is/c++draft/basic.stc.dynamic.allocation>,
there are more promises on global `operator new`, namely:

- non-`std::nothrow_t` `operator new` *never* returns `nullptr`
- global `operator new`-returned pointer is `__STDCPP_DEFAULT_NEW_ALIGNMENT__`-aligned
- If `std::align_val_t align` parameter is taken, the pointer will also be `align`-aligned

Supplying this information may not cause immediate landslide effects
on any specific benchmarks, but it for sure will be healthy for optimizer
in the sense that the IR will better reflect the guarantees provided in the source code.

The caveat is `-fno-assume-sane-operator-new`, which currently prevents emitting `noalias`
attribute, and is automatically passed by Sanitizers (PR16386 <https://bugs.llvm.org/show_bug.cgi?id=16386>) - should it also cover these attributes?
The problem is that the flag is back-end-specific, as seen in `test/Modules/explicit-build-flags.cpp`.
But while it is okay to add `noalias` metadata in backend, we really should be adding at least
the alignment metadata to the AST, since that allows us to perform sema checks on it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73380

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/Analysis/new-ctor-malloc.cpp
  clang/test/Analysis/new-ctor-null-throw.cpp
  clang/test/Analysis/new-ctor-null.cpp
  clang/test/CodeGenCXX/align-avx-complete-objects.cpp
  clang/test/CodeGenCXX/arm.cpp
  clang/test/CodeGenCXX/builtin-calling-conv.cpp
  clang/test/CodeGenCXX/builtin-is-constant-evaluated.cpp
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/dllexport.cpp
  clang/test/CodeGenCXX/dllimport.cpp
  clang/test/CodeGenCXX/exceptions.cpp
  clang/test/CodeGenCXX/goto.cpp
  clang/test/CodeGenCXX/microsoft-abi-array-cookies.cpp
  clang/test/CodeGenCXX/mips-size_t-ptrdiff_t.cpp
  clang/test/CodeGenCXX/multi-dim-operator-new.cpp
  clang/test/CodeGenCXX/new-alias.cpp
  clang/test/CodeGenCXX/new-array-init.cpp
  clang/test/CodeGenCXX/new-overflow.cpp
  clang/test/CodeGenCXX/new.cpp
  clang/test/CodeGenCXX/operator-new.cpp
  clang/test/CodeGenCXX/runtime-dllstorage.cpp
  clang/test/CodeGenCXX/static-init.cpp
  clang/test/CodeGenCoroutines/coro-alloc.cpp
  clang/test/CodeGenCoroutines/coro-cleanup.cpp
  clang/test/CodeGenCoroutines/coro-gro-nrvo.cpp
  clang/test/CodeGenCoroutines/coro-gro.cpp
  clang/test/CodeGenCoroutines/coro-return.cpp
  clang/test/CodeGenObjCXX/arc-new-delete.mm
  clang/test/CodeGenObjCXX/copy.mm
  clang/test/SemaCXX/builtin-operator-new-delete.cpp
  clang/test/SemaCXX/new-delete.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73380.240279.patch
Type: text/x-patch
Size: 72963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200124/5e821cc0/attachment-0001.bin>


More information about the cfe-commits mailing list