forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#59639 - cuviper:ignore-uninhabited, r=sanxiyn
Never return uninhabited values at all Functions with uninhabited return values are already marked `noreturn`, but we were still generating return instructions for this. When running with `C passes=lint`, LLVM prints: Unusual: Return statement in function with noreturn attribute The LLVM manual makes a stronger statement about `noreturn` though: > This produces undefined behavior at runtime if the function ever does dynamically return. We now mark such return values with a new `IgnoreMode::Uninhabited`, and emit an `abort` anywhere that would have returned. Fixes rust-lang#48227 cc rust-lang#7463 rust-lang#48229 r? @eddyb
- Loading branch information
Showing
5 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// compile-flags: -g -C no-prepopulate-passes | ||
// ignore-tidy-linelength | ||
|
||
#![crate_type = "lib"] | ||
|
||
#[derive(Clone, Copy)] | ||
pub enum EmptyEnum {} | ||
|
||
#[no_mangle] | ||
pub fn empty(x: &EmptyEnum) -> EmptyEnum { | ||
// CHECK: @empty({{.*}}) unnamed_addr #0 | ||
// CHECK-NOT: ret void | ||
// CHECK: call void @llvm.trap() | ||
// CHECK: unreachable | ||
*x | ||
} | ||
|
||
pub struct Foo(String, EmptyEnum); | ||
|
||
#[no_mangle] | ||
pub fn foo(x: String, y: &EmptyEnum) -> Foo { | ||
// CHECK: @foo({{.*}}) unnamed_addr #0 | ||
// CHECK-NOT: ret %Foo | ||
// CHECK: call void @llvm.trap() | ||
// CHECK: unreachable | ||
Foo(x, *y) | ||
} | ||
|
||
// CHECK: attributes #0 = {{{.*}} noreturn {{.*}}} | ||
|
||
// CHECK: DISubprogram(name: "empty", {{.*}} DIFlagNoReturn | ||
// CHECK: DISubprogram(name: "foo", {{.*}} DIFlagNoReturn |