Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #46428 and #46253 #46516

Merged
merged 3 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,9 @@ impl<'a, 'tcx> LayoutDetails {
// We have exactly one non-ZST field.
(Some((i, field)), None, None) => {
// Field fills the struct and it has a scalar or scalar pair ABI.
if offsets[i].bytes() == 0 && size == field.size {
if offsets[i].bytes() == 0 &&
align.abi() == field.align.abi() &&
size == field.size {
match field.abi {
// For plain scalars we can't unpack newtypes
// for `#[repr(C)]`, as that affects C ABIs.
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_trans/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@ impl<'a, 'tcx> FnType<'tcx> {
// dependencies rather than pointer equality
let no_alias = match kind {
PointerKind::Shared => false,
PointerKind::Frozen | PointerKind::UniqueOwned => true,
PointerKind::UniqueOwned => true,
PointerKind::Frozen |
PointerKind::UniqueBorrowed => !is_return
};
if no_alias {
Expand Down
12 changes: 5 additions & 7 deletions src/librustc_trans/mir/lvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,12 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
/// Set the discriminant for a new value of the given case of the given
/// representation.
pub fn trans_set_discr(&self, bcx: &Builder<'a, 'tcx>, variant_index: usize) {
match self.layout.variants {
if self.layout.for_variant(bcx.ccx, variant_index).abi == layout::Abi::Uninhabited {
return;
}
match self.layout.variants {
layout::Variants::Single { index } => {
if index != variant_index {
// If the layout of an enum is `Single`, all
// other variants are necessarily uninhabited.
assert_eq!(self.layout.for_variant(bcx.ccx, variant_index).abi,
layout::Abi::Uninhabited);
}
assert_eq!(index, variant_index);
}
layout::Variants::Tagged { .. } => {
let ptr = self.project_field(bcx, 0);
Expand Down
11 changes: 11 additions & 0 deletions src/test/codegen/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ pub fn pkd_pair(pair1: &mut PackedPair, pair2: &mut PackedPair) {
// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 5, i32 1, i1 false)
*pair2 = *pair1;
}

#[repr(packed)]
#[derive(Copy, Clone)]
pub struct PackedNestedPair((u32, u32));

// CHECK-LABEL: @pkd_nested_pair
#[no_mangle]
pub fn pkd_nested_pair(pair1: &mut PackedNestedPair, pair2: &mut PackedNestedPair) {
// CHECK: call void @llvm.memcpy.{{.*}}(i8* %{{.*}}, i8* %{{.*}}, i{{[0-9]+}} 8, i32 1, i1 false)
*pair2 = *pair1;
}
5 changes: 5 additions & 0 deletions src/test/run-make/issue-46239/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-include ../tools.mk

all:
$(RUSTC) main.rs -C opt-level=1
$(call RUN,main)
18 changes: 18 additions & 0 deletions src/test/run-make/issue-46239/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn project<T>(x: &(T,)) -> &T { &x.0 }

fn dummy() {}

fn main() {
let f = (dummy as fn(),);
(*project(&f))();
}
37 changes: 37 additions & 0 deletions src/test/run-pass/issue-46519.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags:--test -O

#[test]
#[should_panic(expected = "creating inhabited type")]
fn test() {
FontLanguageOverride::system_font(SystemFont::new());
}

pub enum FontLanguageOverride {
Normal,
Override(&'static str),
System(SystemFont)
}

pub enum SystemFont {}

impl FontLanguageOverride {
fn system_font(f: SystemFont) -> Self {
FontLanguageOverride::System(f)
}
}

impl SystemFont {
fn new() -> Self {
panic!("creating inhabited type")
}
}