-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect std
by checking if the crate defines #[lang = "start"]
rather than string comparison
#1823
Conversation
src/helpers.rs
Outdated
fn in_std(&self) -> bool { | ||
let this = self.eval_context_ref(); | ||
this.tcx.def_path(this.frame().instance.def_id()).krate | ||
== this.tcx.def_path(this.tcx.lang_items().start_fn().unwrap()).krate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may not be a #[lang = "start"]
when using #![no_std]
in combination with #[start]
, so please don't unwrap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already an unwrap()
in create_ecx()
🤔
Line 113 in ef99830
let start_id = tcx.lang_items().start_fn().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using #![no_std] in combination with #[start]
That sounds like a test case we should have, then. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
#![no_std]
in combination with#[start]
Note that it's currently broken even before the unwrap()
:
error: internal compiler error: src/tools/miri/src/eval.rs:110:9: main function must not take any arguments
thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:1007:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.54.0-nightly (c79419af0 2021-06-04) running on x86_64-unknown-linux-gnu
Line 110 in ef99830
bug!("main function must not take any arguments"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, the start item in Rust has no arguments so I am not sure if it makes sense to support other start items that do.
But this sounds like a separate discussion then, could you open an issue?
Note that the check does not have to be extremely robust. If someone wants to go out of their way to use these incomplete Miri shims, I'm fine with that, but they don't get to complain about any bugs they encounter. ;) So I'm in favor of your code changes, but I am worried about the test size blowup.^^ |
This comment has been minimized.
This comment has been minimized.
(I have removed it now, but) I added it to test that |
Thanks @hyd-dev :) |
📌 Commit 0ece55d has been approved by |
Fair -- however, it is implicitly tested in every single test, which IMO is good enough. |
☀️ Test successful - checks-actions |
I also considered to compare the crate name with
sym::std
, but it's easy to name any cratestd
by using--crate-name std
, so I don't think that is robust enough.Note that this only checks the crate, it does not check whether the call is in
sys::unix
orsys::windows
, unlike the previous implementation, but I think it's already robust enough.Fixes #1821.