Skip to content

Commit 491512b

Browse files
committed
Auto merge of #50304 - nox:uninhabited-output, r=eddyb
Mark functions returning uninhabited types as noreturn
2 parents 2a8ad90 + 69ec4aa commit 491512b

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/librustc_trans/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
271271
}
272272
None => {}
273273
};
274-
if sig.output().is_never() {
274+
if cx.layout_of(sig.output()).abi == ty::layout::Abi::Uninhabited {
275275
flags = flags | DIFlags::FlagNoReturn;
276276
}
277277

src/librustc_trans/declare.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use llvm::{self, ValueRef};
2424
use llvm::AttributePlace::Function;
2525
use rustc::ty::{self, Ty};
26+
use rustc::ty::layout::{self, LayoutOf};
2627
use rustc::session::config::Sanitizer;
2728
use rustc_target::spec::PanicStrategy;
2829
use abi::{Abi, FnType, FnTypeExt};
@@ -133,8 +134,7 @@ pub fn declare_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, name: &str,
133134
let fty = FnType::new(cx, sig, &[]);
134135
let llfn = declare_raw_fn(cx, name, fty.llvm_cconv(), fty.llvm_type(cx));
135136

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

src/test/codegen/noreturnflag.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,27 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// compile-flags: -g -C no-prepopulate-passes
1112
// ignore-tidy-linelength
1213
// min-llvm-version 4.0
1314

14-
// compile-flags: -g -C no-prepopulate-passes
15-
16-
// CHECK: {{.*}}DISubprogram{{.*}}name: "foo"{{.*}}DIFlagNoReturn
15+
#![crate_type = "lib"]
1716

18-
fn foo() -> ! {
17+
#[no_mangle]
18+
pub fn foo() -> ! {
19+
// CHECK: @foo() unnamed_addr #0
1920
loop {}
2021
}
2122

22-
pub fn main() {
23-
foo();
23+
pub enum EmptyEnum {}
24+
25+
#[no_mangle]
26+
pub fn bar() -> EmptyEnum {
27+
// CHECK: @bar() unnamed_addr #0
28+
loop {}
2429
}
30+
31+
// CHECK: attributes #0 = {{{.*}} noreturn {{.*}}}
32+
33+
// CHECK: DISubprogram(name: "foo", {{.*}} DIFlagNoReturn
34+
// CHECK: DISubprogram(name: "bar", {{.*}} DIFlagNoReturn

0 commit comments

Comments
 (0)