Skip to content

Commit

Permalink
add check for llvm 14
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdesjardins committed Feb 20, 2022
1 parent c2e84fa commit 067f628
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 067f628

Please sign in to comment.