Comments (7)
ICE message (which as cut off from the original backtrace -- please pots the full error message, not just a pat of it :)
error: internal compiler error: compiler/rustc_const_eval/src/interpret/validity.rs:1039:17: Unexpected error during validation: `extern type` does not have a known offset
We should really reject extern type
s being used like that, they violate fundamental language invariants...
from rust.
it looks like the problem arises when transmuting in as_counted_str, i'll try to do a minimal repo.
from rust.
minimal repro found
#![feature(extern_types)]
#![allow(dead_code)]
extern {
type Opaque;
}
struct ThinDst {
x: u8,
tail: Opaque,
}
const fn t<const N: usize>(x: &[u8; N]) -> &ThinDst {
unsafe { std::mem::transmute(x.as_ptr()) }
}
const C1: &ThinDst = t(b"d");
fn main() {} // required because "miri build" does not exist
from rust.
I've transferred this issue because it's not a bug in Miri, it's a bug in the compiler overall. Miri is the compiler, until main starts. But in your repro, there's nothing in main. So this is just compiler.
from rust.
Smaller:
#![feature(extern_types)]
extern {
type Opaque;
}
struct ThinDst {
x: u8,
tail: Opaque,
}
const C1: &ThinDst = std::mem::transmute(b"d".as_ptr());
from rust.
Note that this is not a good idea IMO:
// use extern types to satisfy stacked borrow rules.
#[cfg(miri)]
extern {
type TrailingData;
}
Using extern types basically intimidates Miri into not checking your code, but that means Miri may miss bugs.
A better fix is to check your code with -Zmiri-tree-borrows
, which has proper support for references that only cover the "header" of a struct. Tree Borrows should still find all UB bugs that can affect your code today, but in the future it's likely we are going to pick aliasing rules that are stricter than Tree Borrows (and weaker than Stacked Borrows).
from rust.
Note that this is not a good idea IMO:
// use extern types to satisfy stacked borrow rules. #[cfg(miri)] extern { type TrailingData; }
Using extern types basically intimidates Miri into not checking your code, but that means Miri may miss bugs.
A better fix is to check your code with
-Zmiri-tree-borrows
, which has proper support for references that only cover the "header" of a struct. Tree Borrows should still find all UB bugs that can affect your code today, but in the future it's likely we are going to pick aliasing rules that are stricter than Tree Borrows (and weaker than Stacked Borrows).
I used extern types because it's what URLO suggested to accurately represent my semantics. it's a DST that exists behind a thin pointer. unfortunatly the "unknown alignment" part isn't really what i wanted. apparently tree borrows are weak enough that it allows writing to a zero-sized field past the end of a struct, so long as its backed by a larger allocation.
from rust.
Related Issues (20)
- inlining and `--release` builds can result in weird debuginfo relative to source HOT 2
- ICE: `Layout::compute: unexpected type '_'` HOT 1
- ICE: Where clause ... was applicable to ... but now is not in `compiler/rustc_trait_selection/src/traits/select/confirmation.rs` HOT 4
- Pathological performance of `.sort()` / `.sort_unstable()` HOT 4
- runtime error: global allocator may not use TLS on arm64 macos HOT 6
- Compiler hangs and consumes unbounded memory with complex trait bounds HOT 8
- ICE: `non-Aggregate field with matching ABI but differing alignment` HOT 2
- ICE: unnamed fields: `internal compiler error: could not resolve DefId` HOT 1
- Feature request: Function to join thread with timeout HOT 2
- const Traits not being handled inside const associated functions/methods HOT 2
- rustdoc reproducibility issue due to nondeterministic anon.llvm.<hash> HOT 1
- Fix internal `Wtf8Buf::extend_from_slice` check HOT 2
- ICE: `assertion left == right failed` in `rustc_const_eval/src/interpret/cast.rs unsize_into` HOT 3
- Regression from new lint `out_of_scope_macro_calls` HOT 4
- rustdoc: panic when using `macro@` and `!` for referencing a macro in documentation HOT 1
- If-else type checking fails with trait method calls and closures HOT 5
- Lots of testsuite failures on powerpc-unknown-linux-gnu after #118709 HOT 4
- Taking reference to function gets optimized to be 0x1 HOT 5
- document args for `-Zbuild-std` when folks aren't building everything HOT 5
- Well-formedness analysis pass on trait impl paniced HOT 2
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 rust.