Skip to content

Commit

Permalink
Auto merge of #3455 - RalfJung:extern-static, r=RalfJung
Browse files Browse the repository at this point in the history
make 'missing extern static' error consistent with missing shim

What's relevant is mostly the link name of the external symbol, not its Rust path.
  • Loading branch information
bors committed Apr 6, 2024
2 parents beb8a81 + 52a66b2 commit f70a3c4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
let extern_decl_layout = ecx.tcx.layout_of(ty::ParamEnv::empty().and(def_ty)).unwrap();
if extern_decl_layout.size != shim_size || extern_decl_layout.align.abi != shim_align {
throw_unsup_format!(
"`extern` static `{name}` from crate `{krate}` has been declared \
"extern static `{link_name}` has been declared as `{krate}::{name}` \
with a size of {decl_size} bytes and alignment of {decl_align} bytes, \
but Miri emulates it via an extern static shim \
with a size of {shim_size} bytes and alignment of {shim_align} bytes",
Expand All @@ -1080,11 +1080,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
}
Ok(ptr)
} else {
throw_unsup_format!(
"`extern` static `{name}` from crate `{krate}` is not supported by Miri",
name = ecx.tcx.def_path_str(def_id),
krate = ecx.tcx.crate_name(def_id.krate),
)
throw_unsup_format!("extern static `{link_name}` is not supported by Miri",)
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/fail/extern_static.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unsupported operation: `extern` static `FOO` from crate `extern_static` is not supported by Miri
error: unsupported operation: extern static `FOO` is not supported by Miri
--> $DIR/extern_static.rs:LL:CC
|
LL | let _val = unsafe { std::ptr::addr_of!(FOO) };
| ^^^ `extern` static `FOO` from crate `extern_static` is not supported by Miri
| ^^^ extern static `FOO` is not supported by Miri
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/extern_static_in_const.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unsupported operation: `extern` static `E` from crate `extern_static_in_const` is not supported by Miri
error: unsupported operation: extern static `E` is not supported by Miri
--> $DIR/extern_static_in_const.rs:LL:CC
|
LL | let _val = X;
| ^ `extern` static `E` from crate `extern_static_in_const` is not supported by Miri
| ^ extern static `E` is not supported by Miri
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/extern_static_wrong_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ extern "C" {
}

fn main() {
let _val = unsafe { environ }; //~ ERROR: /has been declared with a size of 1 bytes and alignment of 1 bytes, but Miri emulates it via an extern static shim with a size of [48] bytes and alignment of [48] bytes/
let _val = unsafe { environ }; //~ ERROR: /with a size of 1 bytes and alignment of 1 bytes, but Miri emulates it via an extern static shim with a size of [48] bytes and alignment of [48] bytes/
}
4 changes: 2 additions & 2 deletions tests/fail/extern_static_wrong_size.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unsupported operation: `extern` static `environ` from crate `extern_static_wrong_size` has been declared with a size of 1 bytes and alignment of 1 bytes, but Miri emulates it via an extern static shim with a size of N bytes and alignment of N bytes
error: unsupported operation: extern static `environ` has been declared as `extern_static_wrong_size::environ` with a size of 1 bytes and alignment of 1 bytes, but Miri emulates it via an extern static shim with a size of N bytes and alignment of N bytes
--> $DIR/extern_static_wrong_size.rs:LL:CC
|
LL | let _val = unsafe { environ };
| ^^^^^^^ `extern` static `environ` from crate `extern_static_wrong_size` has been declared with a size of 1 bytes and alignment of 1 bytes, but Miri emulates it via an extern static shim with a size of N bytes and alignment of N bytes
| ^^^^^^^ extern static `environ` has been declared as `extern_static_wrong_size::environ` with a size of 1 bytes and alignment of 1 bytes, but Miri emulates it via an extern static shim with a size of N bytes and alignment of N bytes
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unsupported operation: `extern` static `_dispatch_queue_attr_concurrent` from crate `issue_miri_3288_ice_symbolic_alignment_extern_static` is not supported by Miri
error: unsupported operation: extern static `_dispatch_queue_attr_concurrent` is not supported by Miri
--> $DIR/issue-miri-3288-ice-symbolic-alignment-extern-static.rs:LL:CC
|
LL | let _val = *DISPATCH_QUEUE_CONCURRENT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `extern` static `_dispatch_queue_attr_concurrent` from crate `issue_miri_3288_ice_symbolic_alignment_extern_static` is not supported by Miri
| ^^^^^^^^^^^^^^^^^^^^^^^^^ extern static `_dispatch_queue_attr_concurrent` is not supported by Miri
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: BACKTRACE:
Expand Down

0 comments on commit f70a3c4

Please sign in to comment.