Skip to content

Commit b0170b6

Browse files
committedMar 12, 2024
Auto merge of rust-lang#122365 - matthiaskrgr:rollup-4i350h6, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#115141 (Update Windows platform support) - rust-lang#121865 (Add FileCheck annotations to MIR-opt unnamed-fields tests) - rust-lang#122000 (Fix 32-bit overflows in LLVM composite constants) - rust-lang#122194 (Enable creating backtraces via -Ztreat-err-as-bug when stashing errors) - rust-lang#122319 (Don't ICE when non-self part of trait goal is constrained in new solver) - rust-lang#122339 (Update books) - rust-lang#122342 (Update /NODEFAUTLIB comment for msvc) - rust-lang#122343 (Remove some unnecessary `allow(incomplete_features)` in the test suite) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0fa7fea + 39e0076 commit b0170b6

File tree

94 files changed

+396
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+396
-381
lines changed
 

‎compiler/rustc_codegen_llvm/src/common.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ impl<'ll> BackendTypes for CodegenCx<'ll, '_> {
9595

9696
impl<'ll> CodegenCx<'ll, '_> {
9797
pub fn const_array(&self, ty: &'ll Type, elts: &[&'ll Value]) -> &'ll Value {
98-
unsafe { llvm::LLVMConstArray(ty, elts.as_ptr(), elts.len() as c_uint) }
98+
let len = u64::try_from(elts.len()).expect("LLVMConstArray2 elements len overflow");
99+
unsafe { llvm::LLVMConstArray2(ty, elts.as_ptr(), len) }
99100
}
100101

101102
pub fn const_vector(&self, elts: &[&'ll Value]) -> &'ll Value {
102-
unsafe { llvm::LLVMConstVector(elts.as_ptr(), elts.len() as c_uint) }
103+
let len = c_uint::try_from(elts.len()).expect("LLVMConstVector elements len overflow");
104+
unsafe { llvm::LLVMConstVector(elts.as_ptr(), len) }
103105
}
104106

105107
pub fn const_bytes(&self, bytes: &[u8]) -> &'ll Value {
@@ -108,8 +110,8 @@ impl<'ll> CodegenCx<'ll, '_> {
108110

109111
pub fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value {
110112
unsafe {
111-
assert_eq!(idx as c_uint as u64, idx);
112-
let r = llvm::LLVMGetAggregateElement(v, idx as c_uint).unwrap();
113+
let idx = c_uint::try_from(idx).expect("LLVMGetAggregateElement index overflow");
114+
let r = llvm::LLVMGetAggregateElement(v, idx).unwrap();
113115

114116
debug!("const_get_elt(v={:?}, idx={}, r={:?})", v, idx, r);
115117

@@ -329,7 +331,7 @@ pub fn val_ty(v: &Value) -> &Type {
329331
pub fn bytes_in_context<'ll>(llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value {
330332
unsafe {
331333
let ptr = bytes.as_ptr() as *const c_char;
332-
llvm::LLVMConstStringInContext(llcx, ptr, bytes.len() as c_uint, True)
334+
llvm::LLVMConstStringInContext2(llcx, ptr, bytes.len(), True)
333335
}
334336
}
335337

@@ -338,9 +340,8 @@ pub fn struct_in_context<'ll>(
338340
elts: &[&'ll Value],
339341
packed: bool,
340342
) -> &'ll Value {
341-
unsafe {
342-
llvm::LLVMConstStructInContext(llcx, elts.as_ptr(), elts.len() as c_uint, packed as Bool)
343-
}
343+
let len = c_uint::try_from(elts.len()).expect("LLVMConstStructInContext elements len overflow");
344+
unsafe { llvm::LLVMConstStructInContext(llcx, elts.as_ptr(), len, packed as Bool) }
344345
}
345346

346347
#[inline]

‎compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,16 @@ extern "C" {
936936
pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
937937

938938
// Operations on composite constants
939-
pub fn LLVMConstStringInContext(
939+
pub fn LLVMConstArray2<'a>(
940+
ElementTy: &'a Type,
941+
ConstantVals: *const &'a Value,
942+
Length: u64,
943+
) -> &'a Value;
944+
pub fn LLVMArrayType2(ElementType: &Type, ElementCount: u64) -> &Type;
945+
pub fn LLVMConstStringInContext2(
940946
C: &Context,
941947
Str: *const c_char,
942-
Length: c_uint,
948+
Length: size_t,
943949
DontNullTerminate: Bool,
944950
) -> &Value;
945951
pub fn LLVMConstStructInContext<'a>(
@@ -948,14 +954,6 @@ extern "C" {
948954
Count: c_uint,
949955
Packed: Bool,
950956
) -> &'a Value;
951-
952-
// FIXME: replace with LLVMConstArray2 when bumped minimal version to llvm-17
953-
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
954-
pub fn LLVMConstArray<'a>(
955-
ElementTy: &'a Type,
956-
ConstantVals: *const &'a Value,
957-
Length: c_uint,
958-
) -> &'a Value;
959957
pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
960958

961959
// Constant expressions
@@ -1530,9 +1528,6 @@ extern "C" {
15301528
/// See llvm::LLVMTypeKind::getTypeID.
15311529
pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
15321530

1533-
// Operations on array, pointer, and vector types (sequence types)
1534-
pub fn LLVMRustArrayType(ElementType: &Type, ElementCount: u64) -> &Type;
1535-
15361531
// Operations on all values
15371532
pub fn LLVMRustGlobalAddMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
15381533
pub fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool;

0 commit comments

Comments
 (0)