[libc] [flang] [clang-tools-extra] [clang] [libcxx] [llvm] [mlir] [compiler-rt] Make SmallVectorImpl destructor protected (PR #71439)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 6 12:03:37 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Andy Kaylor (andykaylor)
<details>
<summary>Changes</summary>
Because the SmallVectorImpl destructor is not virtual, the destructor of derived classes will not be called if pointers to the SmallVectorImpl class are deleted directly. Making the SmallVectorImpl destructor protected will prevent this.
---
Full diff: https://github.com/llvm/llvm-project/pull/71439.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/SmallVector.h (+3-3)
- (modified) mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp (+3-3)
``````````diff
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 53a107b1574c6a3..2e6d2dc6ce90a2c 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -601,9 +601,6 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
RHS.resetToSmall();
}
-public:
- SmallVectorImpl(const SmallVectorImpl &) = delete;
-
~SmallVectorImpl() {
// Subclass has already destructed this vector's elements.
// If this wasn't grown from the inline copy, deallocate the old space.
@@ -611,6 +608,9 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
free(this->begin());
}
+public:
+ SmallVectorImpl(const SmallVectorImpl &) = delete;
+
void clear() {
this->destroy_range(this->begin(), this->end());
this->Size = 0;
diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
index 5c288e977ad0f23..97b3b66eda00133 100644
--- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
@@ -95,7 +95,7 @@ class SerializeToHsacoPass
std::unique_ptr<std::vector<char>>
serializeISA(const std::string &isa) override;
- std::unique_ptr<SmallVectorImpl<char>> assembleIsa(const std::string &isa);
+ std::unique_ptr<SmallVector<char, 16>> assembleIsa(const std::string &isa);
std::unique_ptr<std::vector<char>>
createHsaco(const SmallVectorImpl<char> &isaBinary);
@@ -318,7 +318,7 @@ SerializeToHsacoPass::translateToLLVMIR(llvm::LLVMContext &llvmContext) {
return ret;
}
-std::unique_ptr<SmallVectorImpl<char>>
+std::unique_ptr<SmallVector<char, 16>>
SerializeToHsacoPass::assembleIsa(const std::string &isa) {
auto loc = getOperation().getLoc();
@@ -381,7 +381,7 @@ SerializeToHsacoPass::assembleIsa(const std::string &isa) {
parser->setTargetParser(*tap);
parser->Run(false);
- return std::make_unique<SmallVector<char, 0>>(std::move(result));
+ return std::make_unique<SmallVector<char, 16>>(std::move(result));
}
std::unique_ptr<std::vector<char>>
``````````
</details>
https://github.com/llvm/llvm-project/pull/71439
More information about the cfe-commits
mailing list