Skip to content

Commit b70baa4

Browse files
committed
Auto merge of rust-lang#105703 - matthiaskrgr:rollup-tfpeam2, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#105399 (Use more LFS functions.) - rust-lang#105578 (Fix transmutes between pointers in different address spaces (e.g. fn ptrs on AVR)) - rust-lang#105598 (explain mem::forget(env_lock) in fork/exec) - rust-lang#105624 (Fix unsoundness in bootstrap cache code) - rust-lang#105630 (Add a test for rust-lang#92481) - rust-lang#105684 (Improve rustdoc markdown variable naming) - rust-lang#105697 (Remove fee1-dead from reviewers) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fbf8b93 + 3069bc0 commit b70baa4

File tree

13 files changed

+150
-26
lines changed

13 files changed

+150
-26
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1802,15 +1802,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
18021802
match (src.layout.abi, dst.layout.abi) {
18031803
(abi::Abi::Scalar(src_scalar), abi::Abi::Scalar(dst_scalar)) => {
18041804
// HACK(eddyb) LLVM doesn't like `bitcast`s between pointers and non-pointers.
1805-
if (src_scalar.primitive() == abi::Pointer)
1806-
== (dst_scalar.primitive() == abi::Pointer)
1807-
{
1805+
let src_is_ptr = src_scalar.primitive() == abi::Pointer;
1806+
let dst_is_ptr = dst_scalar.primitive() == abi::Pointer;
1807+
if src_is_ptr == dst_is_ptr {
18081808
assert_eq!(src.layout.size, dst.layout.size);
18091809

18101810
// NOTE(eddyb) the `from_immediate` and `to_immediate_scalar`
18111811
// conversions allow handling `bool`s the same as `u8`s.
18121812
let src = bx.from_immediate(src.immediate());
1813-
let src_as_dst = bx.bitcast(src, bx.backend_type(dst.layout));
1813+
// LLVM also doesn't like `bitcast`s between pointers in different address spaces.
1814+
let src_as_dst = if src_is_ptr {
1815+
bx.pointercast(src, bx.backend_type(dst.layout))
1816+
} else {
1817+
bx.bitcast(src, bx.backend_type(dst.layout))
1818+
};
18141819
Immediate(bx.to_immediate_scalar(src_as_dst, dst_scalar)).store(bx, dst);
18151820
return;
18161821
}

library/std/src/sys/unix/fs.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1759,8 +1759,13 @@ mod remove_dir_impl {
17591759
use crate::sys::common::small_c_string::run_path_with_cstr;
17601760
use crate::sys::{cvt, cvt_r};
17611761

1762-
#[cfg(not(all(target_os = "macos", not(target_arch = "aarch64")),))]
1762+
#[cfg(not(any(
1763+
target_os = "linux",
1764+
all(target_os = "macos", not(target_arch = "aarch64"))
1765+
)))]
17631766
use libc::{fdopendir, openat, unlinkat};
1767+
#[cfg(target_os = "linux")]
1768+
use libc::{fdopendir, openat64 as openat, unlinkat};
17641769
#[cfg(all(target_os = "macos", not(target_arch = "aarch64")))]
17651770
use macos_weak::{fdopendir, openat, unlinkat};
17661771

library/std/src/sys/unix/kernel_copy.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ use crate::ptr;
6161
use crate::sync::atomic::{AtomicBool, AtomicU8, Ordering};
6262
use crate::sys::cvt;
6363
use crate::sys::weak::syscall;
64+
#[cfg(not(target_os = "linux"))]
65+
use libc::sendfile as sendfile64;
66+
#[cfg(target_os = "linux")]
67+
use libc::sendfile64;
6468
use libc::{EBADF, EINVAL, ENOSYS, EOPNOTSUPP, EOVERFLOW, EPERM, EXDEV};
6569

6670
#[cfg(test)]
@@ -647,7 +651,7 @@ fn sendfile_splice(mode: SpliceMode, reader: RawFd, writer: RawFd, len: u64) ->
647651

648652
let result = match mode {
649653
SpliceMode::Sendfile => {
650-
cvt(unsafe { libc::sendfile(writer, reader, ptr::null_mut(), chunk_size) })
654+
cvt(unsafe { sendfile64(writer, reader, ptr::null_mut(), chunk_size) })
651655
}
652656
SpliceMode::Splice => cvt(unsafe {
653657
splice(reader, ptr::null_mut(), writer, ptr::null_mut(), chunk_size, 0)

library/std/src/sys/unix/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
9595
)))]
9696
'poll: {
9797
use crate::sys::os::errno;
98+
#[cfg(not(target_os = "linux"))]
99+
use libc::open as open64;
100+
#[cfg(target_os = "linux")]
101+
use libc::open64;
98102
let pfds: &mut [_] = &mut [
99103
libc::pollfd { fd: 0, events: 0, revents: 0 },
100104
libc::pollfd { fd: 1, events: 0, revents: 0 },
@@ -116,7 +120,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
116120
if pfd.revents & libc::POLLNVAL == 0 {
117121
continue;
118122
}
119-
if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
123+
if open64("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
120124
// If the stream is closed but we failed to reopen it, abort the
121125
// process. Otherwise we wouldn't preserve the safety of
122126
// operations on the corresponding Rust object Stdin, Stdout, or
@@ -139,9 +143,13 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
139143
)))]
140144
{
141145
use crate::sys::os::errno;
146+
#[cfg(not(target_os = "linux"))]
147+
use libc::open as open64;
148+
#[cfg(target_os = "linux")]
149+
use libc::open64;
142150
for fd in 0..3 {
143151
if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
144-
if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
152+
if open64("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
145153
// If the stream is closed but we failed to reopen it, abort the
146154
// process. Otherwise we wouldn't preserve the safety of
147155
// operations on the corresponding Rust object Stdin, Stdout, or

library/std/src/sys/unix/process/process_unix.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ impl Command {
6666
//
6767
// Note that as soon as we're done with the fork there's no need to hold
6868
// a lock any more because the parent won't do anything and the child is
69-
// in its own process. Thus the parent drops the lock guard while the child
70-
// forgets it to avoid unlocking it on a new thread, which would be invalid.
69+
// in its own process. Thus the parent drops the lock guard immediately.
70+
// The child calls `mem::forget` to leak the lock, which is crucial because
71+
// releasing a lock is not async-signal-safe.
7172
let env_lock = sys::os::env_read_lock();
7273
let (pid, pidfd) = unsafe { self.do_fork()? };
7374

7475
if pid == 0 {
7576
crate::panic::always_abort();
76-
mem::forget(env_lock);
77+
mem::forget(env_lock); // avoid non-async-signal-safe unlocking
7778
drop(input);
7879
let Err(err) = unsafe { self.do_exec(theirs, envp.as_ref()) };
7980
let errno = err.raw_os_error().unwrap_or(libc::EINVAL) as u32;

library/std/src/sys/unix/stack_overflow.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ mod imp {
4545
use crate::thread;
4646

4747
use libc::MAP_FAILED;
48-
use libc::{mmap, munmap};
48+
#[cfg(not(target_os = "linux"))]
49+
use libc::{mmap as mmap64, munmap};
50+
#[cfg(target_os = "linux")]
51+
use libc::{mmap64, munmap};
4952
use libc::{sigaction, sighandler_t, SA_ONSTACK, SA_SIGINFO, SIGBUS, SIG_DFL};
5053
use libc::{sigaltstack, SIGSTKSZ, SS_DISABLE};
5154
use libc::{MAP_ANON, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE, SIGSEGV};
@@ -135,7 +138,7 @@ mod imp {
135138
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "linux",)))]
136139
let flags = MAP_PRIVATE | MAP_ANON;
137140
let stackp =
138-
mmap(ptr::null_mut(), SIGSTKSZ + page_size(), PROT_READ | PROT_WRITE, flags, -1, 0);
141+
mmap64(ptr::null_mut(), SIGSTKSZ + page_size(), PROT_READ | PROT_WRITE, flags, -1, 0);
139142
if stackp == MAP_FAILED {
140143
panic!("failed to allocate an alternative stack: {}", io::Error::last_os_error());
141144
}

library/std/src/sys/unix/thread.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,10 @@ pub mod guard {
653653
))]
654654
#[cfg_attr(test, allow(dead_code))]
655655
pub mod guard {
656-
use libc::{mmap, mprotect};
656+
#[cfg(not(target_os = "linux"))]
657+
use libc::{mmap as mmap64, mprotect};
658+
#[cfg(target_os = "linux")]
659+
use libc::{mmap64, mprotect};
657660
use libc::{MAP_ANON, MAP_FAILED, MAP_FIXED, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE};
658661

659662
use crate::io;
@@ -803,7 +806,7 @@ pub mod guard {
803806
// read/write permissions and only then mprotect() it to
804807
// no permissions at all. See issue #50313.
805808
let stackptr = get_stack_start_aligned()?;
806-
let result = mmap(
809+
let result = mmap64(
807810
stackptr,
808811
page_size,
809812
PROT_READ | PROT_WRITE,

src/bootstrap/cache.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ impl<T: Internable + Hash> Hash for Interned<T> {
8989

9090
impl<T: Internable + Deref> Deref for Interned<T> {
9191
type Target = T::Target;
92-
fn deref(&self) -> &'static Self::Target {
92+
fn deref(&self) -> &Self::Target {
9393
let l = T::intern_cache().lock().unwrap();
94-
unsafe { mem::transmute::<&Self::Target, &'static Self::Target>(l.get(*self)) }
94+
unsafe { mem::transmute::<&Self::Target, &Self::Target>(l.get(*self)) }
9595
}
9696
}
9797

9898
impl<T: Internable + AsRef<U>, U: ?Sized> AsRef<U> for Interned<T> {
99-
fn as_ref(&self) -> &'static U {
99+
fn as_ref(&self) -> &U {
100100
let l = T::intern_cache().lock().unwrap();
101-
unsafe { mem::transmute::<&U, &'static U>(l.get(*self).as_ref()) }
101+
unsafe { mem::transmute::<&U, &U>(l.get(*self).as_ref()) }
102102
}
103103
}
104104

src/librustdoc/html/markdown.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
236236
return event;
237237
};
238238

239-
let mut origtext = String::new();
239+
let mut original_text = String::new();
240240
for event in &mut self.inner {
241241
match event {
242242
Event::End(Tag::CodeBlock(..)) => break,
243243
Event::Text(ref s) => {
244-
origtext.push_str(s);
244+
original_text.push_str(s);
245245
}
246246
_ => {}
247247
}
@@ -258,7 +258,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
258258
<pre class=\"language-{}\"><code>{}</code></pre>\
259259
</div>",
260260
lang,
261-
Escape(&origtext),
261+
Escape(&original_text),
262262
)
263263
.into(),
264264
));
@@ -268,7 +268,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
268268
CodeBlockKind::Indented => Default::default(),
269269
};
270270

271-
let lines = origtext.lines().filter_map(|l| map_line(l).for_html());
271+
let lines = original_text.lines().filter_map(|l| map_line(l).for_html());
272272
let text = lines.intersperse("\n".into()).collect::<String>();
273273

274274
compile_fail = parse_result.compile_fail;
@@ -285,7 +285,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
285285
if url.is_empty() {
286286
return None;
287287
}
288-
let test = origtext
288+
let test = original_text
289289
.lines()
290290
.map(|l| map_line(l).for_code())
291291
.intersperse("\n".into())

src/test/codegen/avr/avr-func-addrspace.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// It also validates that functions can be called through function pointers
1010
// through traits.
1111

12-
#![feature(no_core, lang_items, unboxed_closures, arbitrary_self_types)]
12+
#![feature(no_core, lang_items, intrinsics, unboxed_closures, arbitrary_self_types)]
1313
#![crate_type = "lib"]
1414
#![no_core]
1515

@@ -49,6 +49,10 @@ pub trait Fn<Args: Tuple>: FnOnce<Args> {
4949
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
5050
}
5151

52+
extern "rust-intrinsic" {
53+
pub fn transmute<Src, Dst>(src: Src) -> Dst;
54+
}
55+
5256
pub static mut STORAGE_FOO: fn(&usize, &mut u32) -> Result<(), ()> = arbitrary_black_box;
5357
pub static mut STORAGE_BAR: u32 = 12;
5458

@@ -87,3 +91,21 @@ pub extern "C" fn test() {
8791
STORAGE_FOO(&1, &mut buf);
8892
}
8993
}
94+
95+
// Validate that we can codegen transmutes between data ptrs and fn ptrs.
96+
97+
// CHECK: define{{.+}}{{void \(\) addrspace\(1\)\*|ptr addrspace\(1\)}} @transmute_data_ptr_to_fn({{\{\}\*|ptr}}{{.*}} %x)
98+
#[no_mangle]
99+
pub unsafe fn transmute_data_ptr_to_fn(x: *const ()) -> fn() {
100+
// It doesn't matter precisely how this is codegenned (through memory or an addrspacecast),
101+
// as long as it doesn't cause a verifier error by using `bitcast`.
102+
transmute(x)
103+
}
104+
105+
// CHECK: define{{.+}}{{\{\}\*|ptr}} @transmute_fn_ptr_to_data({{void \(\) addrspace\(1\)\*|ptr addrspace\(1\)}}{{.*}} %x)
106+
#[no_mangle]
107+
pub unsafe fn transmute_fn_ptr_to_data(x: fn()) -> *const () {
108+
// It doesn't matter precisely how this is codegenned (through memory or an addrspacecast),
109+
// as long as it doesn't cause a verifier error by using `bitcast`.
110+
transmute(x)
111+
}

src/test/ui/typeck/issue-92481.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//check-fail
2+
3+
#![crate_type="lib"]
4+
5+
fn r({) {
6+
Ok { //~ ERROR mismatched types [E0308]
7+
d..||_=m
8+
}
9+
}
10+
//~^^^^^ ERROR expected parameter name, found `{`
11+
//~| ERROR expected one of `,`, `:`, or `}`, found `..`
12+
//~^^^^^ ERROR cannot find value `d` in this scope [E0425]
13+
//~| ERROR cannot find value `m` in this scope [E0425]
14+
//~| ERROR variant `Result<_, _>::Ok` has no field named `d` [E0559]

src/test/ui/typeck/issue-92481.stderr

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error: expected parameter name, found `{`
2+
--> $DIR/issue-92481.rs:5:6
3+
|
4+
LL | fn r({) {
5+
| ^ expected parameter name
6+
7+
error: expected one of `,`, `:`, or `}`, found `..`
8+
--> $DIR/issue-92481.rs:5:6
9+
|
10+
LL | fn r({) {
11+
| ^ unclosed delimiter
12+
LL | Ok {
13+
LL | d..||_=m
14+
| -^
15+
| |
16+
| help: `}` may belong here
17+
18+
error[E0425]: cannot find value `d` in this scope
19+
--> $DIR/issue-92481.rs:7:9
20+
|
21+
LL | d..||_=m
22+
| ^ not found in this scope
23+
24+
error[E0425]: cannot find value `m` in this scope
25+
--> $DIR/issue-92481.rs:7:16
26+
|
27+
LL | d..||_=m
28+
| ^ not found in this scope
29+
30+
error[E0559]: variant `Result<_, _>::Ok` has no field named `d`
31+
--> $DIR/issue-92481.rs:7:9
32+
|
33+
LL | d..||_=m
34+
| ^ field does not exist
35+
--> $SRC_DIR/core/src/result.rs:LL:COL
36+
|
37+
= note: `Result<_, _>::Ok` defined here
38+
|
39+
help: `Result<_, _>::Ok` is a tuple variant, use the appropriate syntax
40+
|
41+
LL | Result<_, _>::Ok(/* fields */)
42+
|
43+
44+
error[E0308]: mismatched types
45+
--> $DIR/issue-92481.rs:6:5
46+
|
47+
LL | fn r({) {
48+
| - help: a return type might be missing here: `-> _`
49+
LL | / Ok {
50+
LL | | d..||_=m
51+
LL | | }
52+
| |_____^ expected `()`, found enum `Result`
53+
|
54+
= note: expected unit type `()`
55+
found enum `Result<_, _>`
56+
57+
error: aborting due to 6 previous errors
58+
59+
Some errors have detailed explanations: E0308, E0425, E0559.
60+
For more information about an error, try `rustc --explain E0308`.

triagebot.toml

-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ compiler-team-contributors = [
467467
"@compiler-errors",
468468
"@eholk",
469469
"@jackh726",
470-
"@fee1-dead",
471470
"@TaKO8Ki",
472471
"@Nilstrieb",
473472
]

0 commit comments

Comments
 (0)