Skip to content

Commit 341c860

Browse files
committed
Auto merge of #151594 - matthiaskrgr:rollup-sAb1Qar, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang/rust#149174 (`const` blocks as a `mod` item) - rust-lang/rust#151282 (THIR patterns: Explicitly distinguish `&pin` from plain `&`/`&mut`) - rust-lang/rust#151593 (miri subtree update) - rust-lang/rust#151516 (Do not emit errors on non-metaitem diagnostic attr input) r? @ghost
2 parents 348b485 + f19ae55 commit 341c860

17 files changed

Lines changed: 412 additions & 197 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tex/*/out
55
*.rs.bk
66
.vscode
77
.helix
8+
.zed
89
*.mm_profdata
910
perf.data
1011
perf.data.old

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b6fdaf2a15736cbccf248b532f48e33179614d40
1+
d10ac47c20152feb5e99b1c35a2e6830f77c66dc

src/bin/miri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
clippy::manual_range_contains,
44
clippy::useless_format,
55
clippy::field_reassign_with_default,
6-
clippy::needless_lifetimes,
6+
clippy::needless_lifetimes
77
)]
88

99
// The rustc crates we need

src/shims/sig.rs

Lines changed: 103 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,118 @@ pub struct ShimSig<'tcx, const ARGS: usize> {
2828
/// - `winapi::$ty` for a type from `std::sys::pal::windows::c`
2929
#[macro_export]
3030
macro_rules! shim_sig {
31-
(extern $abi:literal fn($($arg:ty),* $(,)?) -> $ret:ty) => {
31+
(extern $abi:literal fn($($args:tt)*) -> $($ret:tt)*) => {
3232
|this| $crate::shims::sig::ShimSig {
3333
abi: std::str::FromStr::from_str($abi).expect("incorrect abi specified"),
34-
args: [$(shim_sig_arg!(this, $arg)),*],
35-
ret: shim_sig_arg!(this, $ret),
34+
args: shim_sig_args_sep!(this, [$($args)*]),
35+
ret: shim_sig_arg!(this, $($ret)*),
3636
}
3737
};
3838
}
3939

4040
/// Helper for `shim_sig!`.
41+
///
42+
/// Groups tokens into comma-separated chunks and calls the provided macro on them.
43+
///
44+
/// # Examples
45+
///
46+
/// ```ignore
47+
/// shim_sig_args_sep!(this, [*const _, i32, libc::off64_t]);
48+
/// // expands to:
49+
/// [shim_sig_arg!(*const _), shim_sig_arg!(i32), shim_sig_arg!(libc::off64_t)];
50+
/// ```
51+
#[macro_export]
52+
macro_rules! shim_sig_args_sep {
53+
($this:ident, [$($tt:tt)*]) => {
54+
shim_sig_args_sep!(@ $this [] [] $($tt)*)
55+
};
56+
57+
// All below matchers form a fairly simple iterator over the input.
58+
// - Non-comma token - append to collector
59+
// - Comma token - call the provided macro on the collector and reset the collector
60+
// - End of input - empty collector one last time. emit output as an array
61+
62+
// Handles `,` token - take collected type and call shim_sig_arg on it.
63+
// Append the result to the final output.
64+
(@ $this:ident [$($final:tt)*] [$($collected:tt)*] , $($tt:tt)*) => {
65+
shim_sig_args_sep!(@ $this [$($final)* shim_sig_arg!($this, $($collected)*), ] [] $($tt)*)
66+
};
67+
// Handle non-comma token - append to collected type.
68+
(@ $this:ident [$($final:tt)*] [$($collected:tt)*] $first:tt $($tt:tt)*) => {
69+
shim_sig_args_sep!(@ $this [$($final)*] [$($collected)* $first] $($tt)*)
70+
};
71+
// No more tokens - emit final output, including final non-comma type.
72+
(@ $this:ident [$($final:tt)*] [$($collected:tt)+] ) => {
73+
[$($final)* shim_sig_arg!($this, $($collected)*)]
74+
};
75+
// No more tokens - emit final output.
76+
(@ $this:ident [$($final:tt)*] [] ) => {
77+
[$($final)*]
78+
};
79+
}
80+
81+
/// Helper for `shim_sig!`.
82+
///
83+
/// Converts a type
4184
#[macro_export]
4285
macro_rules! shim_sig_arg {
43-
// Unfortuantely we cannot take apart a `ty`-typed token at compile time,
44-
// so we have to stringify it and match at runtime.
45-
($this:ident, $x:ty) => {{
46-
match stringify!($x) {
47-
"i8" => $this.tcx.types.i8,
48-
"i16" => $this.tcx.types.i16,
49-
"i32" => $this.tcx.types.i32,
50-
"i64" => $this.tcx.types.i64,
51-
"i128" => $this.tcx.types.i128,
52-
"isize" => $this.tcx.types.isize,
53-
"u8" => $this.tcx.types.u8,
54-
"u16" => $this.tcx.types.u16,
55-
"u32" => $this.tcx.types.u32,
56-
"u64" => $this.tcx.types.u64,
57-
"u128" => $this.tcx.types.u128,
58-
"usize" => $this.tcx.types.usize,
59-
"()" => $this.tcx.types.unit,
60-
"bool" => $this.tcx.types.bool,
61-
"*const _" => $this.machine.layouts.const_raw_ptr.ty,
62-
"*mut _" => $this.machine.layouts.mut_raw_ptr.ty,
63-
ty if let Some(win_ty) = ty.strip_prefix("winapi::") =>
64-
$this.windows_ty_layout(win_ty).ty,
65-
ty if ty.contains("::") =>
66-
helpers::path_ty_layout($this, &ty.split("::").collect::<Vec<_>>()).ty,
67-
ty => panic!("unsupported signature type {ty:?}"),
68-
}
69-
}};
86+
($this:ident, i8) => {
87+
$this.tcx.types.i8
88+
};
89+
($this:ident, i16) => {
90+
$this.tcx.types.i16
91+
};
92+
($this:ident, i32) => {
93+
$this.tcx.types.i32
94+
};
95+
($this:ident, i64) => {
96+
$this.tcx.types.i64
97+
};
98+
($this:ident, i128) => {
99+
$this.tcx.types.i128
100+
};
101+
($this:ident, isize) => {
102+
$this.tcx.types.isize
103+
};
104+
($this:ident, u8) => {
105+
$this.tcx.types.u8
106+
};
107+
($this:ident, u16) => {
108+
$this.tcx.types.u16
109+
};
110+
($this:ident, u32) => {
111+
$this.tcx.types.u32
112+
};
113+
($this:ident, u64) => {
114+
$this.tcx.types.u64
115+
};
116+
($this:ident, u128) => {
117+
$this.tcx.types.u128
118+
};
119+
($this:ident, usize) => {
120+
$this.tcx.types.usize
121+
};
122+
($this:ident, ()) => {
123+
$this.tcx.types.unit
124+
};
125+
($this:ident, bool) => {
126+
$this.tcx.types.bool
127+
};
128+
($this:ident, *const _) => {
129+
$this.machine.layouts.const_raw_ptr.ty
130+
};
131+
($this:ident, *mut _) => {
132+
$this.machine.layouts.mut_raw_ptr.ty
133+
};
134+
($this:ident, winapi::$ty:ident) => {
135+
$this.windows_ty_layout(stringify!($ty)).ty
136+
};
137+
($this:ident, $krate:ident :: $($path:ident)::+) => {
138+
helpers::path_ty_layout($this, &[stringify!($krate), $(stringify!($path)),*]).ty
139+
};
140+
($this:ident, $($other:tt)*) => {
141+
compile_error!(concat!("unsupported signature type: ", stringify!($($other)*)))
142+
}
70143
}
71144

72145
/// Helper function to compare two ABIs.

src/shims/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
347347
assert_eq!(unblock, UnblockKind::TimedOut);
348348
interp_ok(())
349349
}
350-
)
350+
),
351351
);
352352

353353
interp_ok(Scalar::from_i32(0)) // KERN_SUCCESS

src/shims/unix/android/foreign_items.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3939
let result = this.lstat(path, buf)?;
4040
this.write_scalar(result, dest)?;
4141
}
42-
"readdir" => {
43-
// FIXME: This does not have a direct test (#3179).
44-
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
45-
let result = this.readdir64("dirent", dirp)?;
46-
this.write_scalar(result, dest)?;
47-
}
4842
"pread64" => {
4943
// FIXME: This does not have a direct test (#3179).
5044
let [fd, buf, count, offset] = this.check_shim_sig(
@@ -85,7 +79,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8579
let fd = this.read_scalar(fd)?.to_i32()?;
8680
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
8781
let whence = this.read_scalar(whence)?.to_i32()?;
88-
this.lseek64(fd, offset, whence, dest)?;
82+
this.lseek(fd, offset, whence, dest)?;
8983
}
9084
"ftruncate64" => {
9185
let [fd, length] = this.check_shim_sig(

src/shims/unix/foreign_items.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
363363
this.write_scalar(result, dest)?;
364364
}
365365
"opendir" => {
366-
// FIXME: This does not have a direct test (#3179).
367366
let [name] = this.check_shim_sig(
368367
shim_sig!(extern "C" fn(*const _) -> *mut _),
369368
link_name,
@@ -374,7 +373,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
374373
this.write_scalar(result, dest)?;
375374
}
376375
"closedir" => {
377-
// FIXME: This does not have a direct test (#3179).
378376
let [dirp] = this.check_shim_sig(
379377
shim_sig!(extern "C" fn(*mut _) -> i32),
380378
link_name,
@@ -384,6 +382,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
384382
let result = this.closedir(dirp)?;
385383
this.write_scalar(result, dest)?;
386384
}
385+
"readdir" => {
386+
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
387+
this.readdir(dirp, dest)?;
388+
}
387389
"lseek" => {
388390
// FIXME: This does not have a direct test (#3179).
389391
let [fd, offset, whence] = this.check_shim_sig(
@@ -395,7 +397,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
395397
let fd = this.read_scalar(fd)?.to_i32()?;
396398
let offset = this.read_scalar(offset)?.to_int(offset.layout.size)?;
397399
let whence = this.read_scalar(whence)?.to_i32()?;
398-
this.lseek64(fd, offset, whence, dest)?;
400+
this.lseek(fd, offset, whence, dest)?;
399401
}
400402
"ftruncate" => {
401403
let [fd, length] = this.check_shim_sig(

src/shims/unix/freebsd/foreign_items.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
155155
let result = this.fstat(fd, buf)?;
156156
this.write_scalar(result, dest)?;
157157
}
158-
"readdir" | "readdir@FBSD_1.0" => {
159-
// FIXME: This does not have a direct test (#3179).
158+
"readdir@FBSD_1.0" => {
160159
let [dirp] = this.check_shim_sig_lenient(abi, CanonAbi::C, link_name, args)?;
161-
let result = this.readdir64("dirent", dirp)?;
162-
this.write_scalar(result, dest)?;
160+
this.readdir(dirp, dest)?;
163161
}
164162
// Miscellaneous
165163
"__error" => {

0 commit comments

Comments
 (0)