[PATCH] D95095: [BuildLibcalls, Attrs] Support more variants of C++'s new, add attributes for C++'s delete

Richard Smith - zygoloid via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 4 14:10:31 PST 2021


rsmith added a comment.

Reverted in rG1484ad4137b5d627573672bad48b03785f8fdefd <https://reviews.llvm.org/rG1484ad4137b5d627573672bad48b03785f8fdefd>; pre-existing incorrect attribute logic for plain `operator new` removed in rGab243efb261ba7e27f4b14e1a6fbbff15a79c0bf <https://reviews.llvm.org/rGab243efb261ba7e27f4b14e1a6fbbff15a79c0bf>.

I think there are a few attributes we can meaningfully and correctly add to some calls to `operator new` / `operator delete`:

- `nonnull` can be added for all `operator new` functions that have a throwing exception specification, but only the frontend knows this, so this should be done by Clang.
- `noundef` can be added to all functions that return a pointer, in C++, but the frontend should do that.
- The `nothrow_t` variants can be marked `does_not_throw`, but they're declared `noexcept` so the frontend will do that itself anyway.
- For `builtin` calls to `operator delete`, we might be able to justify adding `inaccessiblemem_or_argmemonly` and/or `nocapture`, but I don't think either of those is justified by the standard rules. It's also unclear to me if `nocapture` is at all meaningful for a pointer that LLVM considers to have been deallocated by the callee. But this can't be done by the mechanism in this patch, as we can only add those attributes on `builtin` call sites, not to the `nobuiltin` declaration of the function.

So there might be some changes we can make in the frontend to add more attributes on `operator new` / `operator delete`, but it doesn't seem like there are any we can / should add here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95095/new/

https://reviews.llvm.org/D95095



More information about the llvm-commits mailing list