Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add runtime safety for noreturn function returning
Closes #15221
- Loading branch information
Showing
4 changed files
with
55 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const std = @import("std"); | ||
|
||
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | ||
_ = stack_trace; | ||
if (std.mem.eql(u8, message, "'noreturn' function returned")) { | ||
std.process.exit(0); | ||
} | ||
std.process.exit(1); | ||
} | ||
const T = struct { | ||
export fn bar() void { | ||
// ... | ||
} | ||
}; | ||
|
||
extern fn bar() noreturn; | ||
pub fn main() void { | ||
_ = T.bar; | ||
bar(); | ||
} | ||
// run | ||
// backend=llvm | ||
// target=native |