about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/builder.rs
diff options
context:
space:
mode:
authorErik Desjardins <erikdesjardins@users.noreply.github.com>2022-02-12 14:01:33 -0500
committerErik Desjardins <erikdesjardins@users.noreply.github.com>2022-02-27 12:16:16 -0500
commitfec4335407c9a292c524e07996ccd4d26c563548 (patch)
tree4af67f978ab9bb4689527c4f1048c2fcf4a8eb83 /compiler/rustc_codegen_llvm/src/builder.rs
parent3b1fe7e7c95e14dd8a420edf2f8a160c70211e04 (diff)
downloadrust-fec4335407c9a292c524e07996ccd4d26c563548.tar.gz
rust-fec4335407c9a292c524e07996ccd4d26c563548.zip
Apply noundef metadata to loads of types that do not permit raw init
This matches the noundef attributes we apply on arguments/return types.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/builder.rs')
-rw-r--r--compiler/rustc_codegen_llvm/src/builder.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs
index 5e78d6fc851..77aaa3010f2 100644
--- a/compiler/rustc_codegen_llvm/src/builder.rs
+++ b/compiler/rustc_codegen_llvm/src/builder.rs
@@ -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) }
     }