From 36be8fabb09764a080e69d37558dd8aa7b81526e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 11 Mar 2022 11:35:15 +0100 Subject: [PATCH] [Bitcode] Delete phi node on error These error conditions are checked after the phi node has been created, so we also need to delete it. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 59e2ae9625bf..767b5f548990 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -5197,8 +5197,10 @@ Error BitcodeReader::parseFunctionBody(Function *F) { // floating-point type. size_t NumArgs = (Record.size() - 1) / 2; PHINode *PN = PHINode::Create(Ty, NumArgs); - if ((Record.size() - 1) % 2 == 1 && !isa(PN)) + if ((Record.size() - 1) % 2 == 1 && !isa(PN)) { + PN->deleteValue(); return error("Invalid phi record"); + } InstructionList.push_back(PN); for (unsigned i = 0; i != NumArgs; i++) { @@ -5211,8 +5213,10 @@ Error BitcodeReader::parseFunctionBody(Function *F) { else V = getValue(Record, i * 2 + 1, NextValueNo, Ty, TyID); BasicBlock *BB = getBasicBlock(Record[i * 2 + 2]); - if (!V || !BB) + if (!V || !BB) { + PN->deleteValue(); return error("Invalid phi record"); + } PN->addIncoming(V, BB); } I = PN;