[libcxx-commits] [PATCH] D136191: [libc++][PMR] Add attributes

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 18 11:40:49 PDT 2022


philnik created this revision.
philnik added reviewers: ldionne, Mordante, var-const.
Herald added a subscriber: krytarowski.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

This allows the compiler to do more optimizations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136191

Files:
  libcxx/include/__memory_resource/memory_resource.h
  libcxx/include/__memory_resource/unsynchronized_pool_resource.h


Index: libcxx/include/__memory_resource/unsynchronized_pool_resource.h
===================================================================
--- libcxx/include/__memory_resource/unsynchronized_pool_resource.h
+++ libcxx/include/__memory_resource/unsynchronized_pool_resource.h
@@ -75,11 +75,11 @@
 
   unsynchronized_pool_resource& operator=(const unsynchronized_pool_resource&) = delete;
 
-  _LIBCPP_AVAILABILITY_MEMORY_RESOURCE void release();
+  [[__gnu__::__pure__]] _LIBCPP_AVAILABILITY_MEMORY_RESOURCE void release();
 
   _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
 
-  _LIBCPP_AVAILABILITY_MEMORY_RESOURCE pool_options options() const;
+  [[__gnu__::__pure__]] _LIBCPP_AVAILABILITY_MEMORY_RESOURCE pool_options options() const;
 
 protected:
   _LIBCPP_AVAILABILITY_MEMORY_RESOURCE void* do_allocate(size_t __bytes, size_t __align) override; // key function
Index: libcxx/include/__memory_resource/memory_resource.h
===================================================================
--- libcxx/include/__memory_resource/memory_resource.h
+++ libcxx/include/__memory_resource/memory_resource.h
@@ -32,11 +32,13 @@
 public:
   virtual ~memory_resource() = default;
 
-  _LIBCPP_HIDE_FROM_ABI void* allocate(size_t __bytes, size_t __align = __max_align) {
+  [[using __gnu__: __returns_nonnull__, __alloc_size__(2), __alloc_align__(3)]] _LIBCPP_HIDE_FROM_ABI void*
+  allocate(size_t __bytes, size_t __align = __max_align) {
     return do_allocate(__bytes, __align);
   }
 
-  _LIBCPP_HIDE_FROM_ABI void deallocate(void* __p, size_t __bytes, size_t __align = __max_align) {
+  [[__gnu__::__nonnull__]] _LIBCPP_HIDE_FROM_ABI void
+  deallocate(void* __p, size_t __bytes, size_t __align = __max_align) {
     do_deallocate(__p, __bytes, __align);
   }
 
@@ -61,10 +63,14 @@
 
 // [mem.res.global]
 
-_LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource* get_default_resource() noexcept;
-_LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource* set_default_resource(memory_resource*) noexcept;
-_LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource* new_delete_resource() noexcept;
-_LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource* null_memory_resource() noexcept;
+[[using __gnu__: __returns_nonnull__, __pure__]] _LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource*
+get_default_resource() noexcept;
+[[using __gnu__: __returns_nonnull__, __pure__]] _LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource*
+set_default_resource(memory_resource*) noexcept;
+[[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource*
+new_delete_resource() noexcept;
+[[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_MEMORY_RESOURCE _LIBCPP_FUNC_VIS memory_resource*
+null_memory_resource() noexcept;
 
 } // namespace pmr
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136191.468638.patch
Type: text/x-patch
Size: 2940 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20221018/1cc5b659/attachment.bin>


More information about the libcxx-commits mailing list