Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fa724e5

Browse files
committed
Auto merge of rust-lang#130934 - matthiaskrgr:rollup-4puticr, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#129087 (Stabilize `option_get_or_insert_default`) - rust-lang#130435 (Move Apple linker args from `rustc_target` to `rustc_codegen_ssa`) - rust-lang#130459 (delete sub build directory "debug" to not delete the change-id file) - rust-lang#130873 (rustc_target: Add powerpc64 atomic-related features) - rust-lang#130916 (Use `&raw` in the compiler) - rust-lang#130917 (Fix error span if arg to `asm!()` is a macro call) - rust-lang#130927 (update outdated comments) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a3f76a2 + 966a0b7 commit fa724e5

File tree

21 files changed

+226
-159
lines changed

21 files changed

+226
-159
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ fn expand_preparsed_asm(
507507

508508
let msg = "asm template must be a string literal";
509509
let template_sp = template_expr.span;
510+
let template_is_mac_call = matches!(template_expr.kind, ast::ExprKind::MacCall(_));
510511
let (template_str, template_style, template_span) = {
511512
let ExpandResult::Ready(mac) = expr_to_spanned_string(ecx, template_expr, msg) else {
512513
return ExpandResult::Retry(());
@@ -596,7 +597,14 @@ fn expand_preparsed_asm(
596597

597598
if !parser.errors.is_empty() {
598599
let err = parser.errors.remove(0);
599-
let err_sp = template_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
600+
let err_sp = if template_is_mac_call {
601+
// If the template is a macro call we can't reliably point to the error's
602+
// span so just use the template's span as the error span (fixes #129503)
603+
template_span
604+
} else {
605+
template_span.from_inner(InnerSpan::new(err.span.start, err.span.end))
606+
};
607+
600608
let msg = format!("invalid asm template string: {}", err.description);
601609
let mut e = ecx.dcx().struct_span_err(err_sp, msg);
602610
e.span_label(err_sp, err.label + " in asm template string");

compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn get_llvm_object_symbols(
123123
llvm::LLVMRustGetSymbols(
124124
buf.as_ptr(),
125125
buf.len(),
126-
std::ptr::addr_of_mut!(*state) as *mut c_void,
126+
(&raw mut *state) as *mut c_void,
127127
callback,
128128
error_callback,
129129
)

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
167167
fn print_pass_timings(&self) {
168168
unsafe {
169169
let mut size = 0;
170-
let cstr = llvm::LLVMRustPrintPassTimings(std::ptr::addr_of_mut!(size));
170+
let cstr = llvm::LLVMRustPrintPassTimings(&raw mut size);
171171
if cstr.is_null() {
172172
println!("failed to get pass timings");
173173
} else {
@@ -180,7 +180,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
180180
fn print_statistics(&self) {
181181
unsafe {
182182
let mut size = 0;
183-
let cstr = llvm::LLVMRustPrintStatistics(std::ptr::addr_of_mut!(size));
183+
let cstr = llvm::LLVMRustPrintStatistics(&raw mut size);
184184
if cstr.is_null() {
185185
println!("failed to get pass stats");
186186
} else {

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ pub(crate) fn print(req: &PrintRequest, mut out: &mut String, sess: &Session) {
478478
&tm,
479479
cpu_cstring.as_ptr(),
480480
callback,
481-
std::ptr::addr_of_mut!(out) as *mut c_void,
481+
(&raw mut out) as *mut c_void,
482482
);
483483
}
484484
}

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_target::spec::crt_objects::CrtObjects;
4040
use rustc_target::spec::{
4141
Cc, LinkOutputKind, LinkSelfContainedComponents, LinkSelfContainedDefault, LinkerFeatures,
4242
LinkerFlavor, LinkerFlavorCli, Lld, PanicStrategy, RelocModel, RelroLevel, SanitizerSet,
43-
SplitDebuginfo,
43+
SplitDebuginfo, current_apple_deployment_target,
4444
};
4545
use tempfile::Builder as TempFileBuilder;
4646
use tracing::{debug, info, warn};
@@ -2405,6 +2405,8 @@ fn add_order_independent_options(
24052405
// Take care of the flavors and CLI options requesting the `lld` linker.
24062406
add_lld_args(cmd, sess, flavor, self_contained_components);
24072407

2408+
add_apple_link_args(cmd, sess, flavor);
2409+
24082410
let apple_sdk_root = add_apple_sdk(cmd, sess, flavor);
24092411

24102412
add_link_script(cmd, sess, tmpdir, crate_type);
@@ -2957,6 +2959,135 @@ pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool
29572959
}
29582960
}
29592961

2962+
/// We need to communicate four things to the linker on Apple/Darwin targets:
2963+
/// - The architecture.
2964+
/// - The operating system (and that it's an Apple platform).
2965+
/// - The deployment target.
2966+
/// - The environment / ABI.
2967+
fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
2968+
if !sess.target.is_like_osx {
2969+
return;
2970+
}
2971+
let LinkerFlavor::Darwin(cc, _) = flavor else {
2972+
return;
2973+
};
2974+
2975+
// `sess.target.arch` (`target_arch`) is not detailed enough.
2976+
let llvm_arch = sess.target.llvm_target.split_once('-').expect("LLVM target must have arch").0;
2977+
let target_os = &*sess.target.os;
2978+
let target_abi = &*sess.target.abi;
2979+
2980+
// The architecture name to forward to the linker.
2981+
//
2982+
// Supported architecture names can be found in the source:
2983+
// https://github.com/apple-oss-distributions/ld64/blob/ld64-951.9/src/abstraction/MachOFileAbstraction.hpp#L578-L648
2984+
//
2985+
// Intentially verbose to ensure that the list always matches correctly
2986+
// with the list in the source above.
2987+
let ld64_arch = match llvm_arch {
2988+
"armv7k" => "armv7k",
2989+
"armv7s" => "armv7s",
2990+
"arm64" => "arm64",
2991+
"arm64e" => "arm64e",
2992+
"arm64_32" => "arm64_32",
2993+
// ld64 doesn't understand i686, so fall back to i386 instead.
2994+
//
2995+
// Same story when linking with cc, since that ends up invoking ld64.
2996+
"i386" | "i686" => "i386",
2997+
"x86_64" => "x86_64",
2998+
"x86_64h" => "x86_64h",
2999+
_ => bug!("unsupported architecture in Apple target: {}", sess.target.llvm_target),
3000+
};
3001+
3002+
if cc == Cc::No {
3003+
// From the man page for ld64 (`man ld`):
3004+
// > The linker accepts universal (multiple-architecture) input files,
3005+
// > but always creates a "thin" (single-architecture), standard
3006+
// > Mach-O output file. The architecture for the output file is
3007+
// > specified using the -arch option.
3008+
//
3009+
// The linker has heuristics to determine the desired architecture,
3010+
// but to be safe, and to avoid a warning, we set the architecture
3011+
// explicitly.
3012+
cmd.link_args(&["-arch", ld64_arch]);
3013+
3014+
// Man page says that ld64 supports the following platform names:
3015+
// > - macos
3016+
// > - ios
3017+
// > - tvos
3018+
// > - watchos
3019+
// > - bridgeos
3020+
// > - visionos
3021+
// > - xros
3022+
// > - mac-catalyst
3023+
// > - ios-simulator
3024+
// > - tvos-simulator
3025+
// > - watchos-simulator
3026+
// > - visionos-simulator
3027+
// > - xros-simulator
3028+
// > - driverkit
3029+
let platform_name = match (target_os, target_abi) {
3030+
(os, "") => os,
3031+
("ios", "macabi") => "mac-catalyst",
3032+
("ios", "sim") => "ios-simulator",
3033+
("tvos", "sim") => "tvos-simulator",
3034+
("watchos", "sim") => "watchos-simulator",
3035+
("visionos", "sim") => "visionos-simulator",
3036+
_ => bug!("invalid OS/ABI combination for Apple target: {target_os}, {target_abi}"),
3037+
};
3038+
3039+
let (major, minor, patch) = current_apple_deployment_target(&sess.target);
3040+
let min_version = format!("{major}.{minor}.{patch}");
3041+
3042+
// Lie about the SDK version, we don't know it here
3043+
let sdk_version = &*min_version;
3044+
3045+
// From the man page for ld64 (`man ld`):
3046+
// > This is set to indicate the platform, oldest supported version of
3047+
// > that platform that output is to be used on, and the SDK that the
3048+
// > output was built against.
3049+
//
3050+
// Like with `-arch`, the linker can figure out the platform versions
3051+
// itself from the binaries being linked, but to be safe, we specify
3052+
// the desired versions here explicitly.
3053+
cmd.link_args(&["-platform_version", platform_name, &*min_version, sdk_version]);
3054+
} else {
3055+
// cc == Cc::Yes
3056+
// We'd _like_ to use `-target` everywhere, since that can uniquely
3057+
// communicate all the required details, but that doesn't work on GCC,
3058+
// and since we don't know whether the `cc` compiler is Clang, GCC, or
3059+
// something else, we fall back to other options that also work on GCC
3060+
// when compiling for macOS.
3061+
//
3062+
// Targets other than macOS are ill-supported by GCC (it doesn't even
3063+
// support e.g. `-miphoneos-version-min`), so in those cases we can
3064+
// fairly safely use `-target`. See also the following, where it is
3065+
// made explicit that the recommendation by LLVM developers is to use
3066+
// `-target`: <https://github.com/llvm/llvm-project/issues/88271>
3067+
if target_os == "macos" {
3068+
// `-arch` communicates the architecture.
3069+
//
3070+
// CC forwards the `-arch` to the linker, so we use the same value
3071+
// here intentionally.
3072+
cmd.cc_args(&["-arch", ld64_arch]);
3073+
3074+
// The presence of `-mmacosx-version-min` makes CC default to
3075+
// macOS, and it sets the deployment target.
3076+
let (major, minor, patch) = current_apple_deployment_target(&sess.target);
3077+
// Intentionally pass this as a single argument, Clang doesn't
3078+
// seem to like it otherwise.
3079+
cmd.cc_arg(&format!("-mmacosx-version-min={major}.{minor}.{patch}"));
3080+
3081+
// macOS has no environment, so with these two, we've told CC the
3082+
// four desired parameters.
3083+
//
3084+
// We avoid `-m32`/`-m64`, as this is already encoded by `-arch`.
3085+
} else {
3086+
cmd.cc_args(&["-target", &sess.target.llvm_target]);
3087+
}
3088+
}
3089+
}
3090+
29603091
fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) -> Option<PathBuf> {
29613092
let arch = &sess.target.arch;
29623093
let os = &sess.target.os;

compiler/rustc_data_structures/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<T> RwLock<T> {
437437
#[inline(always)]
438438
pub fn leak(&self) -> &T {
439439
let guard = self.read();
440-
let ret = unsafe { &*std::ptr::addr_of!(*guard) };
440+
let ret = unsafe { &*(&raw const *guard) };
441441
std::mem::forget(guard);
442442
ret
443443
}

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<'sess> OnDiskCache<'sess> {
233233

234234
for (index, file) in files.iter().enumerate() {
235235
let index = SourceFileIndex(index as u32);
236-
let file_ptr: *const SourceFile = std::ptr::addr_of!(**file);
236+
let file_ptr: *const SourceFile = &raw const **file;
237237
file_to_file_index.insert(file_ptr, index);
238238
let source_file_id = EncodedSourceFileId::new(tcx, file);
239239
file_index_to_stable_id.insert(index, source_file_id);
@@ -827,7 +827,7 @@ pub struct CacheEncoder<'a, 'tcx> {
827827
impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
828828
#[inline]
829829
fn source_file_index(&mut self, source_file: Lrc<SourceFile>) -> SourceFileIndex {
830-
self.file_to_file_index[&std::ptr::addr_of!(*source_file)]
830+
self.file_to_file_index[&(&raw const *source_file)]
831831
}
832832

833833
/// Encode something with additional information that allows to do some

compiler/rustc_middle/src/ty/list.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ impl<H, T> RawList<H, T> {
103103
let mem = arena.dropless.alloc_raw(layout) as *mut RawList<H, T>;
104104
unsafe {
105105
// Write the header
106-
ptr::addr_of_mut!((*mem).skel.header).write(header);
106+
(&raw mut (*mem).skel.header).write(header);
107107

108108
// Write the length
109-
ptr::addr_of_mut!((*mem).skel.len).write(slice.len());
109+
(&raw mut (*mem).skel.len).write(slice.len());
110110

111111
// Write the elements
112-
ptr::addr_of_mut!((*mem).skel.data)
112+
(&raw mut (*mem).skel.data)
113113
.cast::<T>()
114114
.copy_from_nonoverlapping(slice.as_ptr(), slice.len());
115115

@@ -160,7 +160,7 @@ macro_rules! impl_list_empty {
160160

161161
// SAFETY: `EMPTY` is sufficiently aligned to be an empty list for all
162162
// types with `align_of(T) <= align_of(MaxAlign)`, which we checked above.
163-
unsafe { &*(std::ptr::addr_of!(EMPTY) as *const RawList<$header_ty, T>) }
163+
unsafe { &*((&raw const EMPTY) as *const RawList<$header_ty, T>) }
164164
}
165165
}
166166
};
@@ -238,7 +238,7 @@ impl<H, T> Deref for RawList<H, T> {
238238
impl<H, T> AsRef<[T]> for RawList<H, T> {
239239
#[inline(always)]
240240
fn as_ref(&self) -> &[T] {
241-
let data_ptr = ptr::addr_of!(self.skel.data).cast::<T>();
241+
let data_ptr = (&raw const self.skel.data).cast::<T>();
242242
// SAFETY: `data_ptr` has the same provenance as `self` and can therefore
243243
// access the `self.skel.len` elements stored at `self.skel.data`.
244244
// Note that we specifically don't reborrow `&self.skel.data`, because that

compiler/rustc_session/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![feature(iter_intersperse)]
44
#![feature(let_chains)]
55
#![feature(map_many_mut)]
6-
#![feature(option_get_or_insert_default)]
76
#![feature(rustc_attrs)]
87
#![warn(unreachable_pub)]
98
// tidy-alphabetical-end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy