about summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Desjardins <erikdesjardins@users.noreply.github.com>2022-02-20 11:37:22 -0500
committerErik Desjardins <erikdesjardins@users.noreply.github.com>2022-02-20 11:37:22 -0500
commit067f628286216cd3a78524da28fab29bfb0f516a (patch)
tree9b3544381b8e5962212e76792a69691535912216
parentc2e84fa5fc4788a8bcb97fbcdc2fa78359e44121 (diff)
downloadrust-067f628286216cd3a78524da28fab29bfb0f516a.tar.gz
rust-067f628286216cd3a78524da28fab29bfb0f516a.zip
add check for llvm 14
-rw-r--r--compiler/rustc_codegen_llvm/src/consts.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs
index 14de6c5986a..9ab822f01f1 100644
--- a/compiler/rustc_codegen_llvm/src/consts.rs
+++ b/compiler/rustc_codegen_llvm/src/consts.rs
@@ -2,6 +2,7 @@ use crate::base;
 use crate::common::CodegenCx;
 use crate::debuginfo;
 use crate::llvm::{self, True};
+use crate::llvm_util;
 use crate::type_::Type;
 use crate::type_of::LayoutLlvmExt;
 use crate::value::Value;
@@ -57,7 +58,13 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) ->
         // to avoid the cost of generating large complex const expressions.
         // For example, `[(u32, u8); 1024 * 1024]` contains uninit padding in each element,
         // and would result in `{ [5 x i8] zeroinitializer, [3 x i8] undef, ...repeat 1M times... }`.
-        let max = cx.sess().opts.debugging_opts.uninit_const_chunk_threshold;
+        let max = if llvm_util::get_version() < (14, 0, 0) {
+            // Generating partially-uninit consts inhibits optimizations in LLVM < 14.
+            // See https://github.com/rust-lang/rust/issues/84565.
+            1
+        } else {
+            cx.sess().opts.debugging_opts.uninit_const_chunk_threshold
+        };
         let allow_uninit_chunks = chunks.clone().take(max.saturating_add(1)).count() <= max;
 
         if allow_uninit_chunks {