Skip to content

Commit 55c17a5

Browse files
authoredFeb 9, 2017
Rollup merge of rust-lang#39683 - solson:fix-unaligned-load-librustc_metadata, r=bluss
Fix unaligned load in librustc_metadata::index. The derived `Clone` impl contains UB and will be unsafe when we fix rust-lang#27060. See [this comment](rust-lang#27060 (comment)) for more context. r? @bluss
2 parents 7e2b2f3 + 5eaa7c2 commit 55c17a5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎src/librustc_metadata/index.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,17 @@ impl<'tcx> LazySeq<Index> {
9696
}
9797

9898
#[repr(packed)]
99-
#[derive(Copy, Clone)]
99+
#[derive(Copy)]
100100
struct Unaligned<T>(T);
101101

102+
// The derived Clone impl is unsafe for this packed struct since it needs to pass a reference to
103+
// the field to `T::clone`, but this reference may not be properly aligned.
104+
impl<T: Copy> Clone for Unaligned<T> {
105+
fn clone(&self) -> Self {
106+
*self
107+
}
108+
}
109+
102110
impl<T> Unaligned<T> {
103111
fn get(self) -> T { self.0 }
104112
}

0 commit comments

Comments
 (0)
Please sign in to comment.