Skip to content

Commit 067f628

Browse files
add check for llvm 14
1 parent c2e84fa commit 067f628

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::base;
22
use crate::common::CodegenCx;
33
use crate::debuginfo;
44
use crate::llvm::{self, True};
5+
use crate::llvm_util;
56
use crate::type_::Type;
67
use crate::type_of::LayoutLlvmExt;
78
use crate::value::Value;
@@ -57,7 +58,13 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) ->
5758
// to avoid the cost of generating large complex const expressions.
5859
// For example, `[(u32, u8); 1024 * 1024]` contains uninit padding in each element,
5960
// and would result in `{ [5 x i8] zeroinitializer, [3 x i8] undef, ...repeat 1M times... }`.
60-
let max = cx.sess().opts.debugging_opts.uninit_const_chunk_threshold;
61+
let max = if llvm_util::get_version() < (14, 0, 0) {
62+
// Generating partially-uninit consts inhibits optimizations in LLVM < 14.
63+
// See https://github.com/rust-lang/rust/issues/84565.
64+
1
65+
} else {
66+
cx.sess().opts.debugging_opts.uninit_const_chunk_threshold
67+
};
6168
let allow_uninit_chunks = chunks.clone().take(max.saturating_add(1)).count() <= max;
6269

6370
if allow_uninit_chunks {

0 commit comments

Comments
 (0)