[llvm-branch-commits] [llvm] 75f50e1 - Adding PoisonValue for representing poison value explicitly in IR

2020-11-25 Thread Zhengyang Liu via llvm-branch-commits

Author: Zhengyang Liu
Date: 2020-11-25T17:33:51-07:00
New Revision: 75f50e15bf8fff6fba1d4678adedd33ef6a945e5

URL: 
https://github.com/llvm/llvm-project/commit/75f50e15bf8fff6fba1d4678adedd33ef6a945e5
DIFF: 
https://github.com/llvm/llvm-project/commit/75f50e15bf8fff6fba1d4678adedd33ef6a945e5.diff

LOG: Adding PoisonValue for representing poison value explicitly in IR

Define ConstantData::PoisonValue.
Add support for poison value to LLLexer/LLParser/BitcodeReader/BitcodeWriter.
Add support for poison value to llvm-c interface.
Add support for poison value to OCaml binding.
Add m_Poison in PatternMatch.

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

Added: 
llvm/test/CodeGen/X86/poison-ops.ll

Modified: 
llvm/bindings/ocaml/llvm/llvm.ml
llvm/bindings/ocaml/llvm/llvm.mli
llvm/bindings/ocaml/llvm/llvm_ocaml.c
llvm/include/llvm-c/Core.h
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/PatternMatch.h
llvm/include/llvm/IR/Value.def
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/AsmParser/LLParser.h
llvm/lib/AsmParser/LLToken.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/Constants.cpp
llvm/lib/IR/Core.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/test/Bindings/OCaml/core.ml
llvm/test/Bitcode/compatibility.ll
llvm/tools/llvm-c-test/echo.cpp

Removed: 




diff  --git a/llvm/bindings/ocaml/llvm/llvm.ml 
b/llvm/bindings/ocaml/llvm/llvm.ml
index fdef6eb176d6..723ac66ffd05 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -314,6 +314,7 @@ module ValueKind = struct
   | GlobalIFunc
   | GlobalVariable
   | UndefValue
+  | PoisonValue
   | Instruction of Opcode.t
 end
 
@@ -547,8 +548,10 @@ external const_null : lltype -> llvalue = "LLVMConstNull"
 external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes"
 external const_pointer_null : lltype -> llvalue = "LLVMConstPointerNull"
 external undef : lltype -> llvalue = "LLVMGetUndef"
+external poison : lltype -> llvalue = "LLVMGetPoison"
 external is_null : llvalue -> bool = "llvm_is_null"
 external is_undef : llvalue -> bool = "llvm_is_undef"
+external is_poison : llvalue -> bool = "llvm_is_poison"
 external constexpr_opcode : llvalue -> Opcode.t = "llvm_constexpr_get_opcode"
 
 (*--... Operations on instructions 
.--*)

diff  --git a/llvm/bindings/ocaml/llvm/llvm.mli 
b/llvm/bindings/ocaml/llvm/llvm.mli
index 04e27438a479..ba9e6c1f2120 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -347,6 +347,7 @@ module ValueKind : sig
   | GlobalIFunc
   | GlobalVariable
   | UndefValue
+  | PoisonValue
   | Instruction of Opcode.t
 end
 
@@ -842,6 +843,10 @@ val const_pointer_null : lltype -> llvalue
 See the method [llvm::UndefValue::get]. *)
 val undef : lltype -> llvalue
 
+(** [poison ty] returns the poison value of the type [ty].
+See the method [llvm::PoisonValue::get]. *)
+val poison : lltype -> llvalue
+
 (** [is_null v] returns [true] if the value [v] is the null (zero) value.
 See the method [llvm::Constant::isNullValue]. *)
 val is_null : llvalue -> bool
@@ -850,6 +855,10 @@ val is_null : llvalue -> bool
 otherwise. Similar to [llvm::isa]. *)
 val is_undef : llvalue -> bool
 
+(** [is_poison v] returns [true] if the value [v] is a poison value, [false]
+otherwise. Similar to [llvm::isa]. *)
+val is_poison : llvalue -> bool
+
 (** [constexpr_opcode v] returns an [Opcode.t] corresponding to constexpr
 value [v], or [Opcode.Invalid] if [v] is not a constexpr. *)
 val constexpr_opcode : llvalue -> Opcode.t

diff  --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c 
b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 1552abf29c03..5845783278d9 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -627,6 +627,7 @@ enum ValueKind {
   GlobalIFunc,
   GlobalVariable,
   UndefValue,
+  PoisonValue,
   Instruction
 };
 
@@ -669,6 +670,7 @@ CAMLprim value llvm_classify_value(LLVMValueRef Val) {
   DEFINE_CASE(Val, MDNode);
   DEFINE_CASE(Val, MDString);
   DEFINE_CASE(Val, UndefValue);
+  DEFINE_CASE(Val, PoisonValue);
   failwith("Unknown Value class");
 }
 
@@ -762,6 +764,11 @@ CAMLprim value llvm_is_undef(LLVMValueRef Val) {
   return Val_bool(LLVMIsUndef(Val));
 }
 
+/* llvalue -> bool */
+CAMLprim value llvm_is_poison(LLVMValueRef Val) {
+  return Val_bool(LLVMIsPoison(Val));
+}
+
 /* llvalue -> Opcode.t */
 CAMLprim value llvm_constexpr_get_opcode(LLVMValueRef Val) {
   return LLVMIsAConstantExpr(Val) ?

diff  --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index e95038724276..1803c38b445d 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-

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

2020-11-26 Thread Zhengyang Liu via llvm-branch-commits

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(C);
 break;
+  case Constant::PoisonValueVal:
+delete static_cast(C);
+break;
   case Constant::ConstantExprVal:
 if (isa(C))
   delete static_cast(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: {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits