add check for llvm 14

This commit is contained in:
Erik Desjardins 2022-02-20 11:37:22 -05:00
parent c2e84fa5fc
commit 067f628286

View file

@ -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 {