Comments (11)
right. it would probably be better to include a full tracing mode instead of doing something like this.
from miri.
Transmuting a struct with integer at some place to a struct with pointer at that place should be a error.
from miri.
Not sure how hard it would be to check this, but it should also be an error to transmute to an enum with an invalid discriminant.
from miri.
When is a transmute ever UB just by itself? The UB generally comes from the invalid value being used later (and it might not be).
Additionally, it doesn't make sense to special-case transmute. The same effects come from derefing pointers (which might have been casted) and possibly other means. In all these cases Miri is already set up to deal with invalid values that might arise.
from miri.
integer ->
*const T
(cast)
This is actually really common (e.g. std::ptr::null()
does this).
&T
->*const T
(cast/coercion)
*const T
->&T
(should be a deref)
I agree but this is out of scope of Miri. rustc itself should lint these, IMHO. (Normally I would say clippy, but I think these are important enough for rustc.)
from miri.
This is actually really common (e.g. std::ptr::null() does this).
std::ptr::null
uses a cast
from miri.
@oli-obk Oops, sorry, somehow I misunderstood what you meant even though it was clear. I should have been sleeping rather than replying. :)
Yeah, those transmutes should be linted against, too, ideally by rustc.
from miri.
| 32-bit values that aren't valid unicode indices casted to char
Shouldn't they be using std::char::from_u32
or std::char::from_u32_unchecked
?
from miri.
Transmuting a struct with integer at some place to a struct with pointer at that place should be a error.
that means that 0 as *const i32
should be an error, too, since the equivalent transmute<usize, *const i32>(0)
would be an error. We'll catch such errors at the use site, if they are errors.
Ignore that. We should definitely error at transmutes, but allow pointer casts until dereferenced
from miri.
This discussion is going out of bounds in terms of what makes sense to implement inside of Miri. Miri already handles when you do invalid transmutes and then do something that depends on the result being valid (like matching over an enum), it just doesn't error out at transmute time.
Like I said before, this is maybe something that could be brought up as a lint for rustc, but it's not actionable for Miri.
from miri.
Miri can detect transmutes that are UB because of the value. Everything that is UB because of the types should be a lint.
from miri.
Related Issues (20)
- Support more ways of using mmap
- Complete basic support for wasm32-wasip2 HOT 9
- Complete basic support for android HOT 3
- strerror based on ErrorKind is technically valid but surprising HOT 3
- Miri accepts an open-coded compare-exchange loop but rejects the equivalent code using fetch_update HOT 5
- Android: implement support for pthread synchronization primitives
- Android: make std thread APIs work
- Big `Vec::try_reserve` OOMs Miri (slowly) HOT 12
- Clearer error message for unsupported flags: print names of flags (if possible) HOT 1
- "local crate" detection does not work any more
- Stuck when running `cargo miri test` HOT 3
- ICE due to overflow when using a large timeout with futexes HOT 2
- Possible false positive of stacked borrow rules HOT 1
- simd_bitmask: support vectors larger than 64 elements
- Miri does not detect invalid uses of alchemy (std::ptr::from_raw_parts w/ invalid vtable pointer) HOT 5
- Implement blocking support for eventfd and socketpair HOT 6
- Memory-reusing custom allocator fails in miri HOT 1
- Use strict_{add,sub,...} instead of checked_{add,sub,...}.unwrap()
- Support setting Miri flags in the rustc file via attributes HOT 2
- Calling a method on `&mut Box<T>` is not detected as a Unique retag HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miri.