about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
diff options
context:
space:
mode:
authorErik Desjardins <erikdesjardins@users.noreply.github.com>2021-04-27 00:15:41 -0400
committerErik Desjardins <erikdesjardins@users.noreply.github.com>2021-08-25 17:49:28 -0400
commit5e81d643d93e3a1316464b9c83c90ee26098ee7c (patch)
tree24ed175dcaed6dc61516f5101def21a3ade9ecd0 /compiler/rustc_codegen_llvm
parent4d635fdf63f1ba3480c30a6ea1e6f3e49a39b738 (diff)
downloadrust-5e81d643d93e3a1316464b9c83c90ee26098ee7c.tar.gz
rust-5e81d643d93e3a1316464b9c83c90ee26098ee7c.zip
don't generate partially-undef consts
Diffstat (limited to 'compiler/rustc_codegen_llvm')
-rw-r--r--compiler/rustc_codegen_llvm/src/consts.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs
index 901fa9fb047..3ece1659b9e 100644
--- a/compiler/rustc_codegen_llvm/src/consts.rs
+++ b/compiler/rustc_codegen_llvm/src/consts.rs
@@ -36,11 +36,6 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
         alloc: &'a Allocation,
         range: Range<usize>,
     ) {
-        /// Allocations larger than this will only be codegen'd as entirely initialized or entirely undef.
-        /// This avoids compile time regressions when an alloc would have many chunks,
-        /// e.g. for `[(u64, u8); N]`, which has undef padding in each element.
-        const MAX_PARTIALLY_UNDEF_SIZE: usize = 1024;
-
         let mut chunks = alloc
             .init_mask()
             .range_as_init_chunks(Size::from_bytes(range.start), Size::from_bytes(range.end));
@@ -57,21 +52,30 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
             }
         };
 
-        if range.len() > MAX_PARTIALLY_UNDEF_SIZE {
+        // Generating partially-uninit consts inhibits optimizations, so it is disabled by default.
+        // See https://github.com/rust-lang/rust/issues/84565.
+        let allow_partially_uninit =
+            match cx.sess().opts.debugging_opts.partially_uninit_const_threshold {
+                Some(max) => range.len() <= max,
+                None => false,
+            };
+
+        if allow_partially_uninit {
+            llvals.extend(chunks.map(chunk_to_llval));
+        } else {
             let llval = match (chunks.next(), chunks.next()) {
                 (Some(chunk), None) => {
                     // exactly one chunk, either fully init or fully uninit
                     chunk_to_llval(chunk)
                 }
                 _ => {
-                    // partially uninit
+                    // partially uninit, codegen as if it was initialized
+                    // (using some arbitrary value for uninit bytes)
                     let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range);
                     cx.const_bytes(bytes)
                 }
             };
             llvals.push(llval);
-        } else {
-            llvals.extend(chunks.map(chunk_to_llval));
         }
     }