From fc6d4399dc9f765ba8a16a4954222fdb221fa389 Mon Sep 17 00:00:00 2001 From: Galaxy1458 <55453380+Galaxy1458@users.noreply.github.com> Date: Fri, 21 Apr 2023 11:37:42 +0800 Subject: [PATCH] remove some [-Wunused-parameter] warning (#53092) * test,test=develop * test,test=develop * test,test=develop * test,test=develop --- paddle/phi/core/kernel_registry.h | 2 +- paddle/utils/small_vector.h | 77 +++++++++++++++---------------- 2 files changed, 37 insertions(+), 42 deletions(-) diff --git a/paddle/phi/core/kernel_registry.h b/paddle/phi/core/kernel_registry.h index 9f45c23dac9..5d2ab27469a 100644 --- a/paddle/phi/core/kernel_registry.h +++ b/paddle/phi/core/kernel_registry.h @@ -474,7 +474,7 @@ struct KernelRegistrar { variadic_kernel_unfold_marco, \ __VA_ARGS__); \ void __PD_KERNEL_args_def_FN_##kernel_name##_##backend##_##layout( \ - const ::phi::KernelKey& kernel_key, ::phi::Kernel* kernel) + const ::phi::KernelKey& kernel_key UNUSED, ::phi::Kernel* kernel UNUSED) #else /** * `template decltype(fn) fn` can work on gcc and clang, diff --git a/paddle/utils/small_vector.h b/paddle/utils/small_vector.h index 5a8abdb4d23..0081832beed 100644 --- a/paddle/utils/small_vector.h +++ b/paddle/utils/small_vector.h @@ -1,3 +1,4 @@ +// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. // This file copy from llvm/ADT/SmallVector.h, version: 12.0.0 // Modified the following points // 1. remove macro @@ -47,11 +48,12 @@ class iterator_range { IteratorT begin_iterator, end_iterator; public: - // TODO: Add SFINAE to test that the Container's iterators match the range's + // TODO(others): Add SFINAE to test that the Container's iterators match the + // range's // iterators. template - iterator_range(Container &&c) - // TODO: Consider ADL/non-member begin/end calls. + explicit iterator_range(Container &&c) + // TODO(others): Consider ADL/non-member begin/end calls. : begin_iterator(c.begin()), end_iterator(c.end()) {} iterator_range(IteratorT begin_iterator, IteratorT end_iterator) : begin_iterator(std::move(begin_iterator)), @@ -102,7 +104,7 @@ class small_vector_base { /// This is a helper for \a grow() that's out of line to reduce code /// duplication. This function will report a fatal error if it can't grow at /// least to \p MinSize. - void *mallocForGrow(size_t MinSize, size_t TSize, size_t &NewCapacity); + void *mallocForGrow(size_t MinSize, size_t TSize, size_t *NewCapacity); /// This is an implementation of the grow() method which only works /// on POD-like data types and is out of line to reduce code duplication. @@ -162,7 +164,8 @@ class small_vector_template_common // Space after 'FirstEl' is clobbered, do not add any instance vars after it. protected: - small_vector_template_common(size_t Size) : Base(getFirstEl(), Size) {} + explicit small_vector_template_common(size_t Size) + : Base(getFirstEl(), Size) {} void grow_pod(size_t MinSize, size_t TSize) { Base::grow_pod(getFirstEl(), MinSize, TSize); @@ -217,6 +220,8 @@ class small_vector_template_common /// Check whether Elt will be invalidated by resizing the vector to NewSize. void assertSafeToReferenceAfterResize(const void *Elt, size_t NewSize) { + (void)Elt; + (void)NewSize; // just remove [-Wunused-paremeter] assert(isSafeToReferenceAfterResize(Elt, NewSize) && "Attempting to reference an element of the vector in an operation " "that invalidates it"); @@ -376,7 +381,7 @@ class small_vector_template_base : public small_vector_template_common { static constexpr bool TakesParamByValue = false; using ValueParamT = const T &; - small_vector_template_base(size_t Size) + explicit small_vector_template_base(size_t Size) : small_vector_template_common(Size) {} static void destroy_range(T *S, T *E) { @@ -408,7 +413,7 @@ class small_vector_template_base : public small_vector_template_common { /// Create a new allocation big enough for \p MinSize and pass back its size /// in \p NewCapacity. This is the first section of \a grow(). - T *mallocForGrow(size_t MinSize, size_t &NewCapacity) { + T *mallocForGrow(size_t MinSize, size_t *NewCapacity) { return static_cast( small_vector_base>::mallocForGrow( MinSize, sizeof(T), NewCapacity)); @@ -423,13 +428,7 @@ class small_vector_template_base : public small_vector_template_common { /// Reserve enough space to add one element, and return the updated element /// pointer in case it was a reference to the storage. - const T *reserveForParamAndGetAddress(const T &Elt, size_t N = 1) { - return this->reserveForParamAndGetAddressImpl(this, Elt, N); - } - - /// Reserve enough space to add one element, and return the updated element - /// pointer in case it was a reference to the storage. - T *reserveForParamAndGetAddress(T &Elt, size_t N = 1) { + T *reserveForParamAndGetAddress(const T &Elt, size_t N = 1) { return const_cast( this->reserveForParamAndGetAddressImpl(this, Elt, N)); } @@ -439,8 +438,8 @@ class small_vector_template_base : public small_vector_template_common { void growAndAssign(size_t NumElts, const T &Elt) { // Grow manually in case Elt is an internal reference. - size_t NewCapacity; - T *NewElts = mallocForGrow(NumElts, NewCapacity); + size_t NewCapacity = 0; + T *NewElts = mallocForGrow(NumElts, &NewCapacity); std::uninitialized_fill_n(NewElts, NumElts, Elt); this->destroy_range(this->begin(), this->end()); takeAllocationForGrow(NewElts, NewCapacity); @@ -450,9 +449,10 @@ class small_vector_template_base : public small_vector_template_common { template T &growAndEmplaceBack(ArgTypes &&...Args) { // Grow manually in case one of Args is an internal reference. - size_t NewCapacity; - T *NewElts = mallocForGrow(0, NewCapacity); - ::new ((void *)(NewElts + this->size())) T(std::forward(Args)...); + size_t NewCapacity = 0; + T *NewElts = mallocForGrow(0, &NewCapacity); + ::new (reinterpret_cast(NewElts + this->size())) + T(std::forward(Args)...); moveElementsForGrow(NewElts); takeAllocationForGrow(NewElts, NewCapacity); this->set_size(this->size() + 1); @@ -462,13 +462,13 @@ class small_vector_template_base : public small_vector_template_common { public: void push_back(const T &Elt) { const T *EltPtr = reserveForParamAndGetAddress(Elt); - ::new ((void *)this->end()) T(*EltPtr); + ::new (reinterpret_cast(this->end())) T(*EltPtr); this->set_size(this->size() + 1); } void push_back(T &&Elt) { T *EltPtr = reserveForParamAndGetAddress(Elt); - ::new ((void *)this->end()) T(::std::move(*EltPtr)); + ::new (reinterpret_cast(this->end())) T(::std::move(*EltPtr)); this->set_size(this->size() + 1); } @@ -481,8 +481,8 @@ class small_vector_template_base : public small_vector_template_common { // Define this out-of-line to dissuade the C++ compiler from inlining it. template void small_vector_template_base::grow(size_t MinSize) { - size_t NewCapacity; - T *NewElts = mallocForGrow(MinSize, NewCapacity); + size_t NewCapacity = 0; + T *NewElts = mallocForGrow(MinSize, &NewCapacity); moveElementsForGrow(NewElts); takeAllocationForGrow(NewElts, NewCapacity); } @@ -528,7 +528,7 @@ class small_vector_template_base using ValueParamT = typename std::conditional::type; - small_vector_template_base(size_t Size) + explicit small_vector_template_base(size_t Size) : small_vector_template_common(Size) {} // No need to do a destroy loop for POD's. @@ -572,13 +572,7 @@ class small_vector_template_base /// Reserve enough space to add one element, and return the updated element /// pointer in case it was a reference to the storage. - const T *reserveForParamAndGetAddress(const T &Elt, size_t N = 1) { - return this->reserveForParamAndGetAddressImpl(this, Elt, N); - } - - /// Reserve enough space to add one element, and return the updated element - /// pointer in case it was a reference to the storage. - T *reserveForParamAndGetAddress(T &Elt, size_t N = 1) { + T *reserveForParamAndGetAddress(const T &Elt, size_t N = 1) { return const_cast( this->reserveForParamAndGetAddressImpl(this, Elt, N)); } @@ -813,7 +807,7 @@ class small_vector_impl : public small_vector_template_base { this->reserveForParamAndGetAddress(Elt); I = this->begin() + Index; - ::new ((void *)this->end()) T(::std::move(this->back())); + ::new (reinterpret_cast(this->end())) T(::std::move(this->back())); // Push everything else over. std::move_backward(I, this->end() - 1, this->end()); this->set_size(this->size() + 1); @@ -973,7 +967,8 @@ class small_vector_impl : public small_vector_template_base { if (this->size() >= this->capacity()) return this->growAndEmplaceBack(std::forward(Args)...); - ::new ((void *)this->end()) T(std::forward(Args)...); + ::new (reinterpret_cast(this->end())) + T(std::forward(Args)...); this->set_size(this->size() + 1); return this->back(); } @@ -1276,7 +1271,7 @@ class small_vector : public small_vector_impl, small_vector_storage { if (!RHS.empty()) small_vector_impl::operator=(::std::move(RHS)); } - small_vector(small_vector_impl &&RHS) : small_vector_impl(N) { + explicit small_vector(small_vector_impl &&RHS) : small_vector_impl(N) { if (!RHS.empty()) small_vector_impl::operator=(::std::move(RHS)); } @@ -1349,14 +1344,14 @@ inline void *safe_realloc(void *Ptr, size_t Sz) { } // Check that no bytes are wasted and everything is well-aligned. -namespace { + struct Struct16B { alignas(16) void *X; }; struct Struct32B { alignas(32) void *X; }; -} // namespace + static_assert(sizeof(small_vector) == sizeof(unsigned) * 2 + sizeof(void *), "wasted space in small_vector size 0"); @@ -1399,7 +1394,7 @@ static void report_at_maximum_capacity(size_t MaxSize) { // Note: Moving this function into the header may cause performance regression. template -static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) { +static size_t getNewCapacity(size_t MinSize, size_t OldCapacity) { constexpr size_t MaxSize = (std::numeric_limits::max)(); // Ensure we can fit the new capacity. @@ -1422,9 +1417,9 @@ static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) { template void *small_vector_base::mallocForGrow(size_t MinSize, size_t TSize, - size_t &NewCapacity) { - NewCapacity = getNewCapacity(MinSize, TSize, this->capacity()); - return safe_malloc(NewCapacity * TSize); + size_t *NewCapacity) { + *NewCapacity = getNewCapacity(MinSize, this->capacity()); + return safe_malloc((*NewCapacity) * TSize); } // Note: Moving this function into the header may cause performance regression. @@ -1432,7 +1427,7 @@ template void small_vector_base::grow_pod(void *FirstEl, size_t MinSize, size_t TSize) { - size_t NewCapacity = getNewCapacity(MinSize, TSize, this->capacity()); + size_t NewCapacity = getNewCapacity(MinSize, this->capacity()); void *NewElts; if (BeginX == FirstEl) { NewElts = safe_malloc(NewCapacity * TSize); -- GitLab