[llvm] 36be8fa - [Bitcode] Delete phi node on error

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 02:37:40 PST 2022


Author: Nikita Popov
Date: 2022-03-11T11:37:29+01:00
New Revision: 36be8fabb09764a080e69d37558dd8aa7b81526e

URL: https://github.com/llvm/llvm-project/commit/36be8fabb09764a080e69d37558dd8aa7b81526e
DIFF: https://github.com/llvm/llvm-project/commit/36be8fabb09764a080e69d37558dd8aa7b81526e.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 59e2ae9625bf1..767b5f548990f 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<FPMathOperator>(PN))
+      if ((Record.size() - 1) % 2 == 1 && !isa<FPMathOperator>(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;


        


More information about the llvm-commits mailing list