mehdi_amini updated this revision to Diff 305279. mehdi_amini added a comment. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fix one clang instance failing this assertion Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D84293/new/ https://reviews.llvm.org/D84293 Files: clang/lib/CodeGen/CGBuiltin.cpp llvm/include/llvm/ADT/SmallVector.h llvm/include/llvm/MC/MCInst.h Index: llvm/include/llvm/MC/MCInst.h =================================================================== --- llvm/include/llvm/MC/MCInst.h +++ llvm/include/llvm/MC/MCInst.h @@ -181,7 +181,7 @@ MCOperand &getOperand(unsigned i) { return Operands[i]; } unsigned getNumOperands() const { return Operands.size(); } - void addOperand(const MCOperand &Op) { Operands.push_back(Op); } + void addOperand(const MCOperand Op) { Operands.push_back(Op); } using iterator = SmallVectorImpl<MCOperand>::iterator; using const_iterator = SmallVectorImpl<MCOperand>::const_iterator; Index: llvm/include/llvm/ADT/SmallVector.h =================================================================== --- llvm/include/llvm/ADT/SmallVector.h +++ llvm/include/llvm/ADT/SmallVector.h @@ -136,6 +136,13 @@ this->Size = this->Capacity = 0; // FIXME: Setting Capacity to 0 is suspect. } + void assertSafeToPush(const void *Elt) { + assert( + (Elt < begin() || Elt >= end() || this->size() < this->capacity()) && + "Attempting to push_back to the vector an element of the vector without" + " enough space reserved"); + } + public: using size_type = size_t; using difference_type = ptrdiff_t; @@ -251,6 +258,7 @@ public: void push_back(const T &Elt) { + this->assertSafeToPush(&Elt); if (LLVM_UNLIKELY(this->size() >= this->capacity())) this->grow(); ::new ((void*) this->end()) T(Elt); @@ -258,6 +266,7 @@ } void push_back(T &&Elt) { + this->assertSafeToPush(&Elt); if (LLVM_UNLIKELY(this->size() >= this->capacity())) this->grow(); ::new ((void*) this->end()) T(::std::move(Elt)); @@ -353,6 +362,7 @@ public: void push_back(const T &Elt) { + this->assertSafeToPush(&Elt); if (LLVM_UNLIKELY(this->size() >= this->capacity())) this->grow(); memcpy(reinterpret_cast<void *>(this->end()), &Elt, sizeof(T)); Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -10808,6 +10808,7 @@ } case NEON::BI__builtin_neon_vst3_v: case NEON::BI__builtin_neon_vst3q_v: { + Ops.reserve(Ops.size() + 1); Ops.push_back(Ops[0]); Ops.erase(Ops.begin()); llvm::Type *Tys[2] = { VTy, Ops[3]->getType() };
Index: llvm/include/llvm/MC/MCInst.h =================================================================== --- llvm/include/llvm/MC/MCInst.h +++ llvm/include/llvm/MC/MCInst.h @@ -181,7 +181,7 @@ MCOperand &getOperand(unsigned i) { return Operands[i]; } unsigned getNumOperands() const { return Operands.size(); } - void addOperand(const MCOperand &Op) { Operands.push_back(Op); } + void addOperand(const MCOperand Op) { Operands.push_back(Op); } using iterator = SmallVectorImpl<MCOperand>::iterator; using const_iterator = SmallVectorImpl<MCOperand>::const_iterator; Index: llvm/include/llvm/ADT/SmallVector.h =================================================================== --- llvm/include/llvm/ADT/SmallVector.h +++ llvm/include/llvm/ADT/SmallVector.h @@ -136,6 +136,13 @@ this->Size = this->Capacity = 0; // FIXME: Setting Capacity to 0 is suspect. } + void assertSafeToPush(const void *Elt) { + assert( + (Elt < begin() || Elt >= end() || this->size() < this->capacity()) && + "Attempting to push_back to the vector an element of the vector without" + " enough space reserved"); + } + public: using size_type = size_t; using difference_type = ptrdiff_t; @@ -251,6 +258,7 @@ public: void push_back(const T &Elt) { + this->assertSafeToPush(&Elt); if (LLVM_UNLIKELY(this->size() >= this->capacity())) this->grow(); ::new ((void*) this->end()) T(Elt); @@ -258,6 +266,7 @@ } void push_back(T &&Elt) { + this->assertSafeToPush(&Elt); if (LLVM_UNLIKELY(this->size() >= this->capacity())) this->grow(); ::new ((void*) this->end()) T(::std::move(Elt)); @@ -353,6 +362,7 @@ public: void push_back(const T &Elt) { + this->assertSafeToPush(&Elt); if (LLVM_UNLIKELY(this->size() >= this->capacity())) this->grow(); memcpy(reinterpret_cast<void *>(this->end()), &Elt, sizeof(T)); Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -10808,6 +10808,7 @@ } case NEON::BI__builtin_neon_vst3_v: case NEON::BI__builtin_neon_vst3q_v: { + Ops.reserve(Ops.size() + 1); Ops.push_back(Ops[0]); Ops.erase(Ops.begin()); llvm::Type *Tys[2] = { VTy, Ops[3]->getType() };
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits