[llvm-branch-commits] [llvm] 345fccc - Fix use-of-uninitialized-value in rG75f50e15bf8f

Zhengyang Liu via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 26 00:43:58 PST 2020


Author: Zhengyang Liu
Date: 2020-11-26T01:39:22-07:00
New Revision: 345fcccb33795600b9c159908c606c5027a4ce19

URL: https://github.com/llvm/llvm-project/commit/345fcccb33795600b9c159908c606c5027a4ce19
DIFF: https://github.com/llvm/llvm-project/commit/345fcccb33795600b9c159908c606c5027a4ce19.diff

LOG: Fix use-of-uninitialized-value in rG75f50e15bf8f

Differential Revision: https://reviews.llvm.org/D71126

Added: 
    

Modified: 
    llvm/lib/IR/Constants.cpp
    llvm/lib/IR/LLVMContextImpl.cpp
    llvm/lib/Transforms/Utils/FunctionComparator.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index f731021492bf..764d32e39b05 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -519,6 +519,9 @@ void llvm::deleteConstant(Constant *C) {
   case Constant::UndefValueVal:
     delete static_cast<UndefValue *>(C);
     break;
+  case Constant::PoisonValueVal:
+    delete static_cast<PoisonValue *>(C);
+    break;
   case Constant::ConstantExprVal:
     if (isa<UnaryConstantExpr>(C))
       delete static_cast<UnaryConstantExpr *>(C);
@@ -1722,7 +1725,12 @@ UndefValue *UndefValue::get(Type *Ty) {
 /// Remove the constant from the constant table.
 void UndefValue::destroyConstantImpl() {
   // Free the constant and any dangling references to it.
-  getContext().pImpl->UVConstants.erase(getType());
+  if (getValueID() == UndefValueVal) {
+    getContext().pImpl->UVConstants.erase(getType());
+  } else if (getValueID() == PoisonValueVal) {
+    getContext().pImpl->PVConstants.erase(getType());
+  }
+  llvm_unreachable("Not a undef or a poison!");
 }
 
 PoisonValue *PoisonValue::get(Type *Ty) {

diff  --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index c4f0a0ac8549..875c61cda423 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -97,6 +97,7 @@ LLVMContextImpl::~LLVMContextImpl() {
   CAZConstants.clear();
   CPNConstants.clear();
   UVConstants.clear();
+  PVConstants.clear();
   IntConstants.clear();
   FPConstants.clear();
   CDSConstants.clear();

diff  --git a/llvm/lib/Transforms/Utils/FunctionComparator.cpp b/llvm/lib/Transforms/Utils/FunctionComparator.cpp
index f25c4e5d6e99..2696557a719f 100644
--- a/llvm/lib/Transforms/Utils/FunctionComparator.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionComparator.cpp
@@ -291,6 +291,7 @@ int FunctionComparator::cmpConstants(const Constant *L,
 
   switch (L->getValueID()) {
   case Value::UndefValueVal:
+  case Value::PoisonValueVal:
   case Value::ConstantTokenNoneVal:
     return TypesRes;
   case Value::ConstantIntVal: {


        


More information about the llvm-branch-commits mailing list