CBE: Use zig_noreturn instead of noreturn to avoid namespace conflict

This commit is contained in:
Noam Preil
2020-08-09 17:21:40 -04:00
committed by Andrew Kelley
parent b59e2c1e00
commit dd1f1487e4
4 changed files with 13 additions and 16 deletions

View File

@@ -1,10 +1,10 @@
#if __STDC_VERSION__ >= 201112L
#define noreturn _Noreturn
#define zig_noreturn _Noreturn
#elif __GNUC__
#define noreturn __attribute__ ((noreturn))
#define zig_noreturn __attribute__ ((noreturn))
#elif _MSC_VER
#define noreturn __declspec(noreturn)
#define zig_noreturn __declspec(noreturn)
#else
#define noreturn
#define zig_noreturn
#endif

View File

@@ -24,8 +24,7 @@ fn renderType(file: *C, writer: std.ArrayList(u8).Writer, T: Type, src: usize) !
} else {
switch (T.zigTypeTag()) {
.NoReturn => {
file.need_noreturn = true;
try writer.writeAll("noreturn void");
try writer.writeAll("zig_noreturn void");
},
.Void => try writer.writeAll("void"),
.Int => {

View File

@@ -202,7 +202,6 @@ pub const File = struct {
called: std.StringHashMap(void),
need_stddef: bool = false,
need_stdint: bool = false,
need_noreturn: bool = false,
error_msg: *Module.ErrorMsg = undefined,
pub fn openPath(allocator: *Allocator, dir: fs.Dir, sub_path: []const u8, options: Options) !*File {

View File

@@ -12,7 +12,7 @@ pub fn addCases(ctx: *TestContext) !void {
ctx.c("empty start function", linux_x64,
\\export fn _start() noreturn {}
,
\\noreturn void _start(void) {}
\\zig_noreturn void _start(void) {}
\\
);
ctx.c("less empty start function", linux_x64,
@@ -22,19 +22,19 @@ pub fn addCases(ctx: *TestContext) !void {
\\ main();
\\}
,
\\noreturn void main(void);
\\zig_noreturn void main(void);
\\
\\noreturn void _start(void) {
\\zig_noreturn void _start(void) {
\\ main();
\\}
\\
\\noreturn void main(void) {}
\\zig_noreturn void main(void) {}
\\
);
// TODO: implement return values
// TODO: figure out a way to prevent asm constants from being generated
ctx.c("inline asm", linux_x64,
\\fn exitGood() void {
\\fn exitGood() noreturn {
\\ asm volatile ("syscall"
\\ :
\\ : [number] "{rax}" (231),
@@ -48,21 +48,20 @@ pub fn addCases(ctx: *TestContext) !void {
,
\\#include <stddef.h>
\\
\\void exitGood(void);
\\zig_noreturn void exitGood(void);
\\
\\const char *const exitGood__anon_0 = "{rax}";
\\const char *const exitGood__anon_1 = "{rdi}";
\\const char *const exitGood__anon_2 = "syscall";
\\
\\noreturn void _start(void) {
\\zig_noreturn void _start(void) {
\\ exitGood();
\\}
\\
\\void exitGood(void) {
\\zig_noreturn void exitGood(void) {
\\ register size_t rax_constant __asm__("rax") = 231;
\\ register size_t rdi_constant __asm__("rdi") = 0;
\\ __asm volatile ("syscall" :: ""(rax_constant), ""(rdi_constant));
\\ return;
\\}
\\
);