From 8cb0b6ca5bf1321d38f4602113b0f41c837d0586 Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Sat, 5 Feb 2022 01:00:37 -0500 Subject: Apply noundef attribute to &T, &mut T, Box, bool This doesn't handle `char` because it's a bit awkward to distinguish it from u32 at this point in codegen. Note that for some types (like `&Struct` and `&mut Struct`), we already apply `dereferenceable`, which implies `noundef`, so the IR does not change. --- compiler/rustc_codegen_llvm/src/abi.rs | 6 +++++- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_codegen_llvm/src') diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index e9b66b54c58..ff03df79ab1 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -37,7 +37,7 @@ impl ArgAttributeExt for ArgAttribute { where F: FnMut(llvm::Attribute), { - for_each_kind!(self, f, NoAlias, NoCapture, NonNull, ReadOnly, InReg) + for_each_kind!(self, f, NoAlias, NoCapture, NonNull, ReadOnly, InReg, NoUndef) } } @@ -69,7 +69,9 @@ impl ArgAttributesExt for ArgAttributes { } else { llvm::LLVMRustAddDereferenceableOrNullAttr(llfn, idx.as_uint(), deref); } + // dereferenceable implies nonnull noundef; dereferenceable_or_null implies noundef regular -= ArgAttribute::NonNull; + regular -= ArgAttribute::NoUndef; } if let Some(align) = self.pointee_align { llvm::LLVMRustAddAlignmentAttr(llfn, idx.as_uint(), align.bytes() as u32); @@ -109,7 +111,9 @@ impl ArgAttributesExt for ArgAttributes { deref, ); } + // dereferenceable implies nonnull noundef; dereferenceable_or_null implies noundef regular -= ArgAttribute::NonNull; + regular -= ArgAttribute::NoUndef; } if let Some(align) = self.pointee_align { llvm::LLVMRustAddAlignmentCallSiteAttr( diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 367c86a1dc9..4f62c685568 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -189,6 +189,7 @@ pub enum Attribute { StackProtectReq = 30, StackProtectStrong = 31, StackProtect = 32, + NoUndef = 33, } /// LLVMIntPredicate -- cgit 1.4.1-3-g733a5