From 067f628286216cd3a78524da28fab29bfb0f516a Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Sun, 20 Feb 2022 11:37:22 -0500 Subject: [PATCH] add check for llvm 14 --- compiler/rustc_codegen_llvm/src/consts.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 14de6c5986a33..9ab822f01f1ec 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 {