diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-06-24 15:54:21 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-06-30 12:37:53 -0700 |
commit | 15440191b57237eafb18600ac653b9a0023db391 (patch) | |
tree | 56d33b57ff84da3653e156c67c8030a2512cd31f /llvm/lib/IR/Constants.cpp | |
parent | 1ccc49924aeb7bb5fbd2eb956243d16db3a02b08 (diff) | |
download | llvm-15440191b57237eafb18600ac653b9a0023db391.zip llvm-15440191b57237eafb18600ac653b9a0023db391.tar.gz llvm-15440191b57237eafb18600ac653b9a0023db391.tar.bz2 |
[IR] Delete llvm::Constants using the correct type.
In most cases, this doesn't have much impact: the destructors just call
the base class destructor anyway. A few subclasses of ConstantExpr
actually store non-trivial data, though. Make sure we clean up
appropriately.
This is sort of ugly, but I don't see a good alternative given the
constraints.
Issue found by asan buildbots running the testcase for D80330.
Differential Revision: https://reviews.llvm.org/D82509
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 1afd73d..d8e044e 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -463,7 +463,74 @@ void Constant::destroyConstant() { } // Value has no outstanding references it is safe to delete it now... - delete this; + deleteConstant(this); +} + +void llvm::deleteConstant(Constant *C) { + switch (C->getValueID()) { + case Constant::ConstantIntVal: + delete static_cast<ConstantInt *>(C); + break; + case Constant::ConstantFPVal: + delete static_cast<ConstantFP *>(C); + break; + case Constant::ConstantAggregateZeroVal: + delete static_cast<ConstantAggregateZero *>(C); + break; + case Constant::ConstantArrayVal: + delete static_cast<ConstantArray *>(C); + break; + case Constant::ConstantStructVal: + delete static_cast<ConstantStruct *>(C); + break; + case Constant::ConstantVectorVal: + delete static_cast<ConstantVector *>(C); + break; + case Constant::ConstantPointerNullVal: + delete static_cast<ConstantPointerNull *>(C); + break; + case Constant::ConstantDataArrayVal: + delete static_cast<ConstantDataArray *>(C); + break; + case Constant::ConstantDataVectorVal: + delete static_cast<ConstantDataVector *>(C); + break; + case Constant::ConstantTokenNoneVal: + delete static_cast<ConstantTokenNone *>(C); + break; + case Constant::BlockAddressVal: + delete static_cast<BlockAddress *>(C); + break; + case Constant::UndefValueVal: + delete static_cast<UndefValue *>(C); + break; + case Constant::ConstantExprVal: + if (isa<UnaryConstantExpr>(C)) + delete static_cast<UnaryConstantExpr *>(C); + else if (isa<BinaryConstantExpr>(C)) + delete static_cast<BinaryConstantExpr *>(C); + else if (isa<SelectConstantExpr>(C)) + delete static_cast<SelectConstantExpr *>(C); + else if (isa<ExtractElementConstantExpr>(C)) + delete static_cast<ExtractElementConstantExpr *>(C); + else if (isa<InsertElementConstantExpr>(C)) + delete static_cast<InsertElementConstantExpr *>(C); + else if (isa<ShuffleVectorConstantExpr>(C)) + delete static_cast<ShuffleVectorConstantExpr *>(C); + else if (isa<ExtractValueConstantExpr>(C)) + delete static_cast<ExtractValueConstantExpr *>(C); + else if (isa<InsertValueConstantExpr>(C)) + delete static_cast<InsertValueConstantExpr *>(C); + else if (isa<GetElementPtrConstantExpr>(C)) + delete static_cast<GetElementPtrConstantExpr *>(C); + else if (isa<CompareConstantExpr>(C)) + delete static_cast<CompareConstantExpr *>(C); + else + llvm_unreachable("Unexpected constant expr"); + break; + default: + llvm_unreachable("Unexpected constant"); + } } static bool canTrapImpl(const Constant *C, |