Skip to content

Commit e785093

Browse files
authored
Merge pull request #450 from rust-lang/sync_from_rust_2024_02_20
Sync from rust 2024/02/20
2 parents 3e02db2 + e7b7c98 commit e785093

28 files changed

+166
-190
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_system/src/prepare.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,6 @@ where
159159
let repo_path = Path::new(crate::BUILD_DIR).join(&clone_result.repo_name);
160160
run_command(&[&"git", &"checkout", &"--", &"."], Some(&repo_path))?;
161161
run_command(&[&"git", &"checkout", &checkout_commit], Some(&repo_path))?;
162-
let filter = format!("-{}-", clone_result.repo_name);
163-
walk_dir(
164-
"patches/crate_patches",
165-
|_| Ok(()),
166-
|file_path| {
167-
let patch = file_path.as_os_str().to_str().unwrap();
168-
if patch.contains(&filter) && patch.ends_with(".patch") {
169-
run_command_with_output(
170-
&[&"git", &"am", &file_path.canonicalize().unwrap()],
171-
Some(&repo_path),
172-
)?;
173-
}
174-
Ok(())
175-
},
176-
)?;
177162
if let Some(extra) = extra {
178163
extra(&repo_path)?;
179164
}
@@ -238,7 +223,7 @@ pub fn run() -> Result<(), String> {
238223
let to_clone = &[
239224
(
240225
"https://github.com/rust-random/rand.git",
241-
"0f933f9c7176e53b2a3c7952ded484e1783f0bf1",
226+
"1f4507a8e1cf8050e4ceef95eeda8f64645b6719",
242227
None,
243228
),
244229
(

example/mini_core.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
thread_local
55
)]
66
#![no_core]
7-
#![allow(dead_code, internal_features)]
7+
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
88

99
#[no_mangle]
1010
unsafe extern "C" fn _Unwind_Resume() {
@@ -100,9 +100,6 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
100100
#[lang = "structural_peq"]
101101
pub trait StructuralPartialEq {}
102102

103-
#[lang = "structural_teq"]
104-
pub trait StructuralEq {}
105-
106103
#[lang = "not"]
107104
pub trait Not {
108105
type Output;

example/mini_core_hello_world.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ fn start<T: Termination + 'static>(
9898
}
9999

100100
static mut NUM: u8 = 6 * 7;
101+
102+
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
103+
#[allow(static_mut_refs)]
101104
static NUM_REF: &'static u8 = unsafe { &NUM };
102105

103106
macro_rules! assert {

example/std_example.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(internal_features)]
12
#![feature(core_intrinsics, coroutines, coroutine_trait, is_sorted)]
23

34
#[cfg(feature="master")]

patches/0022-core-Disable-not-compiling-tests.patch

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,4 @@ index 42a26ae..5ac1042 100644
3939
+#![cfg(test)]
4040
#![feature(alloc_layout_extra)]
4141
#![feature(array_chunks)]
42-
#![feature(array_methods)]
43-
--
44-
2.21.0 (Apple Git-122)
42+
#![feature(array_windows)]

patches/crate_patches/0002-rand-Disable-failing-test.patch

Lines changed: 0 additions & 32 deletions
This file was deleted.

patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,3 @@ index 5b21355..cb0c49b 100644
2121

2222
[dependencies]
2323
alloc = { path = "../alloc", public = true }
24-
diff --git a/library/test/Cargo.toml b/library/test/Cargo.toml
25-
index 91a1abd..a58c160 100644
26-
--- a/library/test/Cargo.toml
27-
+++ b/library/test/Cargo.toml
28-
@@ -4,7 +4,7 @@ version = "0.0.0"
29-
edition = "2021"
30-
31-
[lib]
32-
-crate-type = ["dylib", "rlib"]
33-
+crate-type = ["rlib"]
34-
35-
[dependencies]
36-
getopts = { version = "0.2.21", features = ['rustc-dep-of-std'] }
37-
--
38-
2.42.0
39-

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2023-11-17"
2+
channel = "nightly-2024-02-20"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn create_wrapper_function(
9090
.collect();
9191
let func = context.new_function(None, FunctionType::Exported, output.unwrap_or(void), &args, from_name, false);
9292

93-
if tcx.sess.target.options.default_hidden_visibility {
93+
if tcx.sess.default_hidden_visibility() {
9494
#[cfg(feature="master")]
9595
func.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden));
9696
}

src/asm.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ enum ConstraintOrRegister {
109109
impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
110110
fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_operands: &[InlineAsmOperandRef<'tcx, Self>], options: InlineAsmOptions, span: &[Span], instance: Instance<'_>, _dest_catch_funclet: Option<(Self::BasicBlock, Self::BasicBlock, Option<&Self::Funclet>)>) {
111111
if options.contains(InlineAsmOptions::MAY_UNWIND) {
112-
self.sess()
112+
self.sess().dcx()
113113
.create_err(UnwindingInlineAsm { span: span[0] })
114114
.emit();
115115
return;
@@ -634,6 +634,7 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
634634
}
635635
InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
636636
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
637+
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg_addr) => "a",
637638
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
638639
InlineAsmRegClass::Err => unreachable!(),
639640
}
@@ -704,7 +705,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
704705
InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
705706
bug!("LLVM backend does not support SPIR-V")
706707
},
707-
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(),
708+
InlineAsmRegClass::S390x(
709+
S390xInlineAsmRegClass::reg | S390xInlineAsmRegClass::reg_addr
710+
) => cx.type_i32(),
708711
InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(),
709712
InlineAsmRegClass::Err => unreachable!(),
710713
}

src/attributes.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
6262
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
6363
func.add_attribute(FnAttribute::Cold);
6464
}
65-
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_RETURNS_TWICE) {
66-
func.add_attribute(FnAttribute::ReturnsTwice);
67-
}
6865
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::FFI_PURE) {
6966
func.add_attribute(FnAttribute::Pure);
7067
}
@@ -80,7 +77,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
8077
let span = cx.tcx
8178
.get_attr(instance.def_id(), sym::target_feature)
8279
.map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span);
83-
cx.tcx.sess.create_err(TiedTargetFeatures {
80+
cx.tcx.dcx().create_err(TiedTargetFeatures {
8481
features: features.join(", "),
8582
span,
8683
})

src/back/lto.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
3030
use rustc_codegen_ssa::traits::*;
3131
use rustc_codegen_ssa::{looks_like_rust_object_file, ModuleCodegen, ModuleKind};
3232
use rustc_data_structures::memmap::Mmap;
33-
use rustc_errors::{FatalError, Handler};
33+
use rustc_errors::{FatalError, DiagCtxt};
3434
use rustc_hir::def_id::LOCAL_CRATE;
3535
use rustc_middle::dep_graph::WorkProduct;
3636
use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel};
@@ -61,7 +61,7 @@ struct LtoData {
6161
tmp_path: TempDir,
6262
}
6363

64-
fn prepare_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler) -> Result<LtoData, FatalError> {
64+
fn prepare_lto(cgcx: &CodegenContext<GccCodegenBackend>, dcx: &DiagCtxt) -> Result<LtoData, FatalError> {
6565
let export_threshold = match cgcx.lto {
6666
// We're just doing LTO for our one crate
6767
Lto::ThinLocal => SymbolExportLevel::Rust,
@@ -106,18 +106,18 @@ fn prepare_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler)
106106
// Make sure we actually can run LTO
107107
for crate_type in cgcx.crate_types.iter() {
108108
if !crate_type_allows_lto(*crate_type) {
109-
diag_handler.emit_err(LtoDisallowed);
109+
dcx.emit_err(LtoDisallowed);
110110
return Err(FatalError);
111111
} else if *crate_type == CrateType::Dylib {
112112
if !cgcx.opts.unstable_opts.dylib_lto {
113-
diag_handler.emit_err(LtoDylib);
113+
dcx.emit_err(LtoDylib);
114114
return Err(FatalError);
115115
}
116116
}
117117
}
118118

119119
if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto {
120-
diag_handler.emit_err(DynamicLinkingWithLTO);
120+
dcx.emit_err(DynamicLinkingWithLTO);
121121
return Err(FatalError);
122122
}
123123

@@ -154,7 +154,7 @@ fn prepare_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler)
154154
upstream_modules.push((module, CString::new(name).unwrap()));
155155
}
156156
Err(e) => {
157-
diag_handler.emit_err(e);
157+
dcx.emit_err(e);
158158
return Err(FatalError);
159159
}
160160
}
@@ -183,16 +183,16 @@ pub(crate) fn run_fat(
183183
modules: Vec<FatLtoInput<GccCodegenBackend>>,
184184
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
185185
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
186-
let diag_handler = cgcx.create_diag_handler();
187-
let lto_data = prepare_lto(cgcx, &diag_handler)?;
186+
let dcx = cgcx.create_dcx();
187+
let lto_data = prepare_lto(cgcx, &dcx)?;
188188
/*let symbols_below_threshold =
189189
lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
190-
fat_lto(cgcx, &diag_handler, modules, cached_modules, lto_data.upstream_modules, lto_data.tmp_path,
190+
fat_lto(cgcx, &dcx, modules, cached_modules, lto_data.upstream_modules, lto_data.tmp_path,
191191
//&symbols_below_threshold,
192192
)
193193
}
194194

195-
fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, _diag_handler: &Handler, modules: Vec<FatLtoInput<GccCodegenBackend>>, cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>, tmp_path: TempDir,
195+
fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, _dcx: &DiagCtxt, modules: Vec<FatLtoInput<GccCodegenBackend>>, cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>, mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>, tmp_path: TempDir,
196196
//symbols_below_threshold: &[*const libc::c_char],
197197
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
198198
let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module");
@@ -257,7 +257,7 @@ fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, _diag_handler: &Handler, mo
257257
let (buffer, name) = serialized_modules.remove(0);
258258
info!("no in-memory regular modules to choose from, parsing {:?}", name);
259259
ModuleCodegen {
260-
module_llvm: GccContext::parse(cgcx, &name, buffer.data(), diag_handler)?,
260+
module_llvm: GccContext::parse(cgcx, &name, buffer.data(), dcx)?,
261261
name: name.into_string().unwrap(),
262262
kind: ModuleKind::Regular,
263263
}*/

src/back/write.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gccjit::OutputKind;
44
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
55
use rustc_codegen_ssa::back::link::ensure_removed;
66
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
7-
use rustc_errors::Handler;
7+
use rustc_errors::DiagCtxt;
88
use rustc_fs_util::link_or_copy;
99
use rustc_session::config::OutputType;
1010
use rustc_span::fatal_error::FatalError;
@@ -13,7 +13,7 @@ use rustc_target::spec::SplitDebuginfo;
1313
use crate::{GccCodegenBackend, GccContext};
1414
use crate::errors::CopyBitcode;
1515

16-
pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler, module: ModuleCodegen<GccContext>, config: &ModuleConfig) -> Result<CompiledModule, FatalError> {
16+
pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, dcx: &DiagCtxt, module: ModuleCodegen<GccContext>, config: &ModuleConfig) -> Result<CompiledModule, FatalError> {
1717
let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name);
1818
{
1919
let context = &module.module_llvm.context;
@@ -128,12 +128,12 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
128128
EmitObj::Bitcode => {
129129
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
130130
if let Err(err) = link_or_copy(&bc_out, &obj_out) {
131-
diag_handler.emit_err(CopyBitcode { err });
131+
dcx.emit_err(CopyBitcode { err });
132132
}
133133

134134
if !config.emit_bc {
135135
debug!("removing_bitcode {:?}", bc_out);
136-
ensure_removed(diag_handler, &bc_out);
136+
ensure_removed(dcx, &bc_out);
137137
}
138138
}
139139

@@ -149,7 +149,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
149149
))
150150
}
151151

152-
pub(crate) fn link(_cgcx: &CodegenContext<GccCodegenBackend>, _diag_handler: &Handler, mut _modules: Vec<ModuleCodegen<GccContext>>) -> Result<ModuleCodegen<GccContext>, FatalError> {
152+
pub(crate) fn link(_cgcx: &CodegenContext<GccCodegenBackend>, _dcx: &DiagCtxt, mut _modules: Vec<ModuleCodegen<GccContext>>) -> Result<ModuleCodegen<GccContext>, FatalError> {
153153
unimplemented!();
154154
}
155155

src/builder.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13131313
}
13141314

13151315
// Atomic Operations
1316-
fn atomic_cmpxchg(&mut self, dst: RValue<'gcc>, cmp: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering, failure_order: AtomicOrdering, weak: bool) -> RValue<'gcc> {
1316+
fn atomic_cmpxchg(&mut self, dst: RValue<'gcc>, cmp: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering, failure_order: AtomicOrdering, weak: bool) -> (RValue<'gcc>, RValue<'gcc>) {
13171317
let expected = self.current_func().new_local(None, cmp.get_type(), "expected");
13181318
self.llbb().add_assignment(None, expected, cmp);
13191319
// NOTE: gcc doesn't support a failure memory model that is stronger than the success
@@ -1327,20 +1327,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13271327
};
13281328
let success = self.compare_exchange(dst, expected, src, order, failure_order, weak);
13291329

1330-
let pair_type = self.cx.type_struct(&[src.get_type(), self.bool_type], false);
1331-
let result = self.current_func().new_local(None, pair_type, "atomic_cmpxchg_result");
1332-
let align = Align::from_bits(64).expect("align"); // TODO(antoyo): use good align.
1330+
// NOTE: since success contains the call to the intrinsic, it must be added to the basic block before
1331+
// expected so that we store expected after the call.
1332+
let success_var = self.current_func().new_local(None, self.bool_type, "success");
1333+
self.llbb().add_assignment(None, success_var, success);
13331334

1334-
let value_type = result.to_rvalue().get_type();
1335-
if let Some(struct_type) = value_type.is_struct() {
1336-
self.store(success, result.access_field(None, struct_type.get_field(1)).get_address(None), align);
1337-
// NOTE: since success contains the call to the intrinsic, it must be stored before
1338-
// expected so that we store expected after the call.
1339-
self.store(expected.to_rvalue(), result.access_field(None, struct_type.get_field(0)).get_address(None), align);
1340-
}
1341-
// TODO(antoyo): handle when value is not a struct.
1342-
1343-
result.to_rvalue()
1335+
(expected.to_rvalue(), success_var.to_rvalue())
13441336
}
13451337

13461338
fn atomic_rmw(&mut self, op: AtomicRmwBinOp, dst: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering) -> RValue<'gcc> {

src/common.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
199199
}
200200
}
201201
Scalar::Ptr(ptr, _size) => {
202-
let (alloc_id, offset) = ptr.into_parts();
202+
let (prov, offset) = ptr.into_parts(); // we know the `offset` is relative
203+
let alloc_id = prov.alloc_id();
203204
let base_addr =
204205
match self.tcx.global_alloc(alloc_id) {
205206
GlobalAlloc::Memory(alloc) => {
@@ -376,9 +377,6 @@ pub trait TypeReflection<'gcc, 'tcx> {
376377
fn is_i128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
377378
fn is_u128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
378379

379-
fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
380-
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
381-
382380
fn is_vector(&self) -> bool;
383381
}
384382

@@ -463,14 +461,6 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
463461
self.unqualified() == cx.u128_type.unqualified()
464462
}
465463

466-
fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
467-
self.unqualified() == cx.context.new_type::<f32>()
468-
}
469-
470-
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
471-
self.unqualified() == cx.context.new_type::<f64>()
472-
}
473-
474464
fn is_vector(&self) -> bool {
475465
let mut typ = self.clone();
476466
loop {

0 commit comments

Comments
 (0)