Skip to content

Commit 4856f07

Browse files
committed
Rollup merge of rust-lang#47618 - mrhota:dw_at_noreturn, r=michaelwoerister
Teach rustc about DW_AT_noreturn and a few more DIFlags We achieve two small things with this PR: 1. We provide definitions for a few additional llvm debuginfo flags 1. We _use_ one of these new flags, `FlagNoReturn`, and add it to debuginfo for functions with the never return type (`!`).
2 parents 9852b23 + e0f9b26 commit 4856f07

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-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) {
@@ -544,7 +548,19 @@ static unsigned fromRust(LLVMRustDIFlags Flags) {
544548
if (isSet(Flags & LLVMRustDIFlags::FlagRValueReference)) {
545549
Result |= DINode::DIFlags::FlagRValueReference;
546550
}
551+
if (isSet(Flags & LLVMRustDIFlags::FlagExternalTypeRef)) {
552+
Result |= DINode::DIFlags::FlagExternalTypeRef;
553+
}
554+
if (isSet(Flags & LLVMRustDIFlags::FlagIntroducedVirtual)) {
555+
Result |= DINode::DIFlags::FlagIntroducedVirtual;
556+
}
557+
if (isSet(Flags & LLVMRustDIFlags::FlagBitField)) {
558+
Result |= DINode::DIFlags::FlagBitField;
559+
}
547560
#if LLVM_RUSTLLVM || LLVM_VERSION_GE(4, 0)
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

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 4.0
13+
14+
// compile-flags: -g -C no-prepopulate-passes
15+
16+
// CHECK: {{.*}}DISubprogram{{.*}}name: "foo"{{.*}}DIFlagNoReturn
17+
18+
fn foo() -> ! {
19+
loop {}
20+
}
21+
22+
pub fn main() {
23+
foo();
24+
}

0 commit comments

Comments
 (0)