1
Fork 0

Apply noundef metadata to loads of types that do not permit raw init

This matches the noundef attributes we apply on arguments/return types.
This commit is contained in:
Erik Desjardins 2022-02-12 14:01:33 -05:00
parent 3b1fe7e7c9
commit fec4335407
3 changed files with 98 additions and 4 deletions

View file

@ -479,6 +479,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
load: &'ll Value,
scalar: abi::Scalar,
) {
if !scalar.is_always_valid(bx) {
bx.noundef_metadata(load);
}
match scalar.value {
abi::Int(..) => {
if !scalar.is_always_valid(bx) {
@ -1215,6 +1219,16 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
}
}
fn noundef_metadata(&mut self, load: &'ll Value) {
unsafe {
llvm::LLVMSetMetadata(
load,
llvm::MD_noundef as c_uint,
llvm::LLVMMDNodeInContext(self.cx.llcx, ptr::null(), 0),
);
}
}
pub fn minnum(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
unsafe { llvm::LLVMRustBuildMinNum(self.llbuilder, lhs, rhs) }
}

View file

@ -442,6 +442,7 @@ pub enum MetadataType {
MD_mem_parallel_loop_access = 10,
MD_nonnull = 11,
MD_type = 19,
MD_noundef = 29,
}
/// LLVMRustAsmDialect