|
fn scalar_load_metadata<'a, 'll, 'tcx>( |
|
bx: &mut Builder<'a, 'll, 'tcx>, |
|
load: &'ll Value, |
|
scalar: abi::Scalar, |
|
) { |
|
match scalar.value { |
|
abi::Int(..) => { |
|
if !scalar.is_always_valid(bx) { |
|
bx.range_metadata(load, scalar.valid_range); |
|
} |
|
} |
|
abi::Pointer if !scalar.valid_range.contains(0) => { |
|
bx.nonnull_metadata(load); |
|
} |
|
_ => {} |
|
} |
|
} |
|
|
|
let val = if let Some(llextra) = place.llextra { |
|
OperandValue::Ref(place.llval, Some(llextra), place.align) |
|
} else if place.layout.is_llvm_immediate() { |
|
let mut const_llval = None; |
|
unsafe { |
|
if let Some(global) = llvm::LLVMIsAGlobalVariable(place.llval) { |
|
if llvm::LLVMIsGlobalConstant(global) == llvm::True { |
|
const_llval = llvm::LLVMGetInitializer(global); |
|
} |
|
} |
|
} |
|
let llval = const_llval.unwrap_or_else(|| { |
|
let load = self.load(place.layout.llvm_type(self), place.llval, place.align); |
|
if let abi::Abi::Scalar(scalar) = place.layout.abi { |
|
scalar_load_metadata(self, load, scalar); |
|
} |
|
load |
|
}); |
|
OperandValue::Immediate(self.to_immediate(llval, place.layout)) |
|
} else if let abi::Abi::ScalarPair(a, b) = place.layout.abi { |
|
let b_offset = a.value.size(self).align_to(b.value.align(self).abi); |
|
let pair_ty = place.layout.llvm_type(self); |
|
|
|
let mut load = |i, scalar: abi::Scalar, align| { |
|
let llptr = self.struct_gep(pair_ty, place.llval, i as u64); |
|
let llty = place.layout.scalar_pair_element_llvm_type(self, i, false); |
|
let load = self.load(llty, llptr, align); |
|
scalar_load_metadata(self, load, scalar); |
|
self.to_immediate_scalar(load, scalar) |
|
}; |
|
|
|
OperandValue::Pair( |
|
load(0, a, place.align), |
|
load(1, b, place.align.restrict_for_offset(b_offset)), |
|
) |
|
} else { |
|
OperandValue::Ref(place.llval, None, place.align) |
|
}; |
Latest LLVM issue for context (currently abandoned and may not be revived): https://reviews.llvm.org/D110745
dereferenceablecurrently means "dereferenceable everywhere", we avoid applyingdereferenceableattribute toBox:rust/compiler/rustc_middle/src/ty/layout.rs
Lines 3074 to 3080 in b8c56fa
!dereferenceablemetadata to loads, e.g. here:rust/compiler/rustc_codegen_llvm/src/builder.rs
Lines 476 to 531 in b8c56fa
@rustbot label A-llvm T-compiler S-blocked