Skip to content

Commit b0170b6

Browse files
committed
Auto merge of #122365 - matthiaskrgr:rollup-4i350h6, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #115141 (Update Windows platform support) - #121865 (Add FileCheck annotations to MIR-opt unnamed-fields tests) - #122000 (Fix 32-bit overflows in LLVM composite constants) - #122194 (Enable creating backtraces via -Ztreat-err-as-bug when stashing errors) - #122319 (Don't ICE when non-self part of trait goal is constrained in new solver) - #122339 (Update books) - #122342 (Update /NODEFAUTLIB comment for msvc) - #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

Lines changed: 9 additions & 8 deletions
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

Lines changed: 8 additions & 13 deletions
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;

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'ll, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
233233
}
234234

235235
fn type_array(&self, ty: &'ll Type, len: u64) -> &'ll Type {
236-
unsafe { llvm::LLVMRustArrayType(ty, len) }
236+
unsafe { llvm::LLVMArrayType2(ty, len) }
237237
}
238238
}
239239

compiler/rustc_errors/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,13 +769,10 @@ impl DiagCtxt {
769769
format!("invalid level in `stash_diagnostic`: {:?}", diag.level),
770770
);
771771
}
772-
Error => {
773-
// This `unchecked_error_guaranteed` is valid. It is where the
774-
// `ErrorGuaranteed` for stashed errors originates. See
775-
// `DiagCtxtInner::drop`.
776-
#[allow(deprecated)]
777-
Some(ErrorGuaranteed::unchecked_error_guaranteed())
778-
}
772+
// We delay a bug here so that `-Ztreat-err-as-bug -Zeagerly-emit-delayed-bugs`
773+
// can be used to create a backtrace at the stashing site insted of whenever the
774+
// diagnostic context is dropped and thus delayed bugs are emitted.
775+
Error => Some(self.span_delayed_bug(span, "stashing {key:?}")),
779776
DelayedBug => return self.inner.borrow_mut().emit_diagnostic(diag),
780777
ForceWarning(_) | Warning | Note | OnceNote | Help | OnceHelp | FailureNote | Allow
781778
| Expect(_) => None,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/IR/IntrinsicsARM.h"
1111
#include "llvm/IR/LLVMRemarkStreamer.h"
1212
#include "llvm/IR/Mangler.h"
13+
#include "llvm/IR/Value.h"
1314
#include "llvm/Remarks/RemarkStreamer.h"
1415
#include "llvm/Remarks/RemarkSerializer.h"
1516
#include "llvm/Remarks/RemarkFormat.h"
@@ -1223,14 +1224,6 @@ extern "C" void LLVMRustWriteValueToString(LLVMValueRef V,
12231224
}
12241225
}
12251226

1226-
// LLVMArrayType function does not support 64-bit ElementCount
1227-
// FIXME: replace with LLVMArrayType2 when bumped minimal version to llvm-17
1228-
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
1229-
extern "C" LLVMTypeRef LLVMRustArrayType(LLVMTypeRef ElementTy,
1230-
uint64_t ElementCount) {
1231-
return wrap(ArrayType::get(unwrap(ElementTy), ElementCount));
1232-
}
1233-
12341227
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Twine, LLVMTwineRef)
12351228

12361229
extern "C" void LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef Str) {
@@ -2114,3 +2107,36 @@ extern "C" bool LLVMRustLLVMHasZlibCompressionForDebugSymbols() {
21142107
extern "C" bool LLVMRustLLVMHasZstdCompressionForDebugSymbols() {
21152108
return llvm::compression::zstd::isAvailable();
21162109
}
2110+
2111+
// Operations on composite constants.
2112+
// These are clones of LLVM api functions that will become available in future releases.
2113+
// They can be removed once Rust's minimum supported LLVM version supports them.
2114+
// See https://github.com/rust-lang/rust/issues/121868
2115+
// See https://llvm.org/doxygen/group__LLVMCCoreValueConstantComposite.html
2116+
2117+
// FIXME: Remove when Rust's minimum supported LLVM version reaches 19.
2118+
// https://github.com/llvm/llvm-project/commit/e1405e4f71c899420ebf8262d5e9745598419df8
2119+
#if LLVM_VERSION_LT(19, 0)
2120+
extern "C" LLVMValueRef LLVMConstStringInContext2(LLVMContextRef C,
2121+
const char *Str,
2122+
size_t Length,
2123+
bool DontNullTerminate) {
2124+
return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length), !DontNullTerminate));
2125+
}
2126+
#endif
2127+
2128+
// FIXME: Remove when Rust's minimum supported LLVM version reaches 17.
2129+
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
2130+
#if LLVM_VERSION_LT(17, 0)
2131+
extern "C" LLVMValueRef LLVMConstArray2(LLVMTypeRef ElementTy,
2132+
LLVMValueRef *ConstantVals,
2133+
uint64_t Length) {
2134+
ArrayRef<Constant *> V(unwrap<Constant>(ConstantVals, Length), Length);
2135+
return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
2136+
}
2137+
2138+
extern "C" LLVMTypeRef LLVMArrayType2(LLVMTypeRef ElementTy,
2139+
uint64_t ElementCount) {
2140+
return wrap(ArrayType::get(unwrap(ElementTy), ElementCount));
2141+
}
2142+
#endif

compiler/rustc_target/src/spec/base/windows_msvc.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ pub fn opts() -> TargetOptions {
1717
crt_static_allows_dylibs: true,
1818
crt_static_respected: true,
1919
requires_uwtable: true,
20-
// Currently we don't pass the /NODEFAULTLIB flag to the linker on MSVC
21-
// as there's been trouble in the past of linking the C++ standard
22-
// library required by LLVM. This likely needs to happen one day, but
23-
// in general Windows is also a more controlled environment than
24-
// Unix, so it's not necessarily as critical that this be implemented.
20+
// We don't pass the /NODEFAULTLIB flag to the linker on MSVC
21+
// as that prevents linker directives embedded in object files from
22+
// including other necessary libraries.
2523
//
26-
// Note that there are also some licensing worries about statically
27-
// linking some libraries which require a specific agreement, so it may
28-
// not ever be possible for us to pass this flag.
24+
// For example, msvcrt.lib embeds a linker directive like:
25+
// /DEFAULTLIB:vcruntime.lib /DEFAULTLIB:ucrt.lib
26+
// So that vcruntime.lib and ucrt.lib are included when the entry point
27+
// in msvcrt.lib is used. Using /NODEFAULTLIB would mean having to
28+
// manually add those two libraries and potentially further dependencies
29+
// they bring in.
30+
//
31+
// See also https://learn.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=msvc-170#lib
32+
// for documention on including library dependencies in C/C++ code.
2933
no_default_libraries: false,
3034
has_thread_local: true,
3135

compiler/rustc_target/src/spec/targets/i686_pc_windows_msvc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn target() -> Target {
2424
Target {
2525
llvm_target: "i686-pc-windows-msvc".into(),
2626
metadata: crate::spec::TargetMetadata {
27-
description: Some("32-bit MSVC (Windows 7+)".into()),
27+
description: Some("32-bit MSVC (Windows 10+)".into()),
2828
tier: Some(1),
2929
host_tools: Some(true),
3030
std: Some(true),

compiler/rustc_target/src/spec/targets/x86_64_pc_windows_msvc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn target() -> Target {
1111
Target {
1212
llvm_target: "x86_64-pc-windows-msvc".into(),
1313
metadata: crate::spec::TargetMetadata {
14-
description: Some("64-bit MSVC (Windows 7+)".into()),
14+
description: Some("64-bit MSVC (Windows 10+)".into()),
1515
tier: Some(1),
1616
host_tools: Some(true),
1717
std: Some(true),

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
274274

275275
let goal =
276276
goal.with(self.tcx(), goal.predicate.with_self_ty(self.tcx(), normalized_self_ty));
277-
debug_assert_eq!(goal, self.resolve_vars_if_possible(goal));
277+
// Vars that show up in the rest of the goal substs may have been constrained by
278+
// normalizing the self type as well, since type variables are not uniquified.
279+
let goal = self.resolve_vars_if_possible(goal);
278280

279281
let mut candidates = vec![];
280282

0 commit comments

Comments
 (0)