Skip to content

Commit

Permalink
Rollup merge of #39683 - solson:fix-unaligned-load-librustc_metadata,…
Browse files Browse the repository at this point in the history
… r=bluss

Fix unaligned load in librustc_metadata::index.

The derived `Clone` impl contains UB and will be unsafe when we fix #27060. See [this comment](#27060 (comment)) for more context.

r? @bluss
  • Loading branch information
frewsxcv authored Feb 9, 2017
2 parents 7e2b2f3 + 5eaa7c2 commit 55c17a5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/librustc_metadata/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,17 @@ impl<'tcx> LazySeq<Index> {
}

#[repr(packed)]
#[derive(Copy, Clone)]
#[derive(Copy)]
struct Unaligned<T>(T);

// The derived Clone impl is unsafe for this packed struct since it needs to pass a reference to
// the field to `T::clone`, but this reference may not be properly aligned.
impl<T: Copy> Clone for Unaligned<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T> Unaligned<T> {
fn get(self) -> T { self.0 }
}
Expand Down

0 comments on commit 55c17a5

Please sign in to comment.