authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-08-09 17:21:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-12 21:58:21-07:00
logdd1f1487e436650f93e05648b5ba879d6832c2a7
tree60f4e89fae80fa4438c0d5389799104d4a402b8a
parentb59e2c1e009e8e2df2de02d61d8f4ef463a652be

CBE: Use zig_noreturn instead of noreturn to avoid namespace conflict


4 files changed, 13 insertions(+), 16 deletions(-)

src-self-hosted/cbe.h+4-4
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1#if __STDC_VERSION__ >= 201112L1#if __STDC_VERSION__ >= 201112L
2#define noreturn _Noreturn2#define zig_noreturn _Noreturn
3#elif __GNUC__3#elif __GNUC__
4#define noreturn __attribute__ ((noreturn))4#define zig_noreturn __attribute__ ((noreturn))
5#elif _MSC_VER5#elif _MSC_VER
6#define noreturn __declspec(noreturn)6#define zig_noreturn __declspec(noreturn)
7#else7#else
8#define noreturn8#define zig_noreturn
9#endif9#endif
1010
src-self-hosted/codegen/c.zig+1-2
...@@ -24,8 +24,7 @@ fn renderType(file: *C, writer: std.ArrayList(u8).Writer, T: Type, src: usize) !...@@ -24,8 +24,7 @@ fn renderType(file: *C, writer: std.ArrayList(u8).Writer, T: Type, src: usize) !
24 } else {24 } else {
25 switch (T.zigTypeTag()) {25 switch (T.zigTypeTag()) {
26 .NoReturn => {26 .NoReturn => {
27 file.need_noreturn = true;27 try writer.writeAll("zig_noreturn void");
28 try writer.writeAll("noreturn void");
29 },28 },
30 .Void => try writer.writeAll("void"),29 .Void => try writer.writeAll("void"),
31 .Int => {30 .Int => {
src-self-hosted/link.zig-1
...@@ -202,7 +202,6 @@ pub const File = struct {...@@ -202,7 +202,6 @@ pub const File = struct {
202 called: std.StringHashMap(void),202 called: std.StringHashMap(void),
203 need_stddef: bool = false,203 need_stddef: bool = false,
204 need_stdint: bool = false,204 need_stdint: bool = false,
205 need_noreturn: bool = false,
206 error_msg: *Module.ErrorMsg = undefined,205 error_msg: *Module.ErrorMsg = undefined,
207206
208 pub fn openPath(allocator: *Allocator, dir: fs.Dir, sub_path: []const u8, options: Options) !*File {207 pub fn openPath(allocator: *Allocator, dir: fs.Dir, sub_path: []const u8, options: Options) !*File {
test/stage2/cbe.zig+8-9
...@@ -12,7 +12,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -12,7 +12,7 @@ pub fn addCases(ctx: *TestContext) !void {
12 ctx.c("empty start function", linux_x64,12 ctx.c("empty start function", linux_x64,
13 \\export fn _start() noreturn {}13 \\export fn _start() noreturn {}
14 ,14 ,
15 \\noreturn void _start(void) {}15 \\zig_noreturn void _start(void) {}
16 \\16 \\
17 );17 );
18 ctx.c("less empty start function", linux_x64,18 ctx.c("less empty start function", linux_x64,
...@@ -22,19 +22,19 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -22,19 +22,19 @@ pub fn addCases(ctx: *TestContext) !void {
22 \\ main();22 \\ main();
23 \\}23 \\}
24 ,24 ,
25 \\noreturn void main(void);25 \\zig_noreturn void main(void);
26 \\26 \\
27 \\noreturn void _start(void) {27 \\zig_noreturn void _start(void) {
28 \\ main();28 \\ main();
29 \\}29 \\}
30 \\30 \\
31 \\noreturn void main(void) {}31 \\zig_noreturn void main(void) {}
32 \\32 \\
33 );33 );
34 // TODO: implement return values34 // TODO: implement return values
35 // TODO: figure out a way to prevent asm constants from being generated35 // TODO: figure out a way to prevent asm constants from being generated
36 ctx.c("inline asm", linux_x64,36 ctx.c("inline asm", linux_x64,
37 \\fn exitGood() void {37 \\fn exitGood() noreturn {
38 \\ asm volatile ("syscall"38 \\ asm volatile ("syscall"
39 \\ :39 \\ :
40 \\ : [number] "{rax}" (231),40 \\ : [number] "{rax}" (231),
...@@ -48,21 +48,20 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -48,21 +48,20 @@ pub fn addCases(ctx: *TestContext) !void {
48 ,48 ,
49 \\#include <stddef.h>49 \\#include <stddef.h>
50 \\50 \\
51 \\void exitGood(void);51 \\zig_noreturn void exitGood(void);
52 \\52 \\
53 \\const char *const exitGood__anon_0 = "{rax}";53 \\const char *const exitGood__anon_0 = "{rax}";
54 \\const char *const exitGood__anon_1 = "{rdi}";54 \\const char *const exitGood__anon_1 = "{rdi}";
55 \\const char *const exitGood__anon_2 = "syscall";55 \\const char *const exitGood__anon_2 = "syscall";
56 \\56 \\
57 \\noreturn void _start(void) {57 \\zig_noreturn void _start(void) {
58 \\ exitGood();58 \\ exitGood();
59 \\}59 \\}
60 \\60 \\
61 \\void exitGood(void) {61 \\zig_noreturn void exitGood(void) {
62 \\ register size_t rax_constant __asm__("rax") = 231;62 \\ register size_t rax_constant __asm__("rax") = 231;
63 \\ register size_t rdi_constant __asm__("rdi") = 0;63 \\ register size_t rdi_constant __asm__("rdi") = 0;
64 \\ __asm volatile ("syscall" :: ""(rax_constant), ""(rdi_constant));64 \\ __asm volatile ("syscall" :: ""(rax_constant), ""(rdi_constant));
65 \\ return;
66 \\}65 \\}
67 \\66 \\
68 );67 );