Skip to content

Commit 7188706

Browse files
committed
Teach rustc about DW_AT_noreturn and a few more DIFlags
1 parent 15a1e28 commit 7188706

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

src/librustc_llvm/ffi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ pub mod debuginfo {
498498
const FlagStaticMember = (1 << 12);
499499
const FlagLValueReference = (1 << 13);
500500
const FlagRValueReference = (1 << 14);
501+
const FlagExternalTypeRef = (1 << 15);
502+
const FlagIntroducedVirtual = (1 << 18);
503+
const FlagBitField = (1 << 19);
504+
const FlagNoReturn = (1 << 20);
501505
const FlagMainSubprogram = (1 << 21);
502506
}
503507
}

src/librustc_trans/debuginfo/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
270270
}
271271
None => {}
272272
};
273+
if sig.output().is_never() {
274+
flags = flags | DIFlags::FlagNoReturn;
275+
}
273276

274277
let fn_metadata = unsafe {
275278
llvm::LLVMRustDIBuilderCreateFunction(

src/rustllvm/RustWrapper.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,13 @@ enum class LLVMRustDIFlags : uint32_t {
457457
FlagStaticMember = (1 << 12),
458458
FlagLValueReference = (1 << 13),
459459
FlagRValueReference = (1 << 14),
460-
FlagMainSubprogram = (1 << 21),
460+
FlagExternalTypeRef = (1 << 15),
461+
FlagIntroducedVirtual = (1 << 18),
462+
FlagBitField = (1 << 19),
463+
FlagNoReturn = (1 << 20),
464+
FlagMainSubprogram = (1 << 21),
461465
// Do not add values that are not supported by the minimum LLVM
462-
// version we support!
466+
// version we support! see llvm/include/llvm/IR/DebugInfoFlags.def
463467
};
464468

465469
inline LLVMRustDIFlags operator&(LLVMRustDIFlags A, LLVMRustDIFlags B) {
@@ -545,6 +549,18 @@ static unsigned fromRust(LLVMRustDIFlags Flags) {
545549
Result |= DINode::DIFlags::FlagRValueReference;
546550
}
547551
#if LLVM_RUSTLLVM || LLVM_VERSION_GE(4, 0)
552+
if (isSet(Flags & LLVMRustDIFlags::FlagExternalTypeRef)) {
553+
Result |= DINode::DIFlags::FlagExternalTypeRef;
554+
}
555+
if (isSet(Flags & LLVMRustDIFlags::FlagIntroducedVirtual)) {
556+
Result |= DINode::DIFlags::FlagIntroducedVirtual;
557+
}
558+
if (isSet(Flags & LLVMRustDIFlags::FlagBitField)) {
559+
Result |= DINode::DIFlags::FlagBitField;
560+
}
561+
if (isSet(Flags & LLVMRustDIFlags::FlagNoReturn)) {
562+
Result |= DINode::DIFlags::FlagNoReturn;
563+
}
548564
if (isSet(Flags & LLVMRustDIFlags::FlagMainSubprogram)) {
549565
Result |= DINode::DIFlags::FlagMainSubprogram;
550566
}

src/test/codegen/noreturnflag.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-linelength
12+
// min-llvm-version 3.8
13+
14+
// compile-flags: -g -C no-prepopulate-passes
15+
16+
// CHECK-LABEL: foo
17+
// CHECK: {{.*}}DISubprogram{{.*}} name: "foo",{{.*}}DIFlagNoReturn{{.*}}
18+
19+
#[no_mangle]
20+
pub fn foo() -> ! {
21+
loop {}
22+
}
23+
24+
// CHECK-LABEL: main
25+
// CHECK: {{.*}}DISubprogram{{.*}}name: "main",{{.*}}DIFlagMainSubprogram{{.*}}
26+
27+
pub fn main() {
28+
foo();
29+
}

0 commit comments

Comments
 (0)