Skip to content

Commit 56c6a2f

Browse files
committed
Auto merge of #132586 - workingjubilee:rollup-qrmn49a, r=workingjubilee
Rollup of 4 pull requests Successful merges: - #131222 (Generate correct symbols.o for sparc-unknown-none-elf) - #132423 (remove const-support for align_offset and is_aligned) - #132565 (Reduce dependence on the target name) - #132576 (remove attribute ids from hir stats (they're simply not needed)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 706eec8 + 759e80d commit 56c6a2f

File tree

26 files changed

+286
-1151
lines changed

26 files changed

+286
-1151
lines changed

compiler/rustc_codegen_gcc/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
146146

147147
// Wasm statics with custom link sections get special treatment as they
148148
// go into custom sections of the wasm executable.
149-
if self.tcx.sess.opts.target_triple.tuple().starts_with("wasm32") {
149+
if self.tcx.sess.target.is_like_wasm {
150150
if let Some(_section) = attrs.link_section {
151151
unimplemented!();
152152
}

compiler/rustc_codegen_llvm/src/back/write.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -945,23 +945,10 @@ fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data:
945945
asm
946946
}
947947

948-
fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
949-
let triple = cgcx.opts.target_triple.tuple();
950-
triple.contains("-ios")
951-
|| triple.contains("-darwin")
952-
|| triple.contains("-tvos")
953-
|| triple.contains("-watchos")
954-
|| triple.contains("-visionos")
955-
}
956-
957-
fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
958-
cgcx.opts.target_triple.tuple().contains("-aix")
959-
}
960-
961948
pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) -> &'static CStr {
962-
if target_is_apple(cgcx) {
949+
if cgcx.target_is_like_osx {
963950
c"__LLVM,__bitcode"
964-
} else if target_is_aix(cgcx) {
951+
} else if cgcx.target_is_like_aix {
965952
c".ipa"
966953
} else {
967954
c".llvmbc"
@@ -1028,10 +1015,12 @@ unsafe fn embed_bitcode(
10281015
// Unfortunately, LLVM provides no way to set custom section flags. For ELF
10291016
// and COFF we emit the sections using module level inline assembly for that
10301017
// reason (see issue #90326 for historical background).
1031-
let is_aix = target_is_aix(cgcx);
1032-
let is_apple = target_is_apple(cgcx);
10331018
unsafe {
1034-
if is_apple || is_aix || cgcx.opts.target_triple.tuple().starts_with("wasm") {
1019+
if cgcx.target_is_like_osx
1020+
|| cgcx.target_is_like_aix
1021+
|| cgcx.target_arch == "wasm32"
1022+
|| cgcx.target_arch == "wasm64"
1023+
{
10351024
// We don't need custom section flags, create LLVM globals.
10361025
let llconst = common::bytes_in_context(llcx, bitcode);
10371026
let llglobal = llvm::LLVMAddGlobal(
@@ -1052,9 +1041,9 @@ unsafe fn embed_bitcode(
10521041
c"rustc.embedded.cmdline".as_ptr(),
10531042
);
10541043
llvm::LLVMSetInitializer(llglobal, llconst);
1055-
let section = if is_apple {
1044+
let section = if cgcx.target_is_like_osx {
10561045
c"__LLVM,__cmdline"
1057-
} else if is_aix {
1046+
} else if cgcx.target_is_like_aix {
10581047
c".info"
10591048
} else {
10601049
c".llvmcmd"

compiler/rustc_codegen_ssa/src/back/link.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ pub fn link_binary(
8585
}
8686

8787
if invalid_output_for_target(sess, crate_type) {
88-
bug!(
89-
"invalid output type `{:?}` for target os `{}`",
90-
crate_type,
91-
sess.opts.target_triple
92-
);
88+
bug!("invalid output type `{:?}` for target `{}`", crate_type, sess.opts.target_triple);
9389
}
9490

9591
sess.time("link_binary_check_files_are_writeable", || {
@@ -996,6 +992,7 @@ fn link_natively(
996992
&& (code < 1000 || code > 9999)
997993
{
998994
let is_vs_installed = windows_registry::find_vs_version().is_ok();
995+
// FIXME(cc-rs#1265) pass only target arch to find_tool()
999996
let has_linker = windows_registry::find_tool(
1000997
sess.opts.target_triple.tuple(),
1001998
"link.exe",

compiler/rustc_codegen_ssa/src/back/linker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub(crate) fn get_linker<'a>(
4747
self_contained: bool,
4848
target_cpu: &'a str,
4949
) -> Box<dyn Linker + 'a> {
50+
// FIXME(cc-rs#1265) pass only target arch to find_tool()
5051
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe");
5152

5253
// If our linker looks like a batch script on Windows then to execute this

compiler/rustc_codegen_ssa/src/back/metadata.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,15 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
211211
"powerpc64" => (Architecture::PowerPc64, None),
212212
"riscv32" => (Architecture::Riscv32, None),
213213
"riscv64" => (Architecture::Riscv64, None),
214-
"sparc" => (Architecture::Sparc32Plus, None),
214+
"sparc" => {
215+
if sess.target.options.cpu == "v9" {
216+
// Target uses V8+, aka EM_SPARC32PLUS, aka 64-bit V9 but in 32-bit mode
217+
(Architecture::Sparc32Plus, None)
218+
} else {
219+
// Target uses V7 or V8, aka EM_SPARC
220+
(Architecture::Sparc, None)
221+
}
222+
}
215223
"sparc64" => (Architecture::Sparc64, None),
216224
"avr" => (Architecture::Avr, None),
217225
"msp430" => (Architecture::Msp430, None),

compiler/rustc_codegen_ssa/src/back/write.rs

+4
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ pub struct CodegenContext<B: WriteBackendMethods> {
345345
pub is_pe_coff: bool,
346346
pub target_can_use_split_dwarf: bool,
347347
pub target_arch: String,
348+
pub target_is_like_osx: bool,
349+
pub target_is_like_aix: bool,
348350
pub split_debuginfo: rustc_target::spec::SplitDebuginfo,
349351
pub split_dwarf_kind: rustc_session::config::SplitDwarfKind,
350352

@@ -1195,6 +1197,8 @@ fn start_executing_work<B: ExtraBackendMethods>(
11951197
is_pe_coff: tcx.sess.target.is_like_windows,
11961198
target_can_use_split_dwarf: tcx.sess.target_can_use_split_dwarf(),
11971199
target_arch: tcx.sess.target.arch.to_string(),
1200+
target_is_like_osx: tcx.sess.target.is_like_osx,
1201+
target_is_like_aix: tcx.sess.target.is_like_aix,
11981202
split_debuginfo: tcx.sess.split_debuginfo(),
11991203
split_dwarf_kind: tcx.sess.opts.unstable_opts.split_dwarf_kind,
12001204
parallel: backend.supports_parallel() && !sess.opts.unstable_opts.no_parallel_backend,

compiler/rustc_const_eval/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
const_eval_address_space_full =
22
there are no more free addresses in the address space
33
4-
const_eval_align_offset_invalid_align =
5-
`align_offset` called with non-power-of-two align: {$target_align}
6-
74
const_eval_alignment_check_failed =
85
{$msg ->
96
[AccessedPtr] accessing memory

compiler/rustc_const_eval/src/const_eval/machine.rs

+6-82
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::borrow::{Borrow, Cow};
22
use std::fmt;
33
use std::hash::Hash;
4-
use std::ops::ControlFlow;
54

65
use rustc_abi::{Align, ExternAbi, Size};
76
use rustc_ast::Mutability;
@@ -10,7 +9,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
109
use rustc_hir::{self as hir, CRATE_HIR_ID, LangItem};
1110
use rustc_middle::mir::AssertMessage;
1211
use rustc_middle::query::TyCtxtAt;
13-
use rustc_middle::ty::layout::{FnAbiOf, TyAndLayout};
12+
use rustc_middle::ty::layout::TyAndLayout;
1413
use rustc_middle::ty::{self, Ty, TyCtxt};
1514
use rustc_middle::{bug, mir};
1615
use rustc_span::Span;
@@ -22,9 +21,9 @@ use crate::errors::{LongRunning, LongRunningWarn};
2221
use crate::fluent_generated as fluent;
2322
use crate::interpret::{
2423
self, AllocId, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame, GlobalAlloc, ImmTy,
25-
InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, PointerArithmetic, RangeSet, Scalar,
26-
StackPopCleanup, compile_time_machine, interp_ok, throw_exhaust, throw_inval, throw_ub,
27-
throw_ub_custom, throw_unsup, throw_unsup_format,
24+
InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, RangeSet, Scalar, compile_time_machine,
25+
interp_ok, throw_exhaust, throw_inval, throw_ub, throw_ub_custom, throw_unsup,
26+
throw_unsup_format,
2827
};
2928

3029
/// When hitting this many interpreted terminators we emit a deny by default lint
@@ -226,8 +225,8 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
226225
&mut self,
227226
instance: ty::Instance<'tcx>,
228227
args: &[FnArg<'tcx>],
229-
dest: &MPlaceTy<'tcx>,
230-
ret: Option<mir::BasicBlock>,
228+
_dest: &MPlaceTy<'tcx>,
229+
_ret: Option<mir::BasicBlock>,
231230
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
232231
let def_id = instance.def_id();
233232

@@ -259,85 +258,10 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
259258
);
260259

261260
return interp_ok(Some(new_instance));
262-
} else if self.tcx.is_lang_item(def_id, LangItem::AlignOffset) {
263-
let args = self.copy_fn_args(args);
264-
// For align_offset, we replace the function call if the pointer has no address.
265-
match self.align_offset(instance, &args, dest, ret)? {
266-
ControlFlow::Continue(()) => return interp_ok(Some(instance)),
267-
ControlFlow::Break(()) => return interp_ok(None),
268-
}
269261
}
270262
interp_ok(Some(instance))
271263
}
272264

273-
/// `align_offset(ptr, target_align)` needs special handling in const eval, because the pointer
274-
/// may not have an address.
275-
///
276-
/// If `ptr` does have a known address, then we return `Continue(())` and the function call should
277-
/// proceed as normal.
278-
///
279-
/// If `ptr` doesn't have an address, but its underlying allocation's alignment is at most
280-
/// `target_align`, then we call the function again with an dummy address relative to the
281-
/// allocation.
282-
///
283-
/// If `ptr` doesn't have an address and `target_align` is stricter than the underlying
284-
/// allocation's alignment, then we return `usize::MAX` immediately.
285-
fn align_offset(
286-
&mut self,
287-
instance: ty::Instance<'tcx>,
288-
args: &[OpTy<'tcx>],
289-
dest: &MPlaceTy<'tcx>,
290-
ret: Option<mir::BasicBlock>,
291-
) -> InterpResult<'tcx, ControlFlow<()>> {
292-
assert_eq!(args.len(), 2);
293-
294-
let ptr = self.read_pointer(&args[0])?;
295-
let target_align = self.read_scalar(&args[1])?.to_target_usize(self)?;
296-
297-
if !target_align.is_power_of_two() {
298-
throw_ub_custom!(
299-
fluent::const_eval_align_offset_invalid_align,
300-
target_align = target_align,
301-
);
302-
}
303-
304-
match self.ptr_try_get_alloc_id(ptr, 0) {
305-
Ok((alloc_id, offset, _extra)) => {
306-
let (_size, alloc_align, _kind) = self.get_alloc_info(alloc_id);
307-
308-
if target_align <= alloc_align.bytes() {
309-
// Extract the address relative to the allocation base that is definitely
310-
// sufficiently aligned and call `align_offset` again.
311-
let addr = ImmTy::from_uint(offset.bytes(), args[0].layout).into();
312-
let align = ImmTy::from_uint(target_align, args[1].layout).into();
313-
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?;
314-
315-
// Push the stack frame with our own adjusted arguments.
316-
self.init_stack_frame(
317-
instance,
318-
self.load_mir(instance.def, None)?,
319-
fn_abi,
320-
&[FnArg::Copy(addr), FnArg::Copy(align)],
321-
/* with_caller_location = */ false,
322-
dest,
323-
StackPopCleanup::Goto { ret, unwind: mir::UnwindAction::Unreachable },
324-
)?;
325-
interp_ok(ControlFlow::Break(()))
326-
} else {
327-
// Not alignable in const, return `usize::MAX`.
328-
let usize_max = Scalar::from_target_usize(self.target_usize_max(), self);
329-
self.write_scalar(usize_max, dest)?;
330-
self.return_to_block(ret)?;
331-
interp_ok(ControlFlow::Break(()))
332-
}
333-
}
334-
Err(_addr) => {
335-
// The pointer has an address, continue with function call.
336-
interp_ok(ControlFlow::Continue(()))
337-
}
338-
}
339-
}
340-
341265
/// See documentation on the `ptr_guaranteed_cmp` intrinsic.
342266
fn guaranteed_cmp(&mut self, a: Scalar, b: Scalar) -> InterpResult<'tcx, u8> {
343267
interp_ok(match (a, b) {

compiler/rustc_hir/src/lang_items.rs

-3
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,6 @@ language_item_table! {
348348

349349
MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None;
350350

351-
/// Align offset for stride != 1; must not panic.
352-
AlignOffset, sym::align_offset, align_offset_fn, Target::Fn, GenericRequirement::None;
353-
354351
Termination, sym::termination, termination, Target::Trait, GenericRequirement::None;
355352

356353
Try, sym::Try, try_trait, Target::Trait, GenericRequirement::None;

0 commit comments

Comments
 (0)