Auto merge of #109220 - nikic:poison, r=cuviper
Use poison instead of undef In cases where it is legal, we should prefer poison values over undef values. This replaces undef with poison for aggregate construction and for uninhabited types. There are more places where we can likely use poison, but I wanted to stay conservative to start with. In particular the aggregate case is important for newer LLVM versions, which are not able to handle an undef base value during early optimization due to poison-propagation concerns. r? `@cuviper`
This commit is contained in:
@@ -990,7 +990,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||
|
||||
fn resume(&mut self, exn0: &'ll Value, exn1: &'ll Value) {
|
||||
let ty = self.type_struct(&[self.type_i8p(), self.type_i32()], false);
|
||||
let mut exn = self.const_undef(ty);
|
||||
let mut exn = self.const_poison(ty);
|
||||
exn = self.insert_value(exn, exn0, 0);
|
||||
exn = self.insert_value(exn, exn1, 1);
|
||||
unsafe {
|
||||
|
||||
@@ -130,6 +130,10 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
unsafe { llvm::LLVMGetUndef(t) }
|
||||
}
|
||||
|
||||
fn const_poison(&self, t: &'ll Type) -> &'ll Value {
|
||||
unsafe { llvm::LLVMGetPoison(t) }
|
||||
}
|
||||
|
||||
fn const_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
|
||||
unsafe { llvm::LLVMConstInt(t, i as u64, True) }
|
||||
}
|
||||
|
||||
@@ -1069,6 +1069,7 @@ extern "C" {
|
||||
// Operations on constants of any type
|
||||
pub fn LLVMConstNull(Ty: &Type) -> &Value;
|
||||
pub fn LLVMGetUndef(Ty: &Type) -> &Value;
|
||||
pub fn LLVMGetPoison(Ty: &Type) -> &Value;
|
||||
|
||||
// Operations on metadata
|
||||
pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
|
||||
|
||||
Reference in New Issue
Block a user