Skip to content

Mark functions returning uninhabited types as noreturn #50304

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

Merged
merged 1 commit into from
May 1, 2018
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
2 changes: 1 addition & 1 deletion src/librustc_trans/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
}
None => {}
};
if sig.output().is_never() {
if cx.layout_of(sig.output()).abi == ty::layout::Abi::Uninhabited {
flags = flags | DIFlags::FlagNoReturn;
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use llvm::{self, ValueRef};
use llvm::AttributePlace::Function;
use rustc::ty::{self, Ty};
use rustc::ty::layout::{self, LayoutOf};
use rustc::session::config::Sanitizer;
use rustc_target::spec::PanicStrategy;
use abi::{Abi, FnType, FnTypeExt};
Expand Down Expand Up @@ -133,8 +134,7 @@ pub fn declare_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, name: &str,
let fty = FnType::new(cx, sig, &[]);
let llfn = declare_raw_fn(cx, name, fty.llvm_cconv(), fty.llvm_type(cx));

// FIXME(canndrew): This is_never should really be an is_uninhabited
if sig.output().is_never() {
if cx.layout_of(sig.output()).abi == layout::Abi::Uninhabited {
llvm::Attribute::NoReturn.apply_llfn(Function, llfn);
}

Expand Down
22 changes: 16 additions & 6 deletions src/test/codegen/noreturnflag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -g -C no-prepopulate-passes
// ignore-tidy-linelength
// min-llvm-version 4.0

// compile-flags: -g -C no-prepopulate-passes

// CHECK: {{.*}}DISubprogram{{.*}}name: "foo"{{.*}}DIFlagNoReturn
#![crate_type = "lib"]

fn foo() -> ! {
#[no_mangle]
pub fn foo() -> ! {
// CHECK: @foo() unnamed_addr #0
loop {}
}

pub fn main() {
foo();
pub enum EmptyEnum {}

#[no_mangle]
pub fn bar() -> EmptyEnum {
// CHECK: @bar() unnamed_addr #0
loop {}
}

// CHECK: attributes #0 = {{{.*}} noreturn {{.*}}}

// CHECK: DISubprogram(name: "foo", {{.*}} DIFlagNoReturn
// CHECK: DISubprogram(name: "bar", {{.*}} DIFlagNoReturn