Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6ece144

Browse files
committedApr 20, 2016
Auto merge of #32939 - eddyb:layout, r=nikomatsakis
Compute LLVM-agnostic type layouts in rustc. Layout for monomorphic types, and some polymorphic ones (e.g. `&T` where `T: Sized`), can now be computed by rustc without involving LLVM in the actual process. This gives rustc the ability to evaluate `size_of` or `align_of`, as well as obtain field offsets. MIR-based CTFE will eventually make use of these layouts, as will MIR trans, shortly. Layout computation also comes with a `[breaking-change]`, or two: * `"data-layout"` is now mandatory in custom target specifications, reverting the decision from #27076. This string is needed because it describes endianness, pointer size and alignments for various types. We have the first two and we could allow tweaking alignments in target specifications. Or we could also extract the data layout from LLVM and feed it back into rustc. However, that can vary with the LLVM version, which is fragile and undermines stability. For built-in targets, I've added a check that the hardcoded data-layout matches LLVM defaults. * `transmute` calls are checked in a stricter fashion, which fixes #32377 To expand on `transmute`, there are only 2 allowed patterns: between types with statically known sizes and between pointers with the same potentially-unsized "tail" (which determines the type of unsized metadata they use, if any). If you're affected, my suggestions are: * try to use casts (and raw pointer deref) instead of transmutes * *really* try to avoid `transmute` where possible * if you have a structure, try working on individual fields and unpack/repack the structure instead of transmuting it whole, e.g. `transmute::<RefCell<Box<T>>, RefCell<*mut T>>(x)` doesn't work, but `RefCell::new(Box::into_raw(x.into_inner()))` does (and `Box::into_raw` is just a `transmute`)
2 parents 133f60f + c7d564d commit 6ece144

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1698
-393
lines changed
 

‎src/librustc/dep_graph/dep_node.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ pub enum DepNode<D: Clone + Debug> {
7171
DeadCheck,
7272
StabilityCheck,
7373
LateLintCheck,
74-
IntrinsicUseCheck,
7574
TransCrate,
7675
TransCrateItem(D),
7776
TransInlinedItem(D),
@@ -169,7 +168,6 @@ impl<D: Clone + Debug> DepNode<D> {
169168
DeadCheck => Some(DeadCheck),
170169
StabilityCheck => Some(StabilityCheck),
171170
LateLintCheck => Some(LateLintCheck),
172-
IntrinsicUseCheck => Some(IntrinsicUseCheck),
173171
TransCrate => Some(TransCrate),
174172
TransWriteMetadata => Some(TransWriteMetadata),
175173
Hir(ref d) => op(d).map(Hir),

‎src/librustc/diagnostics.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,32 @@ It is not possible to use stability attributes outside of the standard library.
14101410
Also, for now, it is not possible to write deprecation messages either.
14111411
"##,
14121412

1413+
E0512: r##"
1414+
Transmute with two differently sized types was attempted. Erroneous code
1415+
example:
1416+
1417+
```compile_fail
1418+
fn takes_u8(_: u8) {}
1419+
1420+
fn main() {
1421+
unsafe { takes_u8(::std::mem::transmute(0u16)); }
1422+
// error: transmute called with differently sized types
1423+
}
1424+
```
1425+
1426+
Please use types with same size or use the expected type directly. Example:
1427+
1428+
```
1429+
fn takes_u8(_: u8) {}
1430+
1431+
fn main() {
1432+
unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
1433+
// or:
1434+
unsafe { takes_u8(0u8); } // ok!
1435+
}
1436+
```
1437+
"##,
1438+
14131439
E0517: r##"
14141440
This error indicates that a `#[repr(..)]` attribute was placed on an
14151441
unsupported item.

0 commit comments

Comments
 (0)
Please sign in to comment.