authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-06 18:53:17-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-06 18:53:17-05:00
log633b6bf92055a62f8a18dbfdb1ddc4f7330bf4ec
tree3be9c09b1e6c0c3aff43fdc3d6d98948756de023
parent4e6ad8efd9fcefb820acf4a03fc4ab9157f85c1b
parentc0e8837ce9168088e89bfeef9516d7318cd5f97d
signature Commit is signed but in an unrecognized format.

Merge branch 'LemonBoy-cc-work'


120 files changed, 1015 insertions(+), 640 deletions(-)

doc/docgen.zig+1
...@@ -818,6 +818,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok...@@ -818,6 +818,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
818 .Keyword_resume,818 .Keyword_resume,
819 .Keyword_return,819 .Keyword_return,
820 .Keyword_linksection,820 .Keyword_linksection,
821 .Keyword_callconv,
821 .Keyword_stdcallcc,822 .Keyword_stdcallcc,
822 .Keyword_struct,823 .Keyword_struct,
823 .Keyword_suspend,824 .Keyword_suspend,
doc/langref.html.in+10-14
...@@ -2829,7 +2829,7 @@ test "@tagName" {...@@ -2829,7 +2829,7 @@ test "@tagName" {
2829 <p>2829 <p>
2830 By default, enums are not guaranteed to be compatible with the C ABI:2830 By default, enums are not guaranteed to be compatible with the C ABI:
2831 </p>2831 </p>
2832 {#code_begin|obj_err|parameter of type 'Foo' not allowed in function with calling convention 'ccc'#}2832 {#code_begin|obj_err|parameter of type 'Foo' not allowed in function with calling convention 'C'#}
2833const Foo = enum { A, B, C };2833const Foo = enum { A, B, C };
2834export fn entry(foo: Foo) void { }2834export fn entry(foo: Foo) void { }
2835 {#code_end#}2835 {#code_end#}
...@@ -3974,7 +3974,7 @@ test "noreturn" {...@@ -3974,7 +3974,7 @@ test "noreturn" {
3974 <p>Another use case for {#syntax#}noreturn{#endsyntax#} is the {#syntax#}exit{#endsyntax#} function:</p>3974 <p>Another use case for {#syntax#}noreturn{#endsyntax#} is the {#syntax#}exit{#endsyntax#} function:</p>
3975 {#code_begin|test#}3975 {#code_begin|test#}
3976 {#target_windows#}3976 {#target_windows#}
3977pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: c_uint) noreturn;3977pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(.Stdcall) noreturn;
39783978
3979test "foo" {3979test "foo" {
3980 const value = bar() catch ExitProcess(1);3980 const value = bar() catch ExitProcess(1);
...@@ -4008,8 +4008,8 @@ export fn sub(a: i8, b: i8) i8 { return a - b; }...@@ -4008,8 +4008,8 @@ export fn sub(a: i8, b: i8) i8 { return a - b; }
4008// The extern specifier is used to declare a function that will be resolved4008// The extern specifier is used to declare a function that will be resolved
4009// at link time, when linking statically, or at runtime, when linking4009// at link time, when linking statically, or at runtime, when linking
4010// dynamically.4010// dynamically.
4011// The stdcallcc specifier changes the calling convention of the function.4011// The callconv specifier changes the calling convention of the function.
4012extern "kernel32" stdcallcc fn ExitProcess(exit_code: u32) noreturn;4012extern "kernel32" fn ExitProcess(exit_code: u32) callconv(.Stdcall) noreturn;
4013extern "c" fn atan2(a: f64, b: f64) f64;4013extern "c" fn atan2(a: f64, b: f64) f64;
40144014
4015// The @setCold builtin tells the optimizer that a function is rarely called.4015// The @setCold builtin tells the optimizer that a function is rarely called.
...@@ -4018,9 +4018,9 @@ fn abort() noreturn {...@@ -4018,9 +4018,9 @@ fn abort() noreturn {
4018 while (true) {}4018 while (true) {}
4019}4019}
40204020
4021// The nakedcc specifier makes a function not have any function prologue or epilogue.4021// The naked calling convention makes a function not have any function prologue or epilogue.
4022// This can be useful when integrating with assembly.4022// This can be useful when integrating with assembly.
4023nakedcc fn _start() noreturn {4023fn _start() callconv(.Naked) noreturn {
4024 abort();4024 abort();
4025}4025}
40264026
...@@ -7735,7 +7735,7 @@ const Derp = @OpaqueType();...@@ -7735,7 +7735,7 @@ const Derp = @OpaqueType();
7735const Wat = @OpaqueType();7735const Wat = @OpaqueType();
77367736
7737extern fn bar(d: *Derp) void;7737extern fn bar(d: *Derp) void;
7738export fn foo(w: *Wat) void {7738fn foo(w: *Wat) callconv(.C) void {
7739 bar(w);7739 bar(w);
7740}7740}
77417741
...@@ -10382,9 +10382,7 @@ LinkSection &lt;- KEYWORD_linksection LPAREN Expr RPAREN...@@ -10382,9 +10382,7 @@ LinkSection &lt;- KEYWORD_linksection LPAREN Expr RPAREN
1038210382
10383# Fn specific10383# Fn specific
10384FnCC10384FnCC
10385 &lt;- KEYWORD_nakedcc10385 &lt;- KEYWORD_extern
10386 / KEYWORD_stdcallcc
10387 / KEYWORD_extern
10388 / KEYWORD_async10386 / KEYWORD_async
1038910387
10390ParamDecl &lt;- (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType10388ParamDecl &lt;- (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType
...@@ -10648,7 +10646,6 @@ KEYWORD_fn &lt;- 'fn' end_of_word...@@ -10648,7 +10646,6 @@ KEYWORD_fn &lt;- 'fn' end_of_word
10648KEYWORD_for &lt;- 'for' end_of_word10646KEYWORD_for &lt;- 'for' end_of_word
10649KEYWORD_if &lt;- 'if' end_of_word10647KEYWORD_if &lt;- 'if' end_of_word
10650KEYWORD_inline &lt;- 'inline' end_of_word10648KEYWORD_inline &lt;- 'inline' end_of_word
10651KEYWORD_nakedcc &lt;- 'nakedcc' end_of_word
10652KEYWORD_noalias &lt;- 'noalias' end_of_word10649KEYWORD_noalias &lt;- 'noalias' end_of_word
10653KEYWORD_null &lt;- 'null' end_of_word10650KEYWORD_null &lt;- 'null' end_of_word
10654KEYWORD_or &lt;- 'or' end_of_word10651KEYWORD_or &lt;- 'or' end_of_word
...@@ -10659,7 +10656,6 @@ KEYWORD_pub &lt;- 'pub' end_of_word...@@ -10659,7 +10656,6 @@ KEYWORD_pub &lt;- 'pub' end_of_word
10659KEYWORD_resume &lt;- 'resume' end_of_word10656KEYWORD_resume &lt;- 'resume' end_of_word
10660KEYWORD_return &lt;- 'return' end_of_word10657KEYWORD_return &lt;- 'return' end_of_word
10661KEYWORD_linksection &lt;- 'linksection' end_of_word10658KEYWORD_linksection &lt;- 'linksection' end_of_word
10662KEYWORD_stdcallcc &lt;- 'stdcallcc' end_of_word
10663KEYWORD_struct &lt;- 'struct' end_of_word10659KEYWORD_struct &lt;- 'struct' end_of_word
10664KEYWORD_suspend &lt;- 'suspend' end_of_word10660KEYWORD_suspend &lt;- 'suspend' end_of_word
10665KEYWORD_switch &lt;- 'switch' end_of_word10661KEYWORD_switch &lt;- 'switch' end_of_word
...@@ -10681,10 +10677,10 @@ keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_allowzero / KEYWORD_asm...@@ -10681,10 +10677,10 @@ keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_allowzero / KEYWORD_asm
10681 / KEYWORD_defer / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer10677 / KEYWORD_defer / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer
10682 / KEYWORD_error / KEYWORD_export / KEYWORD_extern / KEYWORD_false10678 / KEYWORD_error / KEYWORD_export / KEYWORD_extern / KEYWORD_false
10683 / KEYWORD_fn / KEYWORD_for / KEYWORD_if / KEYWORD_inline10679 / KEYWORD_fn / KEYWORD_for / KEYWORD_if / KEYWORD_inline
10684 / KEYWORD_nakedcc / KEYWORD_noalias / KEYWORD_null / KEYWORD_or10680 / KEYWORD_noalias / KEYWORD_null / KEYWORD_or
10685 / KEYWORD_orelse / KEYWORD_packed / KEYWORD_promise / KEYWORD_pub10681 / KEYWORD_orelse / KEYWORD_packed / KEYWORD_promise / KEYWORD_pub
10686 / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection10682 / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
10687 / KEYWORD_stdcallcc / KEYWORD_struct / KEYWORD_suspend10683 / KEYWORD_struct / KEYWORD_suspend
10688 / KEYWORD_switch / KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try10684 / KEYWORD_switch / KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try
10689 / KEYWORD_undefined / KEYWORD_union / KEYWORD_unreachable10685 / KEYWORD_undefined / KEYWORD_union / KEYWORD_unreachable
10690 / KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while</code></pre>10686 / KEYWORD_usingnamespace / KEYWORD_var / KEYWORD_volatile / KEYWORD_while</code></pre>
lib/std/build/translate_c.zig+23-9
...@@ -14,6 +14,7 @@ pub const TranslateCStep = struct {...@@ -14,6 +14,7 @@ pub const TranslateCStep = struct {
14 source: build.FileSource,14 source: build.FileSource,
15 output_dir: ?[]const u8,15 output_dir: ?[]const u8,
16 out_basename: []const u8,16 out_basename: []const u8,
17 target: std.Target = .Native,
1718
18 pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {19 pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
19 const self = builder.allocator.create(TranslateCStep) catch unreachable;20 const self = builder.allocator.create(TranslateCStep) catch unreachable;
...@@ -38,6 +39,10 @@ pub const TranslateCStep = struct {...@@ -38,6 +39,10 @@ pub const TranslateCStep = struct {
38 ) catch unreachable;39 ) catch unreachable;
39 }40 }
4041
42 pub fn setTarget(self: *TranslateCStep, target: std.Target) void {
43 self.target = target;
44 }
45
41 /// Creates a step to build an executable from the translated source.46 /// Creates a step to build an executable from the translated source.
42 pub fn addExecutable(self: *TranslateCStep) *LibExeObjStep {47 pub fn addExecutable(self: *TranslateCStep) *LibExeObjStep {
43 return self.builder.addExecutableSource("translated_c", @as(build.FileSource, .{ .translate_c = self }));48 return self.builder.addExecutableSource("translated_c", @as(build.FileSource, .{ .translate_c = self }));
...@@ -50,16 +55,25 @@ pub const TranslateCStep = struct {...@@ -50,16 +55,25 @@ pub const TranslateCStep = struct {
50 fn make(step: *Step) !void {55 fn make(step: *Step) !void {
51 const self = @fieldParentPtr(TranslateCStep, "step", step);56 const self = @fieldParentPtr(TranslateCStep, "step", step);
5257
53 const argv = [_][]const u8{58 var argv_list = std.ArrayList([]const u8).init(self.builder.allocator);
54 self.builder.zig_exe,59 try argv_list.append(self.builder.zig_exe);
55 "translate-c",60 try argv_list.append("translate-c");
56 "-lc",61 try argv_list.append("-lc");
57 "--cache",62
58 "on",63 try argv_list.append("--cache");
59 self.source.getPath(self.builder),64 try argv_list.append("on");
60 };65
66 switch (self.target) {
67 .Native => {},
68 .Cross => {
69 try argv_list.append("-target");
70 try argv_list.append(try self.target.zigTriple(self.builder.allocator));
71 },
72 }
73
74 try argv_list.append(self.source.getPath(self.builder));
6175
62 const output_path_nl = try self.builder.exec(&argv);76 const output_path_nl = try self.builder.exec(argv_list.toSliceConst());
63 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");77 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
6478
65 self.out_basename = fs.path.basename(output_path);79 self.out_basename = fs.path.basename(output_path);
lib/std/builtin.zig+19-12
...@@ -91,6 +91,25 @@ pub const Mode = enum {...@@ -91,6 +91,25 @@ pub const Mode = enum {
91 ReleaseSmall,91 ReleaseSmall,
92};92};
9393
94/// This data structure is used by the Zig language code generation and
95/// therefore must be kept in sync with the compiler implementation.
96pub const CallingConvention = enum {
97 Unspecified,
98 C,
99 Cold,
100 Naked,
101 Async,
102 Interrupt,
103 Signal,
104 Stdcall,
105 Fastcall,
106 Vectorcall,
107 Thiscall,
108 APCS,
109 AAPCS,
110 AAPCSVFP,
111};
112
94pub const TypeId = @TagType(TypeInfo);113pub const TypeId = @TagType(TypeInfo);
95114
96/// This data structure is used by the Zig language code generation and115/// This data structure is used by the Zig language code generation and
...@@ -253,17 +272,6 @@ pub const TypeInfo = union(enum) {...@@ -253,17 +272,6 @@ pub const TypeInfo = union(enum) {
253 decls: []Declaration,272 decls: []Declaration,
254 };273 };
255274
256 /// This data structure is used by the Zig language code generation and
257 /// therefore must be kept in sync with the compiler implementation.
258 pub const CallingConvention = enum {
259 Unspecified,
260 C,
261 Cold,
262 Naked,
263 Stdcall,
264 Async,
265 };
266
267 /// This data structure is used by the Zig language code generation and275 /// This data structure is used by the Zig language code generation and
268 /// therefore must be kept in sync with the compiler implementation.276 /// therefore must be kept in sync with the compiler implementation.
269 pub const FnArg = struct {277 pub const FnArg = struct {
...@@ -314,7 +322,6 @@ pub const TypeInfo = union(enum) {...@@ -314,7 +322,6 @@ pub const TypeInfo = union(enum) {
314 pub const FnDecl = struct {322 pub const FnDecl = struct {
315 fn_type: type,323 fn_type: type,
316 inline_type: Inline,324 inline_type: Inline,
317 calling_convention: CallingConvention,
318 is_var_args: bool,325 is_var_args: bool,
319 is_extern: bool,326 is_extern: bool,
320 is_export: bool,327 is_export: bool,
lib/std/debug.zig+2-2
...@@ -2428,7 +2428,7 @@ fn resetSegfaultHandler() void {...@@ -2428,7 +2428,7 @@ fn resetSegfaultHandler() void {
2428 os.sigaction(os.SIGILL, &act, null);2428 os.sigaction(os.SIGILL, &act, null);
2429}2429}
24302430
2431extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) noreturn {2431fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) callconv(.C) noreturn {
2432 // Reset to the default handler so that if a segfault happens in this handler it will crash2432 // Reset to the default handler so that if a segfault happens in this handler it will crash
2433 // the process. Also when this handler returns, the original instruction will be repeated2433 // the process. Also when this handler returns, the original instruction will be repeated
2434 // and the resulting segfault will crash the process rather than continually dump stack traces.2434 // and the resulting segfault will crash the process rather than continually dump stack traces.
...@@ -2475,7 +2475,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con...@@ -2475,7 +2475,7 @@ extern fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *con
2475 os.abort();2475 os.abort();
2476}2476}
24772477
2478stdcallcc fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) c_long {2478fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) callconv(.Stdcall) c_long {
2479 const exception_address = @ptrToInt(info.ExceptionRecord.ExceptionAddress);2479 const exception_address = @ptrToInt(info.ExceptionRecord.ExceptionAddress);
2480 switch (info.ExceptionRecord.ExceptionCode) {2480 switch (info.ExceptionRecord.ExceptionCode) {
2481 windows.EXCEPTION_DATATYPE_MISALIGNMENT => panicExtra(null, exception_address, "Unaligned Memory Access", .{}),2481 windows.EXCEPTION_DATATYPE_MISALIGNMENT => panicExtra(null, exception_address, "Unaligned Memory Access", .{}),
lib/std/json/test.zig+6-6
...@@ -22,7 +22,7 @@ fn err(comptime s: []const u8) void {...@@ -22,7 +22,7 @@ fn err(comptime s: []const u8) void {
22 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;22 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
23 var p = std.json.Parser.init(allocator, false);23 var p = std.json.Parser.init(allocator, false);
2424
25 if(p.parse(s)) |_| {25 if (p.parse(s)) |_| {
26 unreachable;26 unreachable;
27 } else |_| {}27 } else |_| {}
28}28}
...@@ -33,7 +33,7 @@ fn any(comptime s: []const u8) void {...@@ -33,7 +33,7 @@ fn any(comptime s: []const u8) void {
33 var mem_buffer: [1024 * 20]u8 = undefined;33 var mem_buffer: [1024 * 20]u8 = undefined;
34 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;34 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
35 var p = std.json.Parser.init(allocator, false);35 var p = std.json.Parser.init(allocator, false);
36 36
37 _ = p.parse(s) catch {};37 _ = p.parse(s) catch {};
38}38}
3939
...@@ -44,7 +44,7 @@ fn anyStreamingErrNonStreaming(comptime s: []const u8) void {...@@ -44,7 +44,7 @@ fn anyStreamingErrNonStreaming(comptime s: []const u8) void {
44 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;44 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buffer).allocator;
45 var p = std.json.Parser.init(allocator, false);45 var p = std.json.Parser.init(allocator, false);
4646
47 if(p.parse(s)) |_| {47 if (p.parse(s)) |_| {
48 unreachable;48 unreachable;
49 } else |_| {}49 } else |_| {}
50}50}
...@@ -1742,9 +1742,9 @@ test "i_number_double_huge_neg_exp" {...@@ -1742,9 +1742,9 @@ test "i_number_double_huge_neg_exp" {
1742test "i_number_huge_exp" {1742test "i_number_huge_exp" {
1743 return error.SkipZigTest;1743 return error.SkipZigTest;
1744 // FIXME Integer overflow in parseFloat1744 // FIXME Integer overflow in parseFloat
1745// any(1745 // any(
1746// \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]1746 // \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
1747// );1747 // );
1748}1748}
17491749
1750test "i_number_neg_int_huge_exp" {1750test "i_number_neg_int_huge_exp" {
lib/std/math/sqrt.zig-1
...@@ -70,4 +70,3 @@ pub fn Sqrt(comptime T: type) type {...@@ -70,4 +70,3 @@ pub fn Sqrt(comptime T: type) type {
70 else => T,70 else => T,
71 };71 };
72}72}
73
lib/std/mutex.zig+15-14
...@@ -17,7 +17,7 @@ const ResetEvent = std.ResetEvent;...@@ -17,7 +17,7 @@ const ResetEvent = std.ResetEvent;
17/// Example usage:17/// Example usage:
18/// var m = Mutex.init();18/// var m = Mutex.init();
19/// defer m.deinit();19/// defer m.deinit();
20/// 20///
21/// const lock = m.acquire();21/// const lock = m.acquire();
22/// defer lock.release();22/// defer lock.release();
23/// ... critical code23/// ... critical code
...@@ -73,8 +73,8 @@ pub const Mutex = if (builtin.single_threaded)...@@ -73,8 +73,8 @@ pub const Mutex = if (builtin.single_threaded)
73 return self.tryAcquire() orelse @panic("deadlock detected");73 return self.tryAcquire() orelse @panic("deadlock detected");
74 }74 }
75 }75 }
76else if (builtin.os == .windows) 76else if (builtin.os == .windows)
77 // https://locklessinc.com/articles/keyed_events/77// https://locklessinc.com/articles/keyed_events/
78 extern union {78 extern union {
79 locked: u8,79 locked: u8,
80 waiters: u32,80 waiters: u32,
...@@ -122,8 +122,8 @@ else if (builtin.os == .windows)...@@ -122,8 +122,8 @@ else if (builtin.os == .windows)
122 return Held{ .mutex = self };122 return Held{ .mutex = self };
123 }123 }
124124
125 // otherwise, try and update the waiting count.125 // otherwise, try and update the waiting count.
126 // then unset the WAKE bit so that another unlocker can wake up a thread.126 // then unset the WAKE bit so that another unlocker can wake up a thread.
127 } else if (@cmpxchgWeak(u32, &self.waiters, waiters, (waiters + WAIT) | 1, .Monotonic, .Monotonic) == null) {127 } else if (@cmpxchgWeak(u32, &self.waiters, waiters, (waiters + WAIT) | 1, .Monotonic, .Monotonic) == null) {
128 const rc = windows.ntdll.NtWaitForKeyedEvent(handle, key, windows.FALSE, null);128 const rc = windows.ntdll.NtWaitForKeyedEvent(handle, key, windows.FALSE, null);
129 assert(rc == 0);129 assert(rc == 0);
...@@ -143,7 +143,7 @@ else if (builtin.os == .windows)...@@ -143,7 +143,7 @@ else if (builtin.os == .windows)
143143
144 while (true) : (SpinLock.loopHint(1)) {144 while (true) : (SpinLock.loopHint(1)) {
145 const waiters = @atomicLoad(u32, &self.mutex.waiters, .Monotonic);145 const waiters = @atomicLoad(u32, &self.mutex.waiters, .Monotonic);
146 146
147 // no one is waiting147 // no one is waiting
148 if (waiters < WAIT) return;148 if (waiters < WAIT) return;
149 // someone grabbed the lock and will do the wake instead149 // someone grabbed the lock and will do the wake instead
...@@ -155,14 +155,14 @@ else if (builtin.os == .windows)...@@ -155,14 +155,14 @@ else if (builtin.os == .windows)
155 if (@cmpxchgWeak(u32, &self.mutex.waiters, waiters, waiters - WAIT + WAKE, .Release, .Monotonic) == null) {155 if (@cmpxchgWeak(u32, &self.mutex.waiters, waiters, waiters - WAIT + WAKE, .Release, .Monotonic) == null) {
156 const rc = windows.ntdll.NtReleaseKeyedEvent(handle, key, windows.FALSE, null);156 const rc = windows.ntdll.NtReleaseKeyedEvent(handle, key, windows.FALSE, null);
157 assert(rc == 0);157 assert(rc == 0);
158 return; 158 return;
159 }159 }
160 }160 }
161 }161 }
162 };162 };
163 }163 }
164else if (builtin.link_libc or builtin.os == .linux)164else if (builtin.link_libc or builtin.os == .linux)
165 // stack-based version of https://github.com/Amanieu/parking_lot/blob/master/core/src/word_lock.rs165// stack-based version of https://github.com/Amanieu/parking_lot/blob/master/core/src/word_lock.rs
166 struct {166 struct {
167 state: usize,167 state: usize,
168168
...@@ -195,8 +195,8 @@ else if (builtin.link_libc or builtin.os == .linux)...@@ -195,8 +195,8 @@ else if (builtin.link_libc or builtin.os == .linux)
195195
196 pub fn acquire(self: *Mutex) Held {196 pub fn acquire(self: *Mutex) Held {
197 return self.tryAcquire() orelse {197 return self.tryAcquire() orelse {
198 self.acquireSlow();198 self.acquireSlow();
199 return Held{ .mutex = self };199 return Held{ .mutex = self };
200 };200 };
201 }201 }
202202
...@@ -265,7 +265,7 @@ else if (builtin.link_libc or builtin.os == .linux)...@@ -265,7 +265,7 @@ else if (builtin.link_libc or builtin.os == .linux)
265265
266 fn releaseSlow(self: *Mutex) void {266 fn releaseSlow(self: *Mutex) void {
267 @setCold(true);267 @setCold(true);
268 268
269 // try and lock the LFIO queue to pop a node off,269 // try and lock the LFIO queue to pop a node off,
270 // stopping altogether if its already locked or the queue is empty270 // stopping altogether if its already locked or the queue is empty
271 var state = @atomicLoad(usize, &self.state, .Monotonic);271 var state = @atomicLoad(usize, &self.state, .Monotonic);
...@@ -293,9 +293,10 @@ else if (builtin.link_libc or builtin.os == .linux)...@@ -293,9 +293,10 @@ else if (builtin.link_libc or builtin.os == .linux)
293 }293 }
294 }294 }
295295
296// for platforms without a known OS blocking296 // for platforms without a known OS blocking
297// primitive, default to SpinLock for correctness297 // primitive, default to SpinLock for correctness
298else SpinLock;298else
299 SpinLock;
299300
300const TestContext = struct {301const TestContext = struct {
301 mutex: *Mutex,302 mutex: *Mutex,
lib/std/net.zig+1-5
...@@ -451,11 +451,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*...@@ -451,11 +451,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
451 .next = null,451 .next = null,
452 };452 };
453 var res: *os.addrinfo = undefined;453 var res: *os.addrinfo = undefined;
454 switch (os.system.getaddrinfo(454 switch (os.system.getaddrinfo(name_c.ptr, @ptrCast([*:0]const u8, port_c.ptr), &hints, &res)) {
455 name_c.ptr,
456 @ptrCast([*:0]const u8, port_c.ptr),
457 &hints,
458 &res)) {
459 0 => {},455 0 => {},
460 c.EAI_ADDRFAMILY => return error.HostLacksNetworkAddresses,456 c.EAI_ADDRFAMILY => return error.HostLacksNetworkAddresses,
461 c.EAI_AGAIN => return error.TemporaryNameServerFailure,457 c.EAI_AGAIN => return error.TemporaryNameServerFailure,
lib/std/os/linux.zig+1-1
...@@ -512,7 +512,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {...@@ -512,7 +512,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
512 return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));512 return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
513}513}
514514
515extern fn init_vdso_clock_gettime(clk: i32, ts: *timespec) usize {515fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
516 const ptr = @intToPtr(?*const c_void, vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM));516 const ptr = @intToPtr(?*const c_void, vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM));
517 // Note that we may not have a VDSO at all, update the stub address anyway517 // Note that we may not have a VDSO at all, update the stub address anyway
518 // so that clock_gettime will fall back on the good old (and slow) syscall518 // so that clock_gettime will fall back on the good old (and slow) syscall
lib/std/os/linux/arm-eabi.zig+3-3
...@@ -91,13 +91,13 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a...@@ -91,13 +91,13 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
91// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass91// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass
92// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883.92// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883.
93// LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig.93// LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig.
94pub extern fn getThreadPointer() usize {94pub fn getThreadPointer() callconv(.C) usize {
95 return asm volatile ("mrc p15, 0, %[ret], c13, c0, 3"95 return asm volatile ("mrc p15, 0, %[ret], c13, c0, 3"
96 : [ret] "=r" (-> usize)96 : [ret] "=r" (-> usize)
97 );97 );
98}98}
9999
100pub nakedcc fn restore() void {100pub fn restore() callconv(.Naked) void {
101 return asm volatile ("svc #0"101 return asm volatile ("svc #0"
102 :102 :
103 : [number] "{r7}" (@as(usize, SYS_sigreturn))103 : [number] "{r7}" (@as(usize, SYS_sigreturn))
...@@ -105,7 +105,7 @@ pub nakedcc fn restore() void {...@@ -105,7 +105,7 @@ pub nakedcc fn restore() void {
105 );105 );
106}106}
107107
108pub nakedcc fn restore_rt() void {108pub fn restore_rt() callconv(.Naked) void {
109 return asm volatile ("svc #0"109 return asm volatile ("svc #0"
110 :110 :
111 : [number] "{r7}" (@as(usize, SYS_rt_sigreturn))111 : [number] "{r7}" (@as(usize, SYS_rt_sigreturn))
lib/std/os/linux/arm64.zig+1-1
...@@ -90,7 +90,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a...@@ -90,7 +90,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
9090
91pub const restore = restore_rt;91pub const restore = restore_rt;
9292
93pub nakedcc fn restore_rt() void {93pub fn restore_rt() callconv(.Naked) void {
94 return asm volatile ("svc #0"94 return asm volatile ("svc #0"
95 :95 :
96 : [number] "{x8}" (@as(usize, SYS_rt_sigreturn))96 : [number] "{x8}" (@as(usize, SYS_rt_sigreturn))
lib/std/os/linux/i386.zig+2-2
...@@ -102,7 +102,7 @@ pub fn socketcall(call: usize, args: [*]usize) usize {...@@ -102,7 +102,7 @@ pub fn socketcall(call: usize, args: [*]usize) usize {
102/// This matches the libc clone function.102/// This matches the libc clone function.
103pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;103pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
104104
105pub nakedcc fn restore() void {105pub fn restore() callconv(.Naked) void {
106 return asm volatile ("int $0x80"106 return asm volatile ("int $0x80"
107 :107 :
108 : [number] "{eax}" (@as(usize, SYS_sigreturn))108 : [number] "{eax}" (@as(usize, SYS_sigreturn))
...@@ -110,7 +110,7 @@ pub nakedcc fn restore() void {...@@ -110,7 +110,7 @@ pub nakedcc fn restore() void {
110 );110 );
111}111}
112112
113pub nakedcc fn restore_rt() void {113pub fn restore_rt() callconv(.Naked) void {
114 return asm volatile ("int $0x80"114 return asm volatile ("int $0x80"
115 :115 :
116 : [number] "{eax}" (@as(usize, SYS_rt_sigreturn))116 : [number] "{eax}" (@as(usize, SYS_rt_sigreturn))
lib/std/os/linux/mipsel.zig+2-2
...@@ -144,7 +144,7 @@ pub fn syscall6(...@@ -144,7 +144,7 @@ pub fn syscall6(
144/// This matches the libc clone function.144/// This matches the libc clone function.
145pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;145pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
146146
147pub nakedcc fn restore() void {147pub fn restore() callconv(.Naked) void {
148 return asm volatile ("syscall"148 return asm volatile ("syscall"
149 :149 :
150 : [number] "{$2}" (@as(usize, SYS_sigreturn))150 : [number] "{$2}" (@as(usize, SYS_sigreturn))
...@@ -152,7 +152,7 @@ pub nakedcc fn restore() void {...@@ -152,7 +152,7 @@ pub nakedcc fn restore() void {
152 );152 );
153}153}
154154
155pub nakedcc fn restore_rt() void {155pub fn restore_rt() callconv(.Naked) void {
156 return asm volatile ("syscall"156 return asm volatile ("syscall"
157 :157 :
158 : [number] "{$2}" (@as(usize, SYS_rt_sigreturn))158 : [number] "{$2}" (@as(usize, SYS_rt_sigreturn))
lib/std/os/linux/riscv64.zig+1-1
...@@ -89,7 +89,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a...@@ -89,7 +89,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
8989
90pub const restore = restore_rt;90pub const restore = restore_rt;
9191
92pub nakedcc fn restore_rt() void {92pub fn restore_rt() callconv(.Naked) void {
93 return asm volatile ("ecall"93 return asm volatile ("ecall"
94 :94 :
95 : [number] "{x17}" (@as(usize, SYS_rt_sigreturn))95 : [number] "{x17}" (@as(usize, SYS_rt_sigreturn))
lib/std/os/linux/x86_64.zig+1-1
...@@ -90,7 +90,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: usize,...@@ -90,7 +90,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: usize,
9090
91pub const restore = restore_rt;91pub const restore = restore_rt;
9292
93pub nakedcc fn restore_rt() void {93pub fn restore_rt() callconv(.Naked) void {
94 return asm volatile ("syscall"94 return asm volatile ("syscall"
95 :95 :
96 : [number] "{rax}" (@as(usize, SYS_rt_sigreturn))96 : [number] "{rax}" (@as(usize, SYS_rt_sigreturn))
lib/std/os/test.zig+1-1
...@@ -166,7 +166,7 @@ test "sigaltstack" {...@@ -166,7 +166,7 @@ test "sigaltstack" {
166// analyzed166// analyzed
167const dl_phdr_info = if (@hasDecl(os, "dl_phdr_info")) os.dl_phdr_info else c_void;167const dl_phdr_info = if (@hasDecl(os, "dl_phdr_info")) os.dl_phdr_info else c_void;
168168
169export fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) i32 {169fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) callconv(.C) i32 {
170 if (builtin.os == .windows or builtin.os == .wasi or builtin.os == .macosx)170 if (builtin.os == .windows or builtin.os == .wasi or builtin.os == .macosx)
171 return 0;171 return 0;
172172
lib/std/os/uefi/protocols/simple_text_input_protocol.zig-1
...@@ -27,4 +27,3 @@ pub const SimpleTextInputProtocol = extern struct {...@@ -27,4 +27,3 @@ pub const SimpleTextInputProtocol = extern struct {
27 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },27 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
28 };28 };
29};29};
30
lib/std/os/windows/advapi32.zig+5-5
...@@ -1,23 +1,23 @@...@@ -1,23 +1,23 @@
1usingnamespace @import("bits.zig");1usingnamespace @import("bits.zig");
22
3pub extern "advapi32" stdcallcc fn RegOpenKeyExW(3pub extern "advapi32" fn RegOpenKeyExW(
4 hKey: HKEY,4 hKey: HKEY,
5 lpSubKey: LPCWSTR,5 lpSubKey: LPCWSTR,
6 ulOptions: DWORD,6 ulOptions: DWORD,
7 samDesired: REGSAM,7 samDesired: REGSAM,
8 phkResult: *HKEY,8 phkResult: *HKEY,
9) LSTATUS;9) callconv(.Stdcall) LSTATUS;
1010
11pub extern "advapi32" stdcallcc fn RegQueryValueExW(11pub extern "advapi32" fn RegQueryValueExW(
12 hKey: HKEY,12 hKey: HKEY,
13 lpValueName: LPCWSTR,13 lpValueName: LPCWSTR,
14 lpReserved: LPDWORD,14 lpReserved: LPDWORD,
15 lpType: LPDWORD,15 lpType: LPDWORD,
16 lpData: LPBYTE,16 lpData: LPBYTE,
17 lpcbData: LPDWORD,17 lpcbData: LPDWORD,
18) LSTATUS;18) callconv(.Stdcall) LSTATUS;
1919
20// RtlGenRandom is known as SystemFunction036 under advapi3220// RtlGenRandom is known as SystemFunction036 under advapi32
21// http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx */21// http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx */
22pub extern "advapi32" stdcallcc fn SystemFunction036(output: [*]u8, length: ULONG) BOOL;22pub extern "advapi32" fn SystemFunction036(output: [*]u8, length: ULONG) callconv(.Stdcall) BOOL;
23pub const RtlGenRandom = SystemFunction036;23pub const RtlGenRandom = SystemFunction036;
lib/std/os/windows/bits.zig+1-1
...@@ -892,7 +892,7 @@ pub const EXCEPTION_POINTERS = extern struct {...@@ -892,7 +892,7 @@ pub const EXCEPTION_POINTERS = extern struct {
892 ContextRecord: *c_void,892 ContextRecord: *c_void,
893};893};
894894
895pub const VECTORED_EXCEPTION_HANDLER = stdcallcc fn (ExceptionInfo: *EXCEPTION_POINTERS) c_long;895pub const VECTORED_EXCEPTION_HANDLER = fn (ExceptionInfo: *EXCEPTION_POINTERS) callconv(.Stdcall) c_long;
896896
897pub const OBJECT_ATTRIBUTES = extern struct {897pub const OBJECT_ATTRIBUTES = extern struct {
898 Length: ULONG,898 Length: ULONG,
lib/std/os/windows/kernel32.zig+100-100
...@@ -1,22 +1,22 @@...@@ -1,22 +1,22 @@
1usingnamespace @import("bits.zig");1usingnamespace @import("bits.zig");
22
3pub extern "kernel32" stdcallcc fn AddVectoredExceptionHandler(First: c_ulong, Handler: ?VECTORED_EXCEPTION_HANDLER) ?*c_void;3pub extern "kernel32" fn AddVectoredExceptionHandler(First: c_ulong, Handler: ?VECTORED_EXCEPTION_HANDLER) callconv(.Stdcall) ?*c_void;
4pub extern "kernel32" stdcallcc fn RemoveVectoredExceptionHandler(Handle: HANDLE) c_ulong;4pub extern "kernel32" fn RemoveVectoredExceptionHandler(Handle: HANDLE) callconv(.Stdcall) c_ulong;
55
6pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) BOOL;6pub extern "kernel32" fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) callconv(.Stdcall) BOOL;
77
8pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) BOOL;8pub extern "kernel32" fn CloseHandle(hObject: HANDLE) callconv(.Stdcall) BOOL;
99
10pub extern "kernel32" stdcallcc fn CreateDirectoryW(lpPathName: [*]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) BOOL;10pub extern "kernel32" fn CreateDirectoryW(lpPathName: [*]const u16, lpSecurityAttributes: ?*SECURITY_ATTRIBUTES) callconv(.Stdcall) BOOL;
1111
12pub extern "kernel32" stdcallcc fn CreateEventExW(12pub extern "kernel32" fn CreateEventExW(
13 lpEventAttributes: ?*SECURITY_ATTRIBUTES,13 lpEventAttributes: ?*SECURITY_ATTRIBUTES,
14 lpName: [*:0]const u16,14 lpName: [*:0]const u16,
15 dwFlags: DWORD,15 dwFlags: DWORD,
16 dwDesiredAccess: DWORD,16 dwDesiredAccess: DWORD,
17) ?HANDLE;17) callconv(.Stdcall) ?HANDLE;
1818
19pub extern "kernel32" stdcallcc fn CreateFileW(19pub extern "kernel32" fn CreateFileW(
20 lpFileName: [*]const u16, // TODO null terminated pointer type20 lpFileName: [*]const u16, // TODO null terminated pointer type
21 dwDesiredAccess: DWORD,21 dwDesiredAccess: DWORD,
22 dwShareMode: DWORD,22 dwShareMode: DWORD,
...@@ -24,16 +24,16 @@ pub extern "kernel32" stdcallcc fn CreateFileW(...@@ -24,16 +24,16 @@ pub extern "kernel32" stdcallcc fn CreateFileW(
24 dwCreationDisposition: DWORD,24 dwCreationDisposition: DWORD,
25 dwFlagsAndAttributes: DWORD,25 dwFlagsAndAttributes: DWORD,
26 hTemplateFile: ?HANDLE,26 hTemplateFile: ?HANDLE,
27) HANDLE;27) callconv(.Stdcall) HANDLE;
2828
29pub extern "kernel32" stdcallcc fn CreatePipe(29pub extern "kernel32" fn CreatePipe(
30 hReadPipe: *HANDLE,30 hReadPipe: *HANDLE,
31 hWritePipe: *HANDLE,31 hWritePipe: *HANDLE,
32 lpPipeAttributes: *const SECURITY_ATTRIBUTES,32 lpPipeAttributes: *const SECURITY_ATTRIBUTES,
33 nSize: DWORD,33 nSize: DWORD,
34) BOOL;34) callconv(.Stdcall) BOOL;
3535
36pub extern "kernel32" stdcallcc fn CreateProcessW(36pub extern "kernel32" fn CreateProcessW(
37 lpApplicationName: ?LPWSTR,37 lpApplicationName: ?LPWSTR,
38 lpCommandLine: LPWSTR,38 lpCommandLine: LPWSTR,
39 lpProcessAttributes: ?*SECURITY_ATTRIBUTES,39 lpProcessAttributes: ?*SECURITY_ATTRIBUTES,
...@@ -44,15 +44,15 @@ pub extern "kernel32" stdcallcc fn CreateProcessW(...@@ -44,15 +44,15 @@ pub extern "kernel32" stdcallcc fn CreateProcessW(
44 lpCurrentDirectory: ?LPWSTR,44 lpCurrentDirectory: ?LPWSTR,
45 lpStartupInfo: *STARTUPINFOW,45 lpStartupInfo: *STARTUPINFOW,
46 lpProcessInformation: *PROCESS_INFORMATION,46 lpProcessInformation: *PROCESS_INFORMATION,
47) BOOL;47) callconv(.Stdcall) BOOL;
4848
49pub extern "kernel32" stdcallcc fn CreateSymbolicLinkW(lpSymlinkFileName: [*]const u16, lpTargetFileName: [*]const u16, dwFlags: DWORD) BOOLEAN;49pub extern "kernel32" fn CreateSymbolicLinkW(lpSymlinkFileName: [*]const u16, lpTargetFileName: [*]const u16, dwFlags: DWORD) callconv(.Stdcall) BOOLEAN;
5050
51pub extern "kernel32" stdcallcc fn CreateIoCompletionPort(FileHandle: HANDLE, ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD) ?HANDLE;51pub extern "kernel32" fn CreateIoCompletionPort(FileHandle: HANDLE, ExistingCompletionPort: ?HANDLE, CompletionKey: ULONG_PTR, NumberOfConcurrentThreads: DWORD) callconv(.Stdcall) ?HANDLE;
5252
53pub extern "kernel32" stdcallcc fn CreateThread(lpThreadAttributes: ?LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, lpStartAddress: LPTHREAD_START_ROUTINE, lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?LPDWORD) ?HANDLE;53pub extern "kernel32" fn CreateThread(lpThreadAttributes: ?LPSECURITY_ATTRIBUTES, dwStackSize: SIZE_T, lpStartAddress: LPTHREAD_START_ROUTINE, lpParameter: ?LPVOID, dwCreationFlags: DWORD, lpThreadId: ?LPDWORD) callconv(.Stdcall) ?HANDLE;
5454
55pub extern "kernel32" stdcallcc fn DeviceIoControl(55pub extern "kernel32" fn DeviceIoControl(
56 h: HANDLE,56 h: HANDLE,
57 dwIoControlCode: DWORD,57 dwIoControlCode: DWORD,
58 lpInBuffer: ?*const c_void,58 lpInBuffer: ?*const c_void,
...@@ -61,107 +61,107 @@ pub extern "kernel32" stdcallcc fn DeviceIoControl(...@@ -61,107 +61,107 @@ pub extern "kernel32" stdcallcc fn DeviceIoControl(
61 nOutBufferSize: DWORD,61 nOutBufferSize: DWORD,
62 lpBytesReturned: ?*DWORD,62 lpBytesReturned: ?*DWORD,
63 lpOverlapped: ?*OVERLAPPED,63 lpOverlapped: ?*OVERLAPPED,
64) BOOL;64) callconv(.Stdcall) BOOL;
6565
66pub extern "kernel32" stdcallcc fn DeleteFileW(lpFileName: [*]const u16) BOOL;66pub extern "kernel32" fn DeleteFileW(lpFileName: [*]const u16) callconv(.Stdcall) BOOL;
6767
68pub extern "kernel32" stdcallcc fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) BOOL;68pub extern "kernel32" fn DuplicateHandle(hSourceProcessHandle: HANDLE, hSourceHandle: HANDLE, hTargetProcessHandle: HANDLE, lpTargetHandle: *HANDLE, dwDesiredAccess: DWORD, bInheritHandle: BOOL, dwOptions: DWORD) callconv(.Stdcall) BOOL;
6969
70pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) noreturn;70pub extern "kernel32" fn ExitProcess(exit_code: UINT) callconv(.Stdcall) noreturn;
7171
72pub extern "kernel32" stdcallcc fn FindFirstFileW(lpFileName: [*]const u16, lpFindFileData: *WIN32_FIND_DATAW) HANDLE;72pub extern "kernel32" fn FindFirstFileW(lpFileName: [*]const u16, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) HANDLE;
73pub extern "kernel32" stdcallcc fn FindClose(hFindFile: HANDLE) BOOL;73pub extern "kernel32" fn FindClose(hFindFile: HANDLE) callconv(.Stdcall) BOOL;
74pub extern "kernel32" stdcallcc fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) BOOL;74pub extern "kernel32" fn FindNextFileW(hFindFile: HANDLE, lpFindFileData: *WIN32_FIND_DATAW) callconv(.Stdcall) BOOL;
7575
76pub extern "kernel32" stdcallcc fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) DWORD;76pub extern "kernel32" fn FormatMessageW(dwFlags: DWORD, lpSource: ?LPVOID, dwMessageId: DWORD, dwLanguageId: DWORD, lpBuffer: LPWSTR, nSize: DWORD, Arguments: ?*va_list) callconv(.Stdcall) DWORD;
7777
78pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsW(penv: [*]u16) BOOL;78pub extern "kernel32" fn FreeEnvironmentStringsW(penv: [*]u16) callconv(.Stdcall) BOOL;
7979
80pub extern "kernel32" stdcallcc fn GetCommandLineA() LPSTR;80pub extern "kernel32" fn GetCommandLineA() callconv(.Stdcall) LPSTR;
8181
82pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: *DWORD) BOOL;82pub extern "kernel32" fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: *DWORD) callconv(.Stdcall) BOOL;
8383
84pub extern "kernel32" stdcallcc fn GetConsoleScreenBufferInfo(hConsoleOutput: HANDLE, lpConsoleScreenBufferInfo: *CONSOLE_SCREEN_BUFFER_INFO) BOOL;84pub extern "kernel32" fn GetConsoleScreenBufferInfo(hConsoleOutput: HANDLE, lpConsoleScreenBufferInfo: *CONSOLE_SCREEN_BUFFER_INFO) callconv(.Stdcall) BOOL;
8585
86pub extern "kernel32" stdcallcc fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: ?[*]WCHAR) DWORD;86pub extern "kernel32" fn GetCurrentDirectoryW(nBufferLength: DWORD, lpBuffer: ?[*]WCHAR) callconv(.Stdcall) DWORD;
8787
88pub extern "kernel32" stdcallcc fn GetCurrentThread() HANDLE;88pub extern "kernel32" fn GetCurrentThread() callconv(.Stdcall) HANDLE;
89pub extern "kernel32" stdcallcc fn GetCurrentThreadId() DWORD;89pub extern "kernel32" fn GetCurrentThreadId() callconv(.Stdcall) DWORD;
9090
91pub extern "kernel32" stdcallcc fn GetEnvironmentStringsW() ?[*]u16;91pub extern "kernel32" fn GetEnvironmentStringsW() callconv(.Stdcall) ?[*]u16;
9292
93pub extern "kernel32" stdcallcc fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) DWORD;93pub extern "kernel32" fn GetEnvironmentVariableW(lpName: LPWSTR, lpBuffer: LPWSTR, nSize: DWORD) callconv(.Stdcall) DWORD;
9494
95pub extern "kernel32" stdcallcc fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) BOOL;95pub extern "kernel32" fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: *DWORD) callconv(.Stdcall) BOOL;
9696
97pub extern "kernel32" stdcallcc fn GetFileSizeEx(hFile: HANDLE, lpFileSize: *LARGE_INTEGER) BOOL;97pub extern "kernel32" fn GetFileSizeEx(hFile: HANDLE, lpFileSize: *LARGE_INTEGER) callconv(.Stdcall) BOOL;
9898
99pub extern "kernel32" stdcallcc fn GetFileAttributesW(lpFileName: [*]const WCHAR) DWORD;99pub extern "kernel32" fn GetFileAttributesW(lpFileName: [*]const WCHAR) callconv(.Stdcall) DWORD;
100100
101pub extern "kernel32" stdcallcc fn GetModuleFileNameW(hModule: ?HMODULE, lpFilename: [*]u16, nSize: DWORD) DWORD;101pub extern "kernel32" fn GetModuleFileNameW(hModule: ?HMODULE, lpFilename: [*]u16, nSize: DWORD) callconv(.Stdcall) DWORD;
102102
103pub extern "kernel32" stdcallcc fn GetModuleHandleW(lpModuleName: ?[*]const WCHAR) HMODULE;103pub extern "kernel32" fn GetModuleHandleW(lpModuleName: ?[*]const WCHAR) callconv(.Stdcall) HMODULE;
104104
105pub extern "kernel32" stdcallcc fn GetLastError() DWORD;105pub extern "kernel32" fn GetLastError() callconv(.Stdcall) DWORD;
106106
107pub extern "kernel32" stdcallcc fn GetFileInformationByHandle(107pub extern "kernel32" fn GetFileInformationByHandle(
108 hFile: HANDLE,108 hFile: HANDLE,
109 lpFileInformation: *BY_HANDLE_FILE_INFORMATION,109 lpFileInformation: *BY_HANDLE_FILE_INFORMATION,
110) BOOL;110) callconv(.Stdcall) BOOL;
111111
112pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(112pub extern "kernel32" fn GetFileInformationByHandleEx(
113 in_hFile: HANDLE,113 in_hFile: HANDLE,
114 in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,114 in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
115 out_lpFileInformation: *c_void,115 out_lpFileInformation: *c_void,
116 in_dwBufferSize: DWORD,116 in_dwBufferSize: DWORD,
117) BOOL;117) callconv(.Stdcall) BOOL;
118118
119pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleW(119pub extern "kernel32" fn GetFinalPathNameByHandleW(
120 hFile: HANDLE,120 hFile: HANDLE,
121 lpszFilePath: [*]u16,121 lpszFilePath: [*]u16,
122 cchFilePath: DWORD,122 cchFilePath: DWORD,
123 dwFlags: DWORD,123 dwFlags: DWORD,
124) DWORD;124) callconv(.Stdcall) DWORD;
125125
126pub extern "kernel32" stdcallcc fn GetOverlappedResult(hFile: HANDLE, lpOverlapped: *OVERLAPPED, lpNumberOfBytesTransferred: *DWORD, bWait: BOOL) BOOL;126pub extern "kernel32" fn GetOverlappedResult(hFile: HANDLE, lpOverlapped: *OVERLAPPED, lpNumberOfBytesTransferred: *DWORD, bWait: BOOL) callconv(.Stdcall) BOOL;
127127
128pub extern "kernel32" stdcallcc fn GetProcessHeap() ?HANDLE;128pub extern "kernel32" fn GetProcessHeap() callconv(.Stdcall) ?HANDLE;
129pub extern "kernel32" stdcallcc fn GetQueuedCompletionStatus(CompletionPort: HANDLE, lpNumberOfBytesTransferred: LPDWORD, lpCompletionKey: *ULONG_PTR, lpOverlapped: *?*OVERLAPPED, dwMilliseconds: DWORD) BOOL;129pub extern "kernel32" fn GetQueuedCompletionStatus(CompletionPort: HANDLE, lpNumberOfBytesTransferred: LPDWORD, lpCompletionKey: *ULONG_PTR, lpOverlapped: *?*OVERLAPPED, dwMilliseconds: DWORD) callconv(.Stdcall) BOOL;
130130
131pub extern "kernel32" stdcallcc fn GetSystemInfo(lpSystemInfo: *SYSTEM_INFO) void;131pub extern "kernel32" fn GetSystemInfo(lpSystemInfo: *SYSTEM_INFO) callconv(.Stdcall) void;
132pub extern "kernel32" stdcallcc fn GetSystemTimeAsFileTime(*FILETIME) void;132pub extern "kernel32" fn GetSystemTimeAsFileTime(*FILETIME) callconv(.Stdcall) void;
133133
134pub extern "kernel32" stdcallcc fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) ?HANDLE;134pub extern "kernel32" fn HeapCreate(flOptions: DWORD, dwInitialSize: SIZE_T, dwMaximumSize: SIZE_T) callconv(.Stdcall) ?HANDLE;
135pub extern "kernel32" stdcallcc fn HeapDestroy(hHeap: HANDLE) BOOL;135pub extern "kernel32" fn HeapDestroy(hHeap: HANDLE) callconv(.Stdcall) BOOL;
136pub extern "kernel32" stdcallcc fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void, dwBytes: SIZE_T) ?*c_void;136pub extern "kernel32" fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void, dwBytes: SIZE_T) callconv(.Stdcall) ?*c_void;
137pub extern "kernel32" stdcallcc fn HeapSize(hHeap: HANDLE, dwFlags: DWORD, lpMem: *const c_void) SIZE_T;137pub extern "kernel32" fn HeapSize(hHeap: HANDLE, dwFlags: DWORD, lpMem: *const c_void) callconv(.Stdcall) SIZE_T;
138pub extern "kernel32" stdcallcc fn HeapCompact(hHeap: HANDLE, dwFlags: DWORD) SIZE_T;138pub extern "kernel32" fn HeapCompact(hHeap: HANDLE, dwFlags: DWORD) callconv(.Stdcall) SIZE_T;
139pub extern "kernel32" stdcallcc fn HeapSummary(hHeap: HANDLE, dwFlags: DWORD, lpSummary: LPHEAP_SUMMARY) BOOL;139pub extern "kernel32" fn HeapSummary(hHeap: HANDLE, dwFlags: DWORD, lpSummary: LPHEAP_SUMMARY) callconv(.Stdcall) BOOL;
140140
141pub extern "kernel32" stdcallcc fn GetStdHandle(in_nStdHandle: DWORD) ?HANDLE;141pub extern "kernel32" fn GetStdHandle(in_nStdHandle: DWORD) callconv(.Stdcall) ?HANDLE;
142142
143pub extern "kernel32" stdcallcc fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) ?*c_void;143pub extern "kernel32" fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) callconv(.Stdcall) ?*c_void;
144144
145pub extern "kernel32" stdcallcc fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void) BOOL;145pub extern "kernel32" fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: *c_void) callconv(.Stdcall) BOOL;
146146
147pub extern "kernel32" stdcallcc fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: ?*const c_void) BOOL;147pub extern "kernel32" fn HeapValidate(hHeap: HANDLE, dwFlags: DWORD, lpMem: ?*const c_void) callconv(.Stdcall) BOOL;
148148
149pub extern "kernel32" stdcallcc fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD) ?LPVOID;149pub extern "kernel32" fn VirtualAlloc(lpAddress: ?LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD) callconv(.Stdcall) ?LPVOID;
150pub extern "kernel32" stdcallcc fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) BOOL;150pub extern "kernel32" fn VirtualFree(lpAddress: ?LPVOID, dwSize: SIZE_T, dwFreeType: DWORD) callconv(.Stdcall) BOOL;
151151
152pub extern "kernel32" stdcallcc fn MoveFileExW(152pub extern "kernel32" fn MoveFileExW(
153 lpExistingFileName: [*]const u16,153 lpExistingFileName: [*]const u16,
154 lpNewFileName: [*]const u16,154 lpNewFileName: [*]const u16,
155 dwFlags: DWORD,155 dwFlags: DWORD,
156) BOOL;156) callconv(.Stdcall) BOOL;
157157
158pub extern "kernel32" stdcallcc fn PostQueuedCompletionStatus(CompletionPort: HANDLE, dwNumberOfBytesTransferred: DWORD, dwCompletionKey: ULONG_PTR, lpOverlapped: ?*OVERLAPPED) BOOL;158pub extern "kernel32" fn PostQueuedCompletionStatus(CompletionPort: HANDLE, dwNumberOfBytesTransferred: DWORD, dwCompletionKey: ULONG_PTR, lpOverlapped: ?*OVERLAPPED) callconv(.Stdcall) BOOL;
159159
160pub extern "kernel32" stdcallcc fn QueryPerformanceCounter(lpPerformanceCount: *LARGE_INTEGER) BOOL;160pub extern "kernel32" fn QueryPerformanceCounter(lpPerformanceCount: *LARGE_INTEGER) callconv(.Stdcall) BOOL;
161161
162pub extern "kernel32" stdcallcc fn QueryPerformanceFrequency(lpFrequency: *LARGE_INTEGER) BOOL;162pub extern "kernel32" fn QueryPerformanceFrequency(lpFrequency: *LARGE_INTEGER) callconv(.Stdcall) BOOL;
163163
164pub extern "kernel32" stdcallcc fn ReadDirectoryChangesW(164pub extern "kernel32" fn ReadDirectoryChangesW(
165 hDirectory: HANDLE,165 hDirectory: HANDLE,
166 lpBuffer: [*]align(@alignOf(FILE_NOTIFY_INFORMATION)) u8,166 lpBuffer: [*]align(@alignOf(FILE_NOTIFY_INFORMATION)) u8,
167 nBufferLength: DWORD,167 nBufferLength: DWORD,
...@@ -170,79 +170,79 @@ pub extern "kernel32" stdcallcc fn ReadDirectoryChangesW(...@@ -170,79 +170,79 @@ pub extern "kernel32" stdcallcc fn ReadDirectoryChangesW(
170 lpBytesReturned: ?*DWORD,170 lpBytesReturned: ?*DWORD,
171 lpOverlapped: ?*OVERLAPPED,171 lpOverlapped: ?*OVERLAPPED,
172 lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE,172 lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE,
173) BOOL;173) callconv(.Stdcall) BOOL;
174174
175pub extern "kernel32" stdcallcc fn ReadFile(175pub extern "kernel32" fn ReadFile(
176 in_hFile: HANDLE,176 in_hFile: HANDLE,
177 out_lpBuffer: [*]u8,177 out_lpBuffer: [*]u8,
178 in_nNumberOfBytesToRead: DWORD,178 in_nNumberOfBytesToRead: DWORD,
179 out_lpNumberOfBytesRead: ?*DWORD,179 out_lpNumberOfBytesRead: ?*DWORD,
180 in_out_lpOverlapped: ?*OVERLAPPED,180 in_out_lpOverlapped: ?*OVERLAPPED,
181) BOOL;181) callconv(.Stdcall) BOOL;
182182
183pub extern "kernel32" stdcallcc fn RemoveDirectoryW(lpPathName: [*]const u16) BOOL;183pub extern "kernel32" fn RemoveDirectoryW(lpPathName: [*]const u16) callconv(.Stdcall) BOOL;
184184
185pub extern "kernel32" stdcallcc fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) BOOL;185pub extern "kernel32" fn SetConsoleTextAttribute(hConsoleOutput: HANDLE, wAttributes: WORD) callconv(.Stdcall) BOOL;
186186
187pub extern "kernel32" stdcallcc fn SetFilePointerEx(187pub extern "kernel32" fn SetFilePointerEx(
188 in_fFile: HANDLE,188 in_fFile: HANDLE,
189 in_liDistanceToMove: LARGE_INTEGER,189 in_liDistanceToMove: LARGE_INTEGER,
190 out_opt_ldNewFilePointer: ?*LARGE_INTEGER,190 out_opt_ldNewFilePointer: ?*LARGE_INTEGER,
191 in_dwMoveMethod: DWORD,191 in_dwMoveMethod: DWORD,
192) BOOL;192) callconv(.Stdcall) BOOL;
193193
194pub extern "kernel32" stdcallcc fn SetFileTime(194pub extern "kernel32" fn SetFileTime(
195 hFile: HANDLE,195 hFile: HANDLE,
196 lpCreationTime: ?*const FILETIME,196 lpCreationTime: ?*const FILETIME,
197 lpLastAccessTime: ?*const FILETIME,197 lpLastAccessTime: ?*const FILETIME,
198 lpLastWriteTime: ?*const FILETIME,198 lpLastWriteTime: ?*const FILETIME,
199) BOOL;199) callconv(.Stdcall) BOOL;
200200
201pub extern "kernel32" stdcallcc fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) BOOL;201pub extern "kernel32" fn SetHandleInformation(hObject: HANDLE, dwMask: DWORD, dwFlags: DWORD) callconv(.Stdcall) BOOL;
202202
203pub extern "kernel32" stdcallcc fn Sleep(dwMilliseconds: DWORD) void;203pub extern "kernel32" fn Sleep(dwMilliseconds: DWORD) callconv(.Stdcall) void;
204204
205pub extern "kernel32" stdcallcc fn SwitchToThread() BOOL;205pub extern "kernel32" fn SwitchToThread() callconv(.Stdcall) BOOL;
206206
207pub extern "kernel32" stdcallcc fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) BOOL;207pub extern "kernel32" fn TerminateProcess(hProcess: HANDLE, uExitCode: UINT) callconv(.Stdcall) BOOL;
208208
209pub extern "kernel32" stdcallcc fn TlsAlloc() DWORD;209pub extern "kernel32" fn TlsAlloc() callconv(.Stdcall) DWORD;
210210
211pub extern "kernel32" stdcallcc fn TlsFree(dwTlsIndex: DWORD) BOOL;211pub extern "kernel32" fn TlsFree(dwTlsIndex: DWORD) callconv(.Stdcall) BOOL;
212212
213pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) DWORD;213pub extern "kernel32" fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) callconv(.Stdcall) DWORD;
214214
215pub extern "kernel32" stdcallcc fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) DWORD;215pub extern "kernel32" fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) callconv(.Stdcall) DWORD;
216216
217pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll: BOOL, dwMilliseconds: DWORD) DWORD;217pub extern "kernel32" fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll: BOOL, dwMilliseconds: DWORD) callconv(.Stdcall) DWORD;
218218
219pub extern "kernel32" stdcallcc fn WaitForMultipleObjectsEx(219pub extern "kernel32" fn WaitForMultipleObjectsEx(
220 nCount: DWORD,220 nCount: DWORD,
221 lpHandle: [*]const HANDLE,221 lpHandle: [*]const HANDLE,
222 bWaitAll: BOOL,222 bWaitAll: BOOL,
223 dwMilliseconds: DWORD,223 dwMilliseconds: DWORD,
224 bAlertable: BOOL,224 bAlertable: BOOL,
225) DWORD;225) callconv(.Stdcall) DWORD;
226226
227pub extern "kernel32" stdcallcc fn WriteFile(227pub extern "kernel32" fn WriteFile(
228 in_hFile: HANDLE,228 in_hFile: HANDLE,
229 in_lpBuffer: [*]const u8,229 in_lpBuffer: [*]const u8,
230 in_nNumberOfBytesToWrite: DWORD,230 in_nNumberOfBytesToWrite: DWORD,
231 out_lpNumberOfBytesWritten: ?*DWORD,231 out_lpNumberOfBytesWritten: ?*DWORD,
232 in_out_lpOverlapped: ?*OVERLAPPED,232 in_out_lpOverlapped: ?*OVERLAPPED,
233) BOOL;233) callconv(.Stdcall) BOOL;
234234
235pub extern "kernel32" stdcallcc fn WriteFileEx(hFile: HANDLE, lpBuffer: [*]const u8, nNumberOfBytesToWrite: DWORD, lpOverlapped: LPOVERLAPPED, lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE) BOOL;235pub extern "kernel32" fn WriteFileEx(hFile: HANDLE, lpBuffer: [*]const u8, nNumberOfBytesToWrite: DWORD, lpOverlapped: LPOVERLAPPED, lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE) callconv(.Stdcall) BOOL;
236236
237pub extern "kernel32" stdcallcc fn LoadLibraryW(lpLibFileName: [*]const u16) ?HMODULE;237pub extern "kernel32" fn LoadLibraryW(lpLibFileName: [*]const u16) callconv(.Stdcall) ?HMODULE;
238238
239pub extern "kernel32" stdcallcc fn GetProcAddress(hModule: HMODULE, lpProcName: [*]const u8) ?FARPROC;239pub extern "kernel32" fn GetProcAddress(hModule: HMODULE, lpProcName: [*]const u8) callconv(.Stdcall) ?FARPROC;
240240
241pub extern "kernel32" stdcallcc fn FreeLibrary(hModule: HMODULE) BOOL;241pub extern "kernel32" fn FreeLibrary(hModule: HMODULE) callconv(.Stdcall) BOOL;
242242
243pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;243pub extern "kernel32" fn InitializeCriticalSection(lpCriticalSection: *CRITICAL_SECTION) callconv(.Stdcall) void;
244pub extern "kernel32" stdcallcc fn EnterCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;244pub extern "kernel32" fn EnterCriticalSection(lpCriticalSection: *CRITICAL_SECTION) callconv(.Stdcall) void;
245pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;245pub extern "kernel32" fn LeaveCriticalSection(lpCriticalSection: *CRITICAL_SECTION) callconv(.Stdcall) void;
246pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;246pub extern "kernel32" fn DeleteCriticalSection(lpCriticalSection: *CRITICAL_SECTION) callconv(.Stdcall) void;
247247
248pub extern "kernel32" stdcallcc fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*c_void, Context: ?*c_void) BOOL;248pub extern "kernel32" fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*c_void, Context: ?*c_void) callconv(.Stdcall) BOOL;
lib/std/os/windows/ntdll.zig+19-19
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1usingnamespace @import("bits.zig");1usingnamespace @import("bits.zig");
22
3pub extern "NtDll" stdcallcc fn RtlCaptureStackBackTrace(FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **c_void, BackTraceHash: ?*DWORD) WORD;3pub extern "NtDll" fn RtlCaptureStackBackTrace(FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **c_void, BackTraceHash: ?*DWORD) callconv(.Stdcall) WORD;
4pub extern "NtDll" stdcallcc fn NtQueryInformationFile(4pub extern "NtDll" fn NtQueryInformationFile(
5 FileHandle: HANDLE,5 FileHandle: HANDLE,
6 IoStatusBlock: *IO_STATUS_BLOCK,6 IoStatusBlock: *IO_STATUS_BLOCK,
7 FileInformation: *c_void,7 FileInformation: *c_void,
8 Length: ULONG,8 Length: ULONG,
9 FileInformationClass: FILE_INFORMATION_CLASS,9 FileInformationClass: FILE_INFORMATION_CLASS,
10) NTSTATUS;10) callconv(.Stdcall) NTSTATUS;
11pub extern "NtDll" stdcallcc fn NtCreateFile(11pub extern "NtDll" fn NtCreateFile(
12 FileHandle: *HANDLE,12 FileHandle: *HANDLE,
13 DesiredAccess: ACCESS_MASK,13 DesiredAccess: ACCESS_MASK,
14 ObjectAttributes: *OBJECT_ATTRIBUTES,14 ObjectAttributes: *OBJECT_ATTRIBUTES,
...@@ -20,8 +20,8 @@ pub extern "NtDll" stdcallcc fn NtCreateFile(...@@ -20,8 +20,8 @@ pub extern "NtDll" stdcallcc fn NtCreateFile(
20 CreateOptions: ULONG,20 CreateOptions: ULONG,
21 EaBuffer: ?*c_void,21 EaBuffer: ?*c_void,
22 EaLength: ULONG,22 EaLength: ULONG,
23) NTSTATUS;23) callconv(.Stdcall) NTSTATUS;
24pub extern "NtDll" stdcallcc fn NtDeviceIoControlFile(24pub extern "NtDll" fn NtDeviceIoControlFile(
25 FileHandle: HANDLE,25 FileHandle: HANDLE,
26 Event: ?HANDLE,26 Event: ?HANDLE,
27 ApcRoutine: ?IO_APC_ROUTINE,27 ApcRoutine: ?IO_APC_ROUTINE,
...@@ -32,17 +32,17 @@ pub extern "NtDll" stdcallcc fn NtDeviceIoControlFile(...@@ -32,17 +32,17 @@ pub extern "NtDll" stdcallcc fn NtDeviceIoControlFile(
32 InputBufferLength: ULONG,32 InputBufferLength: ULONG,
33 OutputBuffer: ?PVOID,33 OutputBuffer: ?PVOID,
34 OutputBufferLength: ULONG,34 OutputBufferLength: ULONG,
35) NTSTATUS;35) callconv(.Stdcall) NTSTATUS;
36pub extern "NtDll" stdcallcc fn NtClose(Handle: HANDLE) NTSTATUS;36pub extern "NtDll" fn NtClose(Handle: HANDLE) callconv(.Stdcall) NTSTATUS;
37pub extern "NtDll" stdcallcc fn RtlDosPathNameToNtPathName_U(37pub extern "NtDll" fn RtlDosPathNameToNtPathName_U(
38 DosPathName: [*]const u16,38 DosPathName: [*]const u16,
39 NtPathName: *UNICODE_STRING,39 NtPathName: *UNICODE_STRING,
40 NtFileNamePart: ?*?[*]const u16,40 NtFileNamePart: ?*?[*]const u16,
41 DirectoryInfo: ?*CURDIR,41 DirectoryInfo: ?*CURDIR,
42) BOOL;42) callconv(.Stdcall) BOOL;
43pub extern "NtDll" stdcallcc fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) void;43pub extern "NtDll" fn RtlFreeUnicodeString(UnicodeString: *UNICODE_STRING) callconv(.Stdcall) void;
4444
45pub extern "NtDll" stdcallcc fn NtQueryDirectoryFile(45pub extern "NtDll" fn NtQueryDirectoryFile(
46 FileHandle: HANDLE,46 FileHandle: HANDLE,
47 Event: ?HANDLE,47 Event: ?HANDLE,
48 ApcRoutine: ?IO_APC_ROUTINE,48 ApcRoutine: ?IO_APC_ROUTINE,
...@@ -54,22 +54,22 @@ pub extern "NtDll" stdcallcc fn NtQueryDirectoryFile(...@@ -54,22 +54,22 @@ pub extern "NtDll" stdcallcc fn NtQueryDirectoryFile(
54 ReturnSingleEntry: BOOLEAN,54 ReturnSingleEntry: BOOLEAN,
55 FileName: ?*UNICODE_STRING,55 FileName: ?*UNICODE_STRING,
56 RestartScan: BOOLEAN,56 RestartScan: BOOLEAN,
57) NTSTATUS;57) callconv(.Stdcall) NTSTATUS;
58pub extern "NtDll" stdcallcc fn NtCreateKeyedEvent(58pub extern "NtDll" fn NtCreateKeyedEvent(
59 KeyedEventHandle: *HANDLE,59 KeyedEventHandle: *HANDLE,
60 DesiredAccess: ACCESS_MASK,60 DesiredAccess: ACCESS_MASK,
61 ObjectAttributes: ?PVOID,61 ObjectAttributes: ?PVOID,
62 Flags: ULONG,62 Flags: ULONG,
63) NTSTATUS;63) callconv(.Stdcall) NTSTATUS;
64pub extern "NtDll" stdcallcc fn NtReleaseKeyedEvent(64pub extern "NtDll" fn NtReleaseKeyedEvent(
65 EventHandle: HANDLE,65 EventHandle: HANDLE,
66 Key: *const c_void,66 Key: *const c_void,
67 Alertable: BOOLEAN,67 Alertable: BOOLEAN,
68 Timeout: ?*LARGE_INTEGER,68 Timeout: ?*LARGE_INTEGER,
69) NTSTATUS;69) callconv(.Stdcall) NTSTATUS;
70pub extern "NtDll" stdcallcc fn NtWaitForKeyedEvent(70pub extern "NtDll" fn NtWaitForKeyedEvent(
71 EventHandle: HANDLE,71 EventHandle: HANDLE,
72 Key: *const c_void,72 Key: *const c_void,
73 Alertable: BOOLEAN,73 Alertable: BOOLEAN,
74 Timeout: ?*LARGE_INTEGER,74 Timeout: ?*LARGE_INTEGER,
75) NTSTATUS;75) callconv(.Stdcall) NTSTATUS;
lib/std/os/windows/ole32.zig+4-4
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1usingnamespace @import("bits.zig");1usingnamespace @import("bits.zig");
22
3pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: LPVOID) void;3pub extern "ole32" fn CoTaskMemFree(pv: LPVOID) callconv(.Stdcall) void;
4pub extern "ole32" stdcallcc fn CoUninitialize() void;4pub extern "ole32" fn CoUninitialize() callconv(.Stdcall) void;
5pub extern "ole32" stdcallcc fn CoGetCurrentProcess() DWORD;5pub extern "ole32" fn CoGetCurrentProcess() callconv(.Stdcall) DWORD;
6pub extern "ole32" stdcallcc fn CoInitializeEx(pvReserved: LPVOID, dwCoInit: DWORD) HRESULT;6pub extern "ole32" fn CoInitializeEx(pvReserved: LPVOID, dwCoInit: DWORD) callconv(.Stdcall) HRESULT;
lib/std/os/windows/shell32.zig+1-1
...@@ -1,3 +1,3 @@...@@ -1,3 +1,3 @@
1usingnamespace @import("bits.zig");1usingnamespace @import("bits.zig");
22
3pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT;3pub extern "shell32" fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) callconv(.Stdcall) HRESULT;
lib/std/os/windows/ws2_32.zig+23-23
...@@ -315,30 +315,30 @@ const IOC_WS2 = 0x08000000;...@@ -315,30 +315,30 @@ const IOC_WS2 = 0x08000000;
315315
316pub const SIO_BASE_HANDLE = IOC_OUT | IOC_WS2 | 34;316pub const SIO_BASE_HANDLE = IOC_OUT | IOC_WS2 | 34;
317317
318pub extern "ws2_32" stdcallcc fn WSAStartup(318pub extern "ws2_32" fn WSAStartup(
319 wVersionRequired: WORD,319 wVersionRequired: WORD,
320 lpWSAData: *WSADATA,320 lpWSAData: *WSADATA,
321) c_int;321) callconv(.Stdcall) c_int;
322pub extern "ws2_32" stdcallcc fn WSACleanup() c_int;322pub extern "ws2_32" fn WSACleanup() callconv(.Stdcall) c_int;
323pub extern "ws2_32" stdcallcc fn WSAGetLastError() c_int;323pub extern "ws2_32" fn WSAGetLastError() callconv(.Stdcall) c_int;
324pub extern "ws2_32" stdcallcc fn WSASocketA(324pub extern "ws2_32" fn WSASocketA(
325 af: c_int,325 af: c_int,
326 type: c_int,326 type: c_int,
327 protocol: c_int,327 protocol: c_int,
328 lpProtocolInfo: ?*WSAPROTOCOL_INFOA,328 lpProtocolInfo: ?*WSAPROTOCOL_INFOA,
329 g: GROUP,329 g: GROUP,
330 dwFlags: DWORD,330 dwFlags: DWORD,
331) SOCKET;331) callconv(.Stdcall) SOCKET;
332pub extern "ws2_32" stdcallcc fn WSASocketW(332pub extern "ws2_32" fn WSASocketW(
333 af: c_int,333 af: c_int,
334 type: c_int,334 type: c_int,
335 protocol: c_int,335 protocol: c_int,
336 lpProtocolInfo: ?*WSAPROTOCOL_INFOW,336 lpProtocolInfo: ?*WSAPROTOCOL_INFOW,
337 g: GROUP,337 g: GROUP,
338 dwFlags: DWORD,338 dwFlags: DWORD,
339) SOCKET;339) callconv(.Stdcall) SOCKET;
340pub extern "ws2_32" stdcallcc fn closesocket(s: SOCKET) c_int;340pub extern "ws2_32" fn closesocket(s: SOCKET) callconv(.Stdcall) c_int;
341pub extern "ws2_32" stdcallcc fn WSAIoctl(341pub extern "ws2_32" fn WSAIoctl(
342 s: SOCKET,342 s: SOCKET,
343 dwIoControlCode: DWORD,343 dwIoControlCode: DWORD,
344 lpvInBuffer: ?*const c_void,344 lpvInBuffer: ?*const c_void,
...@@ -348,18 +348,18 @@ pub extern "ws2_32" stdcallcc fn WSAIoctl(...@@ -348,18 +348,18 @@ pub extern "ws2_32" stdcallcc fn WSAIoctl(
348 lpcbBytesReturned: LPDWORD,348 lpcbBytesReturned: LPDWORD,
349 lpOverlapped: ?*WSAOVERLAPPED,349 lpOverlapped: ?*WSAOVERLAPPED,
350 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,350 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,
351) c_int;351) callconv(.Stdcall) c_int;
352pub extern "ws2_32" stdcallcc fn accept(352pub extern "ws2_32" fn accept(
353 s: SOCKET,353 s: SOCKET,
354 addr: ?*sockaddr,354 addr: ?*sockaddr,
355 addrlen: socklen_t,355 addrlen: socklen_t,
356) SOCKET;356) callconv(.Stdcall) SOCKET;
357pub extern "ws2_32" stdcallcc fn connect(357pub extern "ws2_32" fn connect(
358 s: SOCKET,358 s: SOCKET,
359 name: *const sockaddr,359 name: *const sockaddr,
360 namelen: socklen_t,360 namelen: socklen_t,
361) c_int;361) callconv(.Stdcall) c_int;
362pub extern "ws2_32" stdcallcc fn WSARecv(362pub extern "ws2_32" fn WSARecv(
363 s: SOCKET,363 s: SOCKET,
364 lpBuffers: [*]const WSABUF,364 lpBuffers: [*]const WSABUF,
365 dwBufferCount: DWORD,365 dwBufferCount: DWORD,
...@@ -367,8 +367,8 @@ pub extern "ws2_32" stdcallcc fn WSARecv(...@@ -367,8 +367,8 @@ pub extern "ws2_32" stdcallcc fn WSARecv(
367 lpFlags: *DWORD,367 lpFlags: *DWORD,
368 lpOverlapped: ?*WSAOVERLAPPED,368 lpOverlapped: ?*WSAOVERLAPPED,
369 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,369 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,
370) c_int;370) callconv(.Stdcall) c_int;
371pub extern "ws2_32" stdcallcc fn WSARecvFrom(371pub extern "ws2_32" fn WSARecvFrom(
372 s: SOCKET,372 s: SOCKET,
373 lpBuffers: [*]const WSABUF,373 lpBuffers: [*]const WSABUF,
374 dwBufferCount: DWORD,374 dwBufferCount: DWORD,
...@@ -378,8 +378,8 @@ pub extern "ws2_32" stdcallcc fn WSARecvFrom(...@@ -378,8 +378,8 @@ pub extern "ws2_32" stdcallcc fn WSARecvFrom(
378 lpFromlen: socklen_t,378 lpFromlen: socklen_t,
379 lpOverlapped: ?*WSAOVERLAPPED,379 lpOverlapped: ?*WSAOVERLAPPED,
380 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,380 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,
381) c_int;381) callconv(.Stdcall) c_int;
382pub extern "ws2_32" stdcallcc fn WSASend(382pub extern "ws2_32" fn WSASend(
383 s: SOCKET,383 s: SOCKET,
384 lpBuffers: [*]WSABUF,384 lpBuffers: [*]WSABUF,
385 dwBufferCount: DWORD,385 dwBufferCount: DWORD,
...@@ -387,8 +387,8 @@ pub extern "ws2_32" stdcallcc fn WSASend(...@@ -387,8 +387,8 @@ pub extern "ws2_32" stdcallcc fn WSASend(
387 dwFlags: DWORD,387 dwFlags: DWORD,
388 lpOverlapped: ?*WSAOVERLAPPED,388 lpOverlapped: ?*WSAOVERLAPPED,
389 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,389 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,
390) c_int;390) callconv(.Stdcall) c_int;
391pub extern "ws2_32" stdcallcc fn WSASendTo(391pub extern "ws2_32" fn WSASendTo(
392 s: SOCKET,392 s: SOCKET,
393 lpBuffers: [*]WSABUF,393 lpBuffers: [*]WSABUF,
394 dwBufferCount: DWORD,394 dwBufferCount: DWORD,
...@@ -398,4 +398,4 @@ pub extern "ws2_32" stdcallcc fn WSASendTo(...@@ -398,4 +398,4 @@ pub extern "ws2_32" stdcallcc fn WSASendTo(
398 iTolen: socklen_t,398 iTolen: socklen_t,
399 lpOverlapped: ?*WSAOVERLAPPED,399 lpOverlapped: ?*WSAOVERLAPPED,
400 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,400 lpCompletionRoutine: ?WSAOVERLAPPED_COMPLETION_ROUTINE,
401) c_int;401) callconv(.Stdcall) c_int;
lib/std/reset_event.zig+12-14
...@@ -14,13 +14,12 @@ const windows = os.windows;...@@ -14,13 +14,12 @@ const windows = os.windows;
14pub const ResetEvent = struct {14pub const ResetEvent = struct {
15 os_event: OsEvent,15 os_event: OsEvent,
1616
17 pub const OsEvent = 17 pub const OsEvent = if (builtin.single_threaded)
18 if (builtin.single_threaded)18 DebugEvent
19 DebugEvent19 else if (builtin.link_libc and builtin.os != .windows and builtin.os != .linux)
20 else if (builtin.link_libc and builtin.os != .windows and builtin.os != .linux)20 PosixEvent
21 PosixEvent21 else
22 else22 AtomicEvent;
23 AtomicEvent;
2423
25 pub fn init() ResetEvent {24 pub fn init() ResetEvent {
26 return ResetEvent{ .os_event = OsEvent.init() };25 return ResetEvent{ .os_event = OsEvent.init() };
...@@ -105,7 +104,7 @@ const PosixEvent = struct {...@@ -105,7 +104,7 @@ const PosixEvent = struct {
105 }104 }
106105
107 fn deinit(self: *PosixEvent) void {106 fn deinit(self: *PosixEvent) void {
108 // on dragonfly, *destroy() functions can return EINVAL 107 // on dragonfly, *destroy() functions can return EINVAL
109 // for statically initialized pthread structures108 // for statically initialized pthread structures
110 const err = if (builtin.os == .dragonfly) os.EINVAL else 0;109 const err = if (builtin.os == .dragonfly) os.EINVAL else 0;
111110
...@@ -212,8 +211,7 @@ const AtomicEvent = struct {...@@ -212,8 +211,7 @@ const AtomicEvent = struct {
212 fn wait(self: *AtomicEvent, timeout: ?u64) !void {211 fn wait(self: *AtomicEvent, timeout: ?u64) !void {
213 var waiters = @atomicLoad(u32, &self.waiters, .Acquire);212 var waiters = @atomicLoad(u32, &self.waiters, .Acquire);
214 while (waiters != WAKE) {213 while (waiters != WAKE) {
215 waiters = @cmpxchgWeak(u32, &self.waiters, waiters, waiters + WAIT, .Acquire, .Acquire)214 waiters = @cmpxchgWeak(u32, &self.waiters, waiters, waiters + WAIT, .Acquire, .Acquire) orelse return Futex.wait(&self.waiters, timeout);
216 orelse return Futex.wait(&self.waiters, timeout);
217 }215 }
218 }216 }
219217
...@@ -281,7 +279,7 @@ const AtomicEvent = struct {...@@ -281,7 +279,7 @@ const AtomicEvent = struct {
281 pub fn wake(waiters: *u32, wake_count: u32) void {279 pub fn wake(waiters: *u32, wake_count: u32) void {
282 const handle = getEventHandle() orelse return SpinFutex.wake(waiters, wake_count);280 const handle = getEventHandle() orelse return SpinFutex.wake(waiters, wake_count);
283 const key = @ptrCast(*const c_void, waiters);281 const key = @ptrCast(*const c_void, waiters);
284 282
285 var waiting = wake_count;283 var waiting = wake_count;
286 while (waiting != 0) : (waiting -= 1) {284 while (waiting != 0) : (waiting -= 1) {
287 const rc = windows.ntdll.NtReleaseKeyedEvent(handle, key, windows.FALSE, null);285 const rc = windows.ntdll.NtReleaseKeyedEvent(handle, key, windows.FALSE, null);
...@@ -408,7 +406,7 @@ test "std.ResetEvent" {...@@ -408,7 +406,7 @@ test "std.ResetEvent" {
408 // wait for receiver to update value and signal output406 // wait for receiver to update value and signal output
409 self.out.wait();407 self.out.wait();
410 testing.expect(self.value == 2);408 testing.expect(self.value == 2);
411 409
412 // update value and signal final input410 // update value and signal final input
413 self.value = 3;411 self.value = 3;
414 self.in.set();412 self.in.set();
...@@ -418,12 +416,12 @@ test "std.ResetEvent" {...@@ -418,12 +416,12 @@ test "std.ResetEvent" {
418 // wait for sender to update value and signal input416 // wait for sender to update value and signal input
419 self.in.wait();417 self.in.wait();
420 assert(self.value == 1);418 assert(self.value == 1);
421 419
422 // update value and signal output420 // update value and signal output
423 self.in.reset();421 self.in.reset();
424 self.value = 2;422 self.value = 2;
425 self.out.set();423 self.out.set();
426 424
427 // wait for sender to update value and signal final input425 // wait for sender to update value and signal final input
428 self.in.wait();426 self.in.wait();
429 assert(self.value == 3);427 assert(self.value == 3);
lib/std/special/c.zig+7-9
...@@ -40,19 +40,19 @@ comptime {...@@ -40,19 +40,19 @@ comptime {
40extern var _fltused: c_int = 1;40extern var _fltused: c_int = 1;
4141
42extern fn main(argc: c_int, argv: [*:null]?[*:0]u8) c_int;42extern fn main(argc: c_int, argv: [*:null]?[*:0]u8) c_int;
43extern fn wasm_start() void {43fn wasm_start() callconv(.C) void {
44 _ = main(0, undefined);44 _ = main(0, undefined);
45}45}
4646
47extern fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) c_int {47fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int {
48 return std.cstr.cmp(s1, s2);48 return std.cstr.cmp(s1, s2);
49}49}
5050
51extern fn strlen(s: [*:0]const u8) usize {51fn strlen(s: [*:0]const u8) callconv(.C) usize {
52 return std.mem.len(u8, s);52 return std.mem.len(u8, s);
53}53}
5454
55extern fn strncmp(_l: [*:0]const u8, _r: [*:0]const u8, _n: usize) c_int {55fn strncmp(_l: [*:0]const u8, _r: [*:0]const u8, _n: usize) callconv(.C) c_int {
56 if (_n == 0) return 0;56 if (_n == 0) return 0;
57 var l = _l;57 var l = _l;
58 var r = _r;58 var r = _r;
...@@ -65,7 +65,7 @@ extern fn strncmp(_l: [*:0]const u8, _r: [*:0]const u8, _n: usize) c_int {...@@ -65,7 +65,7 @@ extern fn strncmp(_l: [*:0]const u8, _r: [*:0]const u8, _n: usize) c_int {
65 return @as(c_int, l[0]) - @as(c_int, r[0]);65 return @as(c_int, l[0]) - @as(c_int, r[0]);
66}66}
6767
68extern fn strerror(errnum: c_int) [*:0]const u8 {68fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
69 return "TODO strerror implementation";69 return "TODO strerror implementation";
70}70}
7171
...@@ -188,14 +188,14 @@ comptime {...@@ -188,14 +188,14 @@ comptime {
188 @export("clone", clone, builtin.GlobalLinkage.Strong);188 @export("clone", clone, builtin.GlobalLinkage.Strong);
189 }189 }
190}190}
191extern fn __stack_chk_fail() noreturn {191fn __stack_chk_fail() callconv(.C) noreturn {
192 @panic("stack smashing detected");192 @panic("stack smashing detected");
193}193}
194194
195// TODO we should be able to put this directly in std/linux/x86_64.zig but195// TODO we should be able to put this directly in std/linux/x86_64.zig but
196// it causes a segfault in release mode. this is a workaround of calling it196// it causes a segfault in release mode. this is a workaround of calling it
197// across .o file boundaries. fix comptime @ptrCast of nakedcc functions.197// across .o file boundaries. fix comptime @ptrCast of nakedcc functions.
198nakedcc fn clone() void {198fn clone() callconv(.Naked) void {
199 switch (builtin.arch) {199 switch (builtin.arch) {
200 .i386 => {200 .i386 => {
201 // __clone(func, stack, flags, arg, ptid, tls, ctid)201 // __clone(func, stack, flags, arg, ptid, tls, ctid)
...@@ -750,7 +750,6 @@ test "sqrt special" {...@@ -750,7 +750,6 @@ test "sqrt special" {
750 std.testing.expect(std.math.isNan(sqrt(std.math.nan(f64))));750 std.testing.expect(std.math.isNan(sqrt(std.math.nan(f64))));
751}751}
752752
753
754export fn sqrtf(x: f32) f32 {753export fn sqrtf(x: f32) f32 {
755 const tiny: f32 = 1.0e-30;754 const tiny: f32 = 1.0e-30;
756 const sign: i32 = @bitCast(i32, @as(u32, 0x80000000));755 const sign: i32 = @bitCast(i32, @as(u32, 0x80000000));
...@@ -848,4 +847,3 @@ test "sqrtf special" {...@@ -848,4 +847,3 @@ test "sqrtf special" {
848 std.testing.expect(std.math.isNan(sqrtf(-1.0)));847 std.testing.expect(std.math.isNan(sqrtf(-1.0)));
849 std.testing.expect(std.math.isNan(sqrtf(std.math.nan(f32))));848 std.testing.expect(std.math.isNan(sqrtf(std.math.nan(f32))));
850}849}
851
lib/std/special/compiler_rt.zig+24-24
...@@ -309,7 +309,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn...@@ -309,7 +309,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
309 }309 }
310}310}
311311
312extern fn __stack_chk_fail() noreturn {312fn __stack_chk_fail() callconv(.C) noreturn {
313 @panic("stack smashing detected");313 @panic("stack smashing detected");
314}314}
315315
...@@ -320,17 +320,17 @@ extern var __stack_chk_guard: usize = blk: {...@@ -320,17 +320,17 @@ extern var __stack_chk_guard: usize = blk: {
320 break :blk @bitCast(usize, buf);320 break :blk @bitCast(usize, buf);
321};321};
322322
323extern fn __aeabi_unwind_cpp_pr0() void {323fn __aeabi_unwind_cpp_pr0() callconv(.C) void {
324 unreachable;324 unreachable;
325}325}
326extern fn __aeabi_unwind_cpp_pr1() void {326fn __aeabi_unwind_cpp_pr1() callconv(.C) void {
327 unreachable;327 unreachable;
328}328}
329extern fn __aeabi_unwind_cpp_pr2() void {329fn __aeabi_unwind_cpp_pr2() callconv(.C) void {
330 unreachable;330 unreachable;
331}331}
332332
333extern fn __divmoddi4(a: i64, b: i64, rem: *i64) i64 {333fn __divmoddi4(a: i64, b: i64, rem: *i64) callconv(.C) i64 {
334 @setRuntimeSafety(is_test);334 @setRuntimeSafety(is_test);
335335
336 const d = __divdi3(a, b);336 const d = __divdi3(a, b);
...@@ -338,7 +338,7 @@ extern fn __divmoddi4(a: i64, b: i64, rem: *i64) i64 {...@@ -338,7 +338,7 @@ extern fn __divmoddi4(a: i64, b: i64, rem: *i64) i64 {
338 return d;338 return d;
339}339}
340340
341extern fn __divdi3(a: i64, b: i64) i64 {341fn __divdi3(a: i64, b: i64) callconv(.C) i64 {
342 @setRuntimeSafety(is_test);342 @setRuntimeSafety(is_test);
343343
344 // Set aside the sign of the quotient.344 // Set aside the sign of the quotient.
...@@ -352,7 +352,7 @@ extern fn __divdi3(a: i64, b: i64) i64 {...@@ -352,7 +352,7 @@ extern fn __divdi3(a: i64, b: i64) i64 {
352 return @bitCast(i64, (res ^ sign) -% sign);352 return @bitCast(i64, (res ^ sign) -% sign);
353}353}
354354
355extern fn __moddi3(a: i64, b: i64) i64 {355fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
356 @setRuntimeSafety(is_test);356 @setRuntimeSafety(is_test);
357357
358 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).358 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
...@@ -365,12 +365,12 @@ extern fn __moddi3(a: i64, b: i64) i64 {...@@ -365,12 +365,12 @@ extern fn __moddi3(a: i64, b: i64) i64 {
365 return (@bitCast(i64, r) ^ (a >> 63)) -% (a >> 63);365 return (@bitCast(i64, r) ^ (a >> 63)) -% (a >> 63);
366}366}
367367
368extern fn __udivdi3(a: u64, b: u64) u64 {368fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
369 @setRuntimeSafety(is_test);369 @setRuntimeSafety(is_test);
370 return __udivmoddi4(a, b, null);370 return __udivmoddi4(a, b, null);
371}371}
372372
373extern fn __umoddi3(a: u64, b: u64) u64 {373fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {
374 @setRuntimeSafety(is_test);374 @setRuntimeSafety(is_test);
375375
376 var r: u64 = undefined;376 var r: u64 = undefined;
...@@ -378,7 +378,7 @@ extern fn __umoddi3(a: u64, b: u64) u64 {...@@ -378,7 +378,7 @@ extern fn __umoddi3(a: u64, b: u64) u64 {
378 return r;378 return r;
379}379}
380380
381extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct {381fn __aeabi_uidivmod(n: u32, d: u32) callconv(.C) extern struct {
382 q: u32,382 q: u32,
383 r: u32,383 r: u32,
384} {384} {
...@@ -389,7 +389,7 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct {...@@ -389,7 +389,7 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct {
389 return result;389 return result;
390}390}
391391
392extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct {392fn __aeabi_uldivmod(n: u64, d: u64) callconv(.C) extern struct {
393 q: u64,393 q: u64,
394 r: u64,394 r: u64,
395} {395} {
...@@ -400,7 +400,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct {...@@ -400,7 +400,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct {
400 return result;400 return result;
401}401}
402402
403extern fn __aeabi_idivmod(n: i32, d: i32) extern struct {403fn __aeabi_idivmod(n: i32, d: i32) callconv(.C) extern struct {
404 q: i32,404 q: i32,
405 r: i32,405 r: i32,
406} {406} {
...@@ -411,7 +411,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct {...@@ -411,7 +411,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct {
411 return result;411 return result;
412}412}
413413
414extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct {414fn __aeabi_ldivmod(n: i64, d: i64) callconv(.C) extern struct {
415 q: i64,415 q: i64,
416 r: i64,416 r: i64,
417} {417} {
...@@ -528,7 +528,7 @@ fn usesThumb1PreArmv6(arch: builtin.Arch) bool {...@@ -528,7 +528,7 @@ fn usesThumb1PreArmv6(arch: builtin.Arch) bool {
528 };528 };
529}529}
530530
531nakedcc fn __aeabi_memcpy() noreturn {531fn __aeabi_memcpy() callconv(.Naked) noreturn {
532 @setRuntimeSafety(false);532 @setRuntimeSafety(false);
533 if (use_thumb_1) {533 if (use_thumb_1) {
534 asm volatile (534 asm volatile (
...@@ -544,7 +544,7 @@ nakedcc fn __aeabi_memcpy() noreturn {...@@ -544,7 +544,7 @@ nakedcc fn __aeabi_memcpy() noreturn {
544 unreachable;544 unreachable;
545}545}
546546
547nakedcc fn __aeabi_memmove() noreturn {547fn __aeabi_memmove() callconv(.Naked) noreturn {
548 @setRuntimeSafety(false);548 @setRuntimeSafety(false);
549 if (use_thumb_1) {549 if (use_thumb_1) {
550 asm volatile (550 asm volatile (
...@@ -560,7 +560,7 @@ nakedcc fn __aeabi_memmove() noreturn {...@@ -560,7 +560,7 @@ nakedcc fn __aeabi_memmove() noreturn {
560 unreachable;560 unreachable;
561}561}
562562
563nakedcc fn __aeabi_memset() noreturn {563fn __aeabi_memset() callconv(.Naked) noreturn {
564 @setRuntimeSafety(false);564 @setRuntimeSafety(false);
565 if (use_thumb_1_pre_armv6) {565 if (use_thumb_1_pre_armv6) {
566 asm volatile (566 asm volatile (
...@@ -591,7 +591,7 @@ nakedcc fn __aeabi_memset() noreturn {...@@ -591,7 +591,7 @@ nakedcc fn __aeabi_memset() noreturn {
591 unreachable;591 unreachable;
592}592}
593593
594nakedcc fn __aeabi_memclr() noreturn {594fn __aeabi_memclr() callconv(.Naked) noreturn {
595 @setRuntimeSafety(false);595 @setRuntimeSafety(false);
596 if (use_thumb_1_pre_armv6) {596 if (use_thumb_1_pre_armv6) {
597 asm volatile (597 asm volatile (
...@@ -619,7 +619,7 @@ nakedcc fn __aeabi_memclr() noreturn {...@@ -619,7 +619,7 @@ nakedcc fn __aeabi_memclr() noreturn {
619 unreachable;619 unreachable;
620}620}
621621
622nakedcc fn __aeabi_memcmp() noreturn {622fn __aeabi_memcmp() callconv(.Naked) noreturn {
623 @setRuntimeSafety(false);623 @setRuntimeSafety(false);
624 if (use_thumb_1) {624 if (use_thumb_1) {
625 asm volatile (625 asm volatile (
...@@ -635,7 +635,7 @@ nakedcc fn __aeabi_memcmp() noreturn {...@@ -635,7 +635,7 @@ nakedcc fn __aeabi_memcmp() noreturn {
635 unreachable;635 unreachable;
636}636}
637637
638extern fn __divmodsi4(a: i32, b: i32, rem: *i32) i32 {638fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
639 @setRuntimeSafety(is_test);639 @setRuntimeSafety(is_test);
640640
641 const d = __divsi3(a, b);641 const d = __divsi3(a, b);
...@@ -643,7 +643,7 @@ extern fn __divmodsi4(a: i32, b: i32, rem: *i32) i32 {...@@ -643,7 +643,7 @@ extern fn __divmodsi4(a: i32, b: i32, rem: *i32) i32 {
643 return d;643 return d;
644}644}
645645
646extern fn __udivmodsi4(a: u32, b: u32, rem: *u32) u32 {646fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
647 @setRuntimeSafety(is_test);647 @setRuntimeSafety(is_test);
648648
649 const d = __udivsi3(a, b);649 const d = __udivsi3(a, b);
...@@ -651,7 +651,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: *u32) u32 {...@@ -651,7 +651,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: *u32) u32 {
651 return d;651 return d;
652}652}
653653
654extern fn __divsi3(n: i32, d: i32) i32 {654fn __divsi3(n: i32, d: i32) callconv(.C) i32 {
655 @setRuntimeSafety(is_test);655 @setRuntimeSafety(is_test);
656656
657 // Set aside the sign of the quotient.657 // Set aside the sign of the quotient.
...@@ -665,7 +665,7 @@ extern fn __divsi3(n: i32, d: i32) i32 {...@@ -665,7 +665,7 @@ extern fn __divsi3(n: i32, d: i32) i32 {
665 return @bitCast(i32, (res ^ sign) -% sign);665 return @bitCast(i32, (res ^ sign) -% sign);
666}666}
667667
668extern fn __udivsi3(n: u32, d: u32) u32 {668fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
669 @setRuntimeSafety(is_test);669 @setRuntimeSafety(is_test);
670670
671 const n_uword_bits: c_uint = u32.bit_count;671 const n_uword_bits: c_uint = u32.bit_count;
...@@ -706,13 +706,13 @@ extern fn __udivsi3(n: u32, d: u32) u32 {...@@ -706,13 +706,13 @@ extern fn __udivsi3(n: u32, d: u32) u32 {
706 return q;706 return q;
707}707}
708708
709extern fn __modsi3(n: i32, d: i32) i32 {709fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
710 @setRuntimeSafety(is_test);710 @setRuntimeSafety(is_test);
711711
712 return n -% __divsi3(n, d) *% d;712 return n -% __divsi3(n, d) *% d;
713}713}
714714
715extern fn __umodsi3(n: u32, d: u32) u32 {715fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
716 @setRuntimeSafety(is_test);716 @setRuntimeSafety(is_test);
717717
718 return n -% __udivsi3(n, d) *% d;718 return n -% __udivsi3(n, d) *% d;
lib/std/special/compiler_rt/addXf3.zig+6-6
...@@ -6,29 +6,29 @@ const std = @import("std");...@@ -6,29 +6,29 @@ const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const compiler_rt = @import("../compiler_rt.zig");7const compiler_rt = @import("../compiler_rt.zig");
88
9pub extern fn __addsf3(a: f32, b: f32) f32 {9pub fn __addsf3(a: f32, b: f32) callconv(.C) f32 {
10 return addXf3(f32, a, b);10 return addXf3(f32, a, b);
11}11}
1212
13pub extern fn __adddf3(a: f64, b: f64) f64 {13pub fn __adddf3(a: f64, b: f64) callconv(.C) f64 {
14 return addXf3(f64, a, b);14 return addXf3(f64, a, b);
15}15}
1616
17pub extern fn __addtf3(a: f128, b: f128) f128 {17pub fn __addtf3(a: f128, b: f128) callconv(.C) f128 {
18 return addXf3(f128, a, b);18 return addXf3(f128, a, b);
19}19}
2020
21pub extern fn __subsf3(a: f32, b: f32) f32 {21pub fn __subsf3(a: f32, b: f32) callconv(.C) f32 {
22 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31));22 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31));
23 return addXf3(f32, a, neg_b);23 return addXf3(f32, a, neg_b);
24}24}
2525
26pub extern fn __subdf3(a: f64, b: f64) f64 {26pub fn __subdf3(a: f64, b: f64) callconv(.C) f64 {
27 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63));27 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (@as(u64, 1) << 63));
28 return addXf3(f64, a, neg_b);28 return addXf3(f64, a, neg_b);
29}29}
3030
31pub extern fn __subtf3(a: f128, b: f128) f128 {31pub fn __subtf3(a: f128, b: f128) callconv(.C) f128 {
32 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (@as(u128, 1) << 127));32 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (@as(u128, 1) << 127));
33 return addXf3(f128, a, neg_b);33 return addXf3(f128, a, neg_b);
34}34}
lib/std/special/compiler_rt/arm/aeabi_dcmp.zig+5-5
...@@ -12,31 +12,31 @@ const ConditionalOperator = enum {...@@ -12,31 +12,31 @@ const ConditionalOperator = enum {
12 Gt,12 Gt,
13};13};
1414
15pub nakedcc fn __aeabi_dcmpeq() noreturn {15pub fn __aeabi_dcmpeq() callconv(.Naked) noreturn {
16 @setRuntimeSafety(false);16 @setRuntimeSafety(false);
17 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Eq});17 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Eq});
18 unreachable;18 unreachable;
19}19}
2020
21pub nakedcc fn __aeabi_dcmplt() noreturn {21pub fn __aeabi_dcmplt() callconv(.Naked) noreturn {
22 @setRuntimeSafety(false);22 @setRuntimeSafety(false);
23 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Lt});23 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Lt});
24 unreachable;24 unreachable;
25}25}
2626
27pub nakedcc fn __aeabi_dcmple() noreturn {27pub fn __aeabi_dcmple() callconv(.Naked) noreturn {
28 @setRuntimeSafety(false);28 @setRuntimeSafety(false);
29 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Le});29 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Le});
30 unreachable;30 unreachable;
31}31}
3232
33pub nakedcc fn __aeabi_dcmpge() noreturn {33pub fn __aeabi_dcmpge() callconv(.Naked) noreturn {
34 @setRuntimeSafety(false);34 @setRuntimeSafety(false);
35 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Ge});35 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Ge});
36 unreachable;36 unreachable;
37}37}
3838
39pub nakedcc fn __aeabi_dcmpgt() noreturn {39pub fn __aeabi_dcmpgt() callconv(.Naked) noreturn {
40 @setRuntimeSafety(false);40 @setRuntimeSafety(false);
41 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Gt});41 @call(.{ .modifier = .always_inline }, aeabi_dcmp, .{.Gt});
42 unreachable;42 unreachable;
lib/std/special/compiler_rt/arm/aeabi_fcmp.zig+5-5
...@@ -12,31 +12,31 @@ const ConditionalOperator = enum {...@@ -12,31 +12,31 @@ const ConditionalOperator = enum {
12 Gt,12 Gt,
13};13};
1414
15pub nakedcc fn __aeabi_fcmpeq() noreturn {15pub fn __aeabi_fcmpeq() callconv(.Naked) noreturn {
16 @setRuntimeSafety(false);16 @setRuntimeSafety(false);
17 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Eq});17 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Eq});
18 unreachable;18 unreachable;
19}19}
2020
21pub nakedcc fn __aeabi_fcmplt() noreturn {21pub fn __aeabi_fcmplt() callconv(.Naked) noreturn {
22 @setRuntimeSafety(false);22 @setRuntimeSafety(false);
23 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Lt});23 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Lt});
24 unreachable;24 unreachable;
25}25}
2626
27pub nakedcc fn __aeabi_fcmple() noreturn {27pub fn __aeabi_fcmple() callconv(.Naked) noreturn {
28 @setRuntimeSafety(false);28 @setRuntimeSafety(false);
29 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Le});29 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Le});
30 unreachable;30 unreachable;
31}31}
3232
33pub nakedcc fn __aeabi_fcmpge() noreturn {33pub fn __aeabi_fcmpge() callconv(.Naked) noreturn {
34 @setRuntimeSafety(false);34 @setRuntimeSafety(false);
35 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Ge});35 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Ge});
36 unreachable;36 unreachable;
37}37}
3838
39pub nakedcc fn __aeabi_fcmpgt() noreturn {39pub fn __aeabi_fcmpgt() callconv(.Naked) noreturn {
40 @setRuntimeSafety(false);40 @setRuntimeSafety(false);
41 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Gt});41 @call(.{ .modifier = .always_inline }, aeabi_fcmp, .{.Gt});
42 unreachable;42 unreachable;
lib/std/special/compiler_rt/ashlti3.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const compiler_rt = @import("../compiler_rt.zig");2const compiler_rt = @import("../compiler_rt.zig");
33
4pub extern fn __ashlti3(a: i128, b: i32) i128 {4pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 {
5 var input = twords{ .all = a };5 var input = twords{ .all = a };
6 var result: twords = undefined;6 var result: twords = undefined;
77
lib/std/special/compiler_rt/ashrti3.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const compiler_rt = @import("../compiler_rt.zig");2const compiler_rt = @import("../compiler_rt.zig");
33
4pub extern fn __ashrti3(a: i128, b: i32) i128 {4pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 {
5 var input = twords{ .all = a };5 var input = twords{ .all = a };
6 var result: twords = undefined;6 var result: twords = undefined;
77
lib/std/special/compiler_rt/aulldiv.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
22
3pub extern stdcallcc fn _alldiv(a: i64, b: i64) i64 {3pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
4 @setRuntimeSafety(builtin.is_test);4 @setRuntimeSafety(builtin.is_test);
5 const s_a = a >> (i64.bit_count - 1);5 const s_a = a >> (i64.bit_count - 1);
6 const s_b = b >> (i64.bit_count - 1);6 const s_b = b >> (i64.bit_count - 1);
...@@ -13,7 +13,7 @@ pub extern stdcallcc fn _alldiv(a: i64, b: i64) i64 {...@@ -13,7 +13,7 @@ pub extern stdcallcc fn _alldiv(a: i64, b: i64) i64 {
13 return (@bitCast(i64, r) ^ s) -% s;13 return (@bitCast(i64, r) ^ s) -% s;
14}14}
1515
16pub nakedcc fn _aulldiv() void {16pub fn _aulldiv() callconv(.Naked) void {
17 @setRuntimeSafety(false);17 @setRuntimeSafety(false);
1818
19 // The stack layout is:19 // The stack layout is:
lib/std/special/compiler_rt/aullrem.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
22
3pub extern stdcallcc fn _allrem(a: i64, b: i64) i64 {3pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {
4 @setRuntimeSafety(builtin.is_test);4 @setRuntimeSafety(builtin.is_test);
5 const s_a = a >> (i64.bit_count - 1);5 const s_a = a >> (i64.bit_count - 1);
6 const s_b = b >> (i64.bit_count - 1);6 const s_b = b >> (i64.bit_count - 1);
...@@ -13,7 +13,7 @@ pub extern stdcallcc fn _allrem(a: i64, b: i64) i64 {...@@ -13,7 +13,7 @@ pub extern stdcallcc fn _allrem(a: i64, b: i64) i64 {
13 return (@bitCast(i64, r) ^ s) -% s;13 return (@bitCast(i64, r) ^ s) -% s;
14}14}
1515
16pub nakedcc fn _aullrem() void {16pub fn _aullrem() callconv(.Naked) void {
17 @setRuntimeSafety(false);17 @setRuntimeSafety(false);
1818
19 // The stack layout is:19 // The stack layout is:
lib/std/special/compiler_rt/comparedf2.zig+7-7
...@@ -27,7 +27,7 @@ const LE_EQUAL = @as(c_int, 0);...@@ -27,7 +27,7 @@ const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = @as(c_int, 1);27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = @as(c_int, 1);28const LE_UNORDERED = @as(c_int, 1);
2929
30pub extern fn __ledf2(a: fp_t, b: fp_t) c_int {30pub fn __ledf2(a: fp_t, b: fp_t) callconv(.C) c_int {
31 @setRuntimeSafety(is_test);31 @setRuntimeSafety(is_test);
32 const aInt: srep_t = @bitCast(srep_t, a);32 const aInt: srep_t = @bitCast(srep_t, a);
33 const bInt: srep_t = @bitCast(srep_t, b);33 const bInt: srep_t = @bitCast(srep_t, b);
...@@ -70,7 +70,7 @@ const GE_EQUAL = @as(c_int, 0);...@@ -70,7 +70,7 @@ const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = @as(c_int, 1);70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
7272
73pub extern fn __gedf2(a: fp_t, b: fp_t) c_int {73pub fn __gedf2(a: fp_t, b: fp_t) callconv(.C) c_int {
74 @setRuntimeSafety(is_test);74 @setRuntimeSafety(is_test);
75 const aInt: srep_t = @bitCast(srep_t, a);75 const aInt: srep_t = @bitCast(srep_t, a);
76 const bInt: srep_t = @bitCast(srep_t, b);76 const bInt: srep_t = @bitCast(srep_t, b);
...@@ -94,26 +94,26 @@ pub extern fn __gedf2(a: fp_t, b: fp_t) c_int {...@@ -94,26 +94,26 @@ pub extern fn __gedf2(a: fp_t, b: fp_t) c_int {
94 }94 }
95}95}
9696
97pub extern fn __unorddf2(a: fp_t, b: fp_t) c_int {97pub fn __unorddf2(a: fp_t, b: fp_t) callconv(.C) c_int {
98 @setRuntimeSafety(is_test);98 @setRuntimeSafety(is_test);
99 const aAbs: rep_t = @bitCast(rep_t, a) & absMask;99 const aAbs: rep_t = @bitCast(rep_t, a) & absMask;
100 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;100 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;
101 return @boolToInt(aAbs > infRep or bAbs > infRep);101 return @boolToInt(aAbs > infRep or bAbs > infRep);
102}102}
103103
104pub extern fn __eqdf2(a: fp_t, b: fp_t) c_int {104pub fn __eqdf2(a: fp_t, b: fp_t) callconv(.C) c_int {
105 return __ledf2(a, b);105 return __ledf2(a, b);
106}106}
107107
108pub extern fn __ltdf2(a: fp_t, b: fp_t) c_int {108pub fn __ltdf2(a: fp_t, b: fp_t) callconv(.C) c_int {
109 return __ledf2(a, b);109 return __ledf2(a, b);
110}110}
111111
112pub extern fn __nedf2(a: fp_t, b: fp_t) c_int {112pub fn __nedf2(a: fp_t, b: fp_t) callconv(.C) c_int {
113 return __ledf2(a, b);113 return __ledf2(a, b);
114}114}
115115
116pub extern fn __gtdf2(a: fp_t, b: fp_t) c_int {116pub fn __gtdf2(a: fp_t, b: fp_t) callconv(.C) c_int {
117 return __gedf2(a, b);117 return __gedf2(a, b);
118}118}
119119
lib/std/special/compiler_rt/comparesf2.zig+7-7
...@@ -27,7 +27,7 @@ const LE_EQUAL = @as(c_int, 0);...@@ -27,7 +27,7 @@ const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = @as(c_int, 1);27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = @as(c_int, 1);28const LE_UNORDERED = @as(c_int, 1);
2929
30pub extern fn __lesf2(a: fp_t, b: fp_t) c_int {30pub fn __lesf2(a: fp_t, b: fp_t) callconv(.C) c_int {
31 @setRuntimeSafety(is_test);31 @setRuntimeSafety(is_test);
32 const aInt: srep_t = @bitCast(srep_t, a);32 const aInt: srep_t = @bitCast(srep_t, a);
33 const bInt: srep_t = @bitCast(srep_t, b);33 const bInt: srep_t = @bitCast(srep_t, b);
...@@ -70,7 +70,7 @@ const GE_EQUAL = @as(c_int, 0);...@@ -70,7 +70,7 @@ const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = @as(c_int, 1);70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
7272
73pub extern fn __gesf2(a: fp_t, b: fp_t) c_int {73pub fn __gesf2(a: fp_t, b: fp_t) callconv(.C) c_int {
74 @setRuntimeSafety(is_test);74 @setRuntimeSafety(is_test);
75 const aInt: srep_t = @bitCast(srep_t, a);75 const aInt: srep_t = @bitCast(srep_t, a);
76 const bInt: srep_t = @bitCast(srep_t, b);76 const bInt: srep_t = @bitCast(srep_t, b);
...@@ -94,26 +94,26 @@ pub extern fn __gesf2(a: fp_t, b: fp_t) c_int {...@@ -94,26 +94,26 @@ pub extern fn __gesf2(a: fp_t, b: fp_t) c_int {
94 }94 }
95}95}
9696
97pub extern fn __unordsf2(a: fp_t, b: fp_t) c_int {97pub fn __unordsf2(a: fp_t, b: fp_t) callconv(.C) c_int {
98 @setRuntimeSafety(is_test);98 @setRuntimeSafety(is_test);
99 const aAbs: rep_t = @bitCast(rep_t, a) & absMask;99 const aAbs: rep_t = @bitCast(rep_t, a) & absMask;
100 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;100 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;
101 return @boolToInt(aAbs > infRep or bAbs > infRep);101 return @boolToInt(aAbs > infRep or bAbs > infRep);
102}102}
103103
104pub extern fn __eqsf2(a: fp_t, b: fp_t) c_int {104pub fn __eqsf2(a: fp_t, b: fp_t) callconv(.C) c_int {
105 return __lesf2(a, b);105 return __lesf2(a, b);
106}106}
107107
108pub extern fn __ltsf2(a: fp_t, b: fp_t) c_int {108pub fn __ltsf2(a: fp_t, b: fp_t) callconv(.C) c_int {
109 return __lesf2(a, b);109 return __lesf2(a, b);
110}110}
111111
112pub extern fn __nesf2(a: fp_t, b: fp_t) c_int {112pub fn __nesf2(a: fp_t, b: fp_t) callconv(.C) c_int {
113 return __lesf2(a, b);113 return __lesf2(a, b);
114}114}
115115
116pub extern fn __gtsf2(a: fp_t, b: fp_t) c_int {116pub fn __gtsf2(a: fp_t, b: fp_t) callconv(.C) c_int {
117 return __gesf2(a, b);117 return __gesf2(a, b);
118}118}
119119
lib/std/special/compiler_rt/comparetf2.zig+3-3
...@@ -21,7 +21,7 @@ const infRep = exponentMask;...@@ -21,7 +21,7 @@ const infRep = exponentMask;
21const builtin = @import("builtin");21const builtin = @import("builtin");
22const is_test = builtin.is_test;22const is_test = builtin.is_test;
2323
24pub extern fn __letf2(a: f128, b: f128) c_int {24pub fn __letf2(a: f128, b: f128) callconv(.C) c_int {
25 @setRuntimeSafety(is_test);25 @setRuntimeSafety(is_test);
2626
27 const aInt = @bitCast(rep_t, a);27 const aInt = @bitCast(rep_t, a);
...@@ -65,7 +65,7 @@ const GE_EQUAL = @as(c_int, 0);...@@ -65,7 +65,7 @@ const GE_EQUAL = @as(c_int, 0);
65const GE_GREATER = @as(c_int, 1);65const GE_GREATER = @as(c_int, 1);
66const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED66const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
6767
68pub extern fn __getf2(a: f128, b: f128) c_int {68pub fn __getf2(a: f128, b: f128) callconv(.C) c_int {
69 @setRuntimeSafety(is_test);69 @setRuntimeSafety(is_test);
7070
71 const aInt = @bitCast(srep_t, a);71 const aInt = @bitCast(srep_t, a);
...@@ -90,7 +90,7 @@ pub extern fn __getf2(a: f128, b: f128) c_int {...@@ -90,7 +90,7 @@ pub extern fn __getf2(a: f128, b: f128) c_int {
90 GE_GREATER;90 GE_GREATER;
91}91}
9292
93pub extern fn __unordtf2(a: f128, b: f128) c_int {93pub fn __unordtf2(a: f128, b: f128) callconv(.C) c_int {
94 @setRuntimeSafety(is_test);94 @setRuntimeSafety(is_test);
9595
96 const aAbs = @bitCast(rep_t, a) & absMask;96 const aAbs = @bitCast(rep_t, a) & absMask;
lib/std/special/compiler_rt/divdf3.zig+1-1
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
77
8pub extern fn __divdf3(a: f64, b: f64) f64 {8pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
9 @setRuntimeSafety(builtin.is_test);9 @setRuntimeSafety(builtin.is_test);
10 const Z = @IntType(false, f64.bit_count);10 const Z = @IntType(false, f64.bit_count);
11 const SignedZ = @IntType(true, f64.bit_count);11 const SignedZ = @IntType(true, f64.bit_count);
lib/std/special/compiler_rt/divsf3.zig+1-1
...@@ -5,7 +5,7 @@...@@ -5,7 +5,7 @@
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
77
8pub extern fn __divsf3(a: f32, b: f32) f32 {8pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
9 @setRuntimeSafety(builtin.is_test);9 @setRuntimeSafety(builtin.is_test);
10 const Z = @IntType(false, f32.bit_count);10 const Z = @IntType(false, f32.bit_count);
1111
lib/std/special/compiler_rt/divti3.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const udivmod = @import("udivmod.zig").udivmod;1const udivmod = @import("udivmod.zig").udivmod;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __divti3(a: i128, b: i128) i128 {4pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
66
7 const s_a = a >> (i128.bit_count - 1);7 const s_a = a >> (i128.bit_count - 1);
...@@ -16,7 +16,7 @@ pub extern fn __divti3(a: i128, b: i128) i128 {...@@ -16,7 +16,7 @@ pub extern fn __divti3(a: i128, b: i128) i128 {
16}16}
1717
18const v128 = @Vector(2, u64);18const v128 = @Vector(2, u64);
19pub extern fn __divti3_windows_x86_64(a: v128, b: v128) v128 {19pub fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
20 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __divti3, .{20 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __divti3, .{
21 @bitCast(i128, a),21 @bitCast(i128, a),
22 @bitCast(i128, b),22 @bitCast(i128, b),
lib/std/special/compiler_rt/extendXfYf2.zig+4-4
...@@ -2,19 +2,19 @@ const std = @import("std");...@@ -2,19 +2,19 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;3const is_test = builtin.is_test;
44
5pub extern fn __extendsfdf2(a: f32) f64 {5pub fn __extendsfdf2(a: f32) callconv(.C) f64 {
6 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f64, f32, @bitCast(u32, a) });6 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f64, f32, @bitCast(u32, a) });
7}7}
88
9pub extern fn __extenddftf2(a: f64) f128 {9pub fn __extenddftf2(a: f64) callconv(.C) f128 {
10 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f128, f64, @bitCast(u64, a) });10 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f128, f64, @bitCast(u64, a) });
11}11}
1212
13pub extern fn __extendsftf2(a: f32) f128 {13pub fn __extendsftf2(a: f32) callconv(.C) f128 {
14 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f128, f32, @bitCast(u32, a) });14 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f128, f32, @bitCast(u32, a) });
15}15}
1616
17pub extern fn __extendhfsf2(a: u16) f32 {17pub fn __extendhfsf2(a: u16) callconv(.C) f32 {
18 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f32, f16, a });18 return @call(.{ .modifier = .always_inline }, extendXfYf2, .{ f32, f16, a });
19}19}
2020
lib/std/special/compiler_rt/fixdfdi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixdfdi(a: f64) i64 {4pub fn __fixdfdi(a: f64) callconv(.C) i64 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f64, i64, a);6 return fixint(f64, i64, a);
7}7}
lib/std/special/compiler_rt/fixdfsi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixdfsi(a: f64) i32 {4pub fn __fixdfsi(a: f64) callconv(.C) i32 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f64, i32, a);6 return fixint(f64, i32, a);
7}7}
lib/std/special/compiler_rt/fixdfti.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixdfti(a: f64) i128 {4pub fn __fixdfti(a: f64) callconv(.C) i128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f64, i128, a);6 return fixint(f64, i128, a);
7}7}
lib/std/special/compiler_rt/fixsfdi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixsfdi(a: f32) i64 {4pub fn __fixsfdi(a: f32) callconv(.C) i64 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f32, i64, a);6 return fixint(f32, i64, a);
7}7}
lib/std/special/compiler_rt/fixsfsi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixsfsi(a: f32) i32 {4pub fn __fixsfsi(a: f32) callconv(.C) i32 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f32, i32, a);6 return fixint(f32, i32, a);
7}7}
lib/std/special/compiler_rt/fixsfti.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixsfti(a: f32) i128 {4pub fn __fixsfti(a: f32) callconv(.C) i128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f32, i128, a);6 return fixint(f32, i128, a);
7}7}
lib/std/special/compiler_rt/fixtfdi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixtfdi(a: f128) i64 {4pub fn __fixtfdi(a: f128) callconv(.C) i64 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f128, i64, a);6 return fixint(f128, i64, a);
7}7}
lib/std/special/compiler_rt/fixtfsi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixtfsi(a: f128) i32 {4pub fn __fixtfsi(a: f128) callconv(.C) i32 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f128, i32, a);6 return fixint(f128, i32, a);
7}7}
lib/std/special/compiler_rt/fixtfti.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixint = @import("fixint.zig").fixint;1const fixint = @import("fixint.zig").fixint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixtfti(a: f128) i128 {4pub fn __fixtfti(a: f128) callconv(.C) i128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixint(f128, i128, a);6 return fixint(f128, i128, a);
7}7}
lib/std/special/compiler_rt/fixunsdfdi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunsdfdi(a: f64) u64 {4pub fn __fixunsdfdi(a: f64) callconv(.C) u64 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f64, u64, a);6 return fixuint(f64, u64, a);
7}7}
lib/std/special/compiler_rt/fixunsdfsi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunsdfsi(a: f64) u32 {4pub fn __fixunsdfsi(a: f64) callconv(.C) u32 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f64, u32, a);6 return fixuint(f64, u32, a);
7}7}
lib/std/special/compiler_rt/fixunsdfti.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunsdfti(a: f64) u128 {4pub fn __fixunsdfti(a: f64) callconv(.C) u128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f64, u128, a);6 return fixuint(f64, u128, a);
7}7}
lib/std/special/compiler_rt/fixunssfdi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunssfdi(a: f32) u64 {4pub fn __fixunssfdi(a: f32) callconv(.C) u64 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f32, u64, a);6 return fixuint(f32, u64, a);
7}7}
lib/std/special/compiler_rt/fixunssfsi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunssfsi(a: f32) u32 {4pub fn __fixunssfsi(a: f32) callconv(.C) u32 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f32, u32, a);6 return fixuint(f32, u32, a);
7}7}
lib/std/special/compiler_rt/fixunssfti.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunssfti(a: f32) u128 {4pub fn __fixunssfti(a: f32) callconv(.C) u128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f32, u128, a);6 return fixuint(f32, u128, a);
7}7}
lib/std/special/compiler_rt/fixunstfdi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunstfdi(a: f128) u64 {4pub fn __fixunstfdi(a: f128) callconv(.C) u64 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f128, u64, a);6 return fixuint(f128, u64, a);
7}7}
lib/std/special/compiler_rt/fixunstfsi.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunstfsi(a: f128) u32 {4pub fn __fixunstfsi(a: f128) callconv(.C) u32 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f128, u32, a);6 return fixuint(f128, u32, a);
7}7}
lib/std/special/compiler_rt/fixunstfti.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const fixuint = @import("fixuint.zig").fixuint;1const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunstfti(a: f128) u128 {4pub fn __fixunstfti(a: f128) callconv(.C) u128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f128, u128, a);6 return fixuint(f128, u128, a);
7}7}
lib/std/special/compiler_rt/floatdidf.zig+1-1
...@@ -4,7 +4,7 @@ const std = @import("std");...@@ -4,7 +4,7 @@ const std = @import("std");
4const twop52: f64 = 0x1.0p52;4const twop52: f64 = 0x1.0p52;
5const twop32: f64 = 0x1.0p32;5const twop32: f64 = 0x1.0p32;
66
7pub extern fn __floatdidf(a: i64) f64 {7pub fn __floatdidf(a: i64) callconv(.C) f64 {
8 @setRuntimeSafety(builtin.is_test);8 @setRuntimeSafety(builtin.is_test);
99
10 if (a == 0) return 0;10 if (a == 0) return 0;
lib/std/special/compiler_rt/floatsiXf.zig+3-3
...@@ -53,17 +53,17 @@ fn floatsiXf(comptime T: type, a: i32) T {...@@ -53,17 +53,17 @@ fn floatsiXf(comptime T: type, a: i32) T {
53 return @bitCast(T, result);53 return @bitCast(T, result);
54}54}
5555
56pub extern fn __floatsisf(arg: i32) f32 {56pub fn __floatsisf(arg: i32) callconv(.C) f32 {
57 @setRuntimeSafety(builtin.is_test);57 @setRuntimeSafety(builtin.is_test);
58 return @call(.{ .modifier = .always_inline }, floatsiXf, .{ f32, arg });58 return @call(.{ .modifier = .always_inline }, floatsiXf, .{ f32, arg });
59}59}
6060
61pub extern fn __floatsidf(arg: i32) f64 {61pub fn __floatsidf(arg: i32) callconv(.C) f64 {
62 @setRuntimeSafety(builtin.is_test);62 @setRuntimeSafety(builtin.is_test);
63 return @call(.{ .modifier = .always_inline }, floatsiXf, .{ f64, arg });63 return @call(.{ .modifier = .always_inline }, floatsiXf, .{ f64, arg });
64}64}
6565
66pub extern fn __floatsitf(arg: i32) f128 {66pub fn __floatsitf(arg: i32) callconv(.C) f128 {
67 @setRuntimeSafety(builtin.is_test);67 @setRuntimeSafety(builtin.is_test);
68 return @call(.{ .modifier = .always_inline }, floatsiXf, .{ f128, arg });68 return @call(.{ .modifier = .always_inline }, floatsiXf, .{ f128, arg });
69}69}
lib/std/special/compiler_rt/floattidf.zig+1-1
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6const DBL_MANT_DIG = 53;6const DBL_MANT_DIG = 53;
77
8pub extern fn __floattidf(arg: i128) f64 {8pub fn __floattidf(arg: i128) callconv(.C) f64 {
9 @setRuntimeSafety(is_test);9 @setRuntimeSafety(is_test);
1010
11 if (arg == 0)11 if (arg == 0)
lib/std/special/compiler_rt/floattisf.zig+1-1
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6const FLT_MANT_DIG = 24;6const FLT_MANT_DIG = 24;
77
8pub extern fn __floattisf(arg: i128) f32 {8pub fn __floattisf(arg: i128) callconv(.C) f32 {
9 @setRuntimeSafety(is_test);9 @setRuntimeSafety(is_test);
1010
11 if (arg == 0)11 if (arg == 0)
lib/std/special/compiler_rt/floattitf.zig+1-1
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6const LDBL_MANT_DIG = 113;6const LDBL_MANT_DIG = 113;
77
8pub extern fn __floattitf(arg: i128) f128 {8pub fn __floattitf(arg: i128) callconv(.C) f128 {
9 @setRuntimeSafety(is_test);9 @setRuntimeSafety(is_test);
1010
11 if (arg == 0)11 if (arg == 0)
lib/std/special/compiler_rt/floatundidf.zig+1-1
...@@ -5,7 +5,7 @@ const twop52: f64 = 0x1.0p52;...@@ -5,7 +5,7 @@ const twop52: f64 = 0x1.0p52;
5const twop84: f64 = 0x1.0p84;5const twop84: f64 = 0x1.0p84;
6const twop84_plus_twop52: f64 = 0x1.00000001p84;6const twop84_plus_twop52: f64 = 0x1.00000001p84;
77
8pub extern fn __floatundidf(a: u64) f64 {8pub fn __floatundidf(a: u64) callconv(.C) f64 {
9 @setRuntimeSafety(builtin.is_test);9 @setRuntimeSafety(builtin.is_test);
1010
11 if (a == 0) return 0;11 if (a == 0) return 0;
lib/std/special/compiler_rt/floatunditf.zig+1-1
...@@ -2,7 +2,7 @@ const builtin = @import("builtin");...@@ -2,7 +2,7 @@ const builtin = @import("builtin");
2const is_test = builtin.is_test;2const is_test = builtin.is_test;
3const std = @import("std");3const std = @import("std");
44
5pub extern fn __floatunditf(a: u128) f128 {5pub fn __floatunditf(a: u128) callconv(.C) f128 {
6 @setRuntimeSafety(is_test);6 @setRuntimeSafety(is_test);
77
8 if (a == 0) {8 if (a == 0) {
lib/std/special/compiler_rt/floatunsidf.zig+1-1
...@@ -4,7 +4,7 @@ const maxInt = std.math.maxInt;...@@ -4,7 +4,7 @@ const maxInt = std.math.maxInt;
44
5const implicitBit = @as(u64, 1) << 52;5const implicitBit = @as(u64, 1) << 52;
66
7pub extern fn __floatunsidf(arg: u32) f64 {7pub fn __floatunsidf(arg: u32) callconv(.C) f64 {
8 @setRuntimeSafety(builtin.is_test);8 @setRuntimeSafety(builtin.is_test);
99
10 if (arg == 0) return 0.0;10 if (arg == 0) return 0.0;
lib/std/special/compiler_rt/floatunsitf.zig+1-1
...@@ -2,7 +2,7 @@ const builtin = @import("builtin");...@@ -2,7 +2,7 @@ const builtin = @import("builtin");
2const is_test = builtin.is_test;2const is_test = builtin.is_test;
3const std = @import("std");3const std = @import("std");
44
5pub extern fn __floatunsitf(a: u64) f128 {5pub fn __floatunsitf(a: u64) callconv(.C) f128 {
6 @setRuntimeSafety(is_test);6 @setRuntimeSafety(is_test);
77
8 if (a == 0) {8 if (a == 0) {
lib/std/special/compiler_rt/floatuntidf.zig+1-1
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6const DBL_MANT_DIG = 53;6const DBL_MANT_DIG = 53;
77
8pub extern fn __floatuntidf(arg: u128) f64 {8pub fn __floatuntidf(arg: u128) callconv(.C) f64 {
9 @setRuntimeSafety(is_test);9 @setRuntimeSafety(is_test);
1010
11 if (arg == 0)11 if (arg == 0)
lib/std/special/compiler_rt/floatuntisf.zig+1-1
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6const FLT_MANT_DIG = 24;6const FLT_MANT_DIG = 24;
77
8pub extern fn __floatuntisf(arg: u128) f32 {8pub fn __floatuntisf(arg: u128) callconv(.C) f32 {
9 @setRuntimeSafety(is_test);9 @setRuntimeSafety(is_test);
1010
11 if (arg == 0)11 if (arg == 0)
lib/std/special/compiler_rt/floatuntitf.zig+1-1
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6const LDBL_MANT_DIG = 113;6const LDBL_MANT_DIG = 113;
77
8pub extern fn __floatuntitf(arg: u128) f128 {8pub fn __floatuntitf(arg: u128) callconv(.C) f128 {
9 @setRuntimeSafety(is_test);9 @setRuntimeSafety(is_test);
1010
11 if (arg == 0)11 if (arg == 0)
lib/std/special/compiler_rt/lshrti3.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const compiler_rt = @import("../compiler_rt.zig");2const compiler_rt = @import("../compiler_rt.zig");
33
4pub extern fn __lshrti3(a: i128, b: i32) i128 {4pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
5 var input = twords{ .all = a };5 var input = twords{ .all = a };
6 var result: twords = undefined;6 var result: twords = undefined;
77
lib/std/special/compiler_rt/modti3.zig+2-2
...@@ -6,7 +6,7 @@ const udivmod = @import("udivmod.zig").udivmod;...@@ -6,7 +6,7 @@ const udivmod = @import("udivmod.zig").udivmod;
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const compiler_rt = @import("../compiler_rt.zig");7const compiler_rt = @import("../compiler_rt.zig");
88
9pub extern fn __modti3(a: i128, b: i128) i128 {9pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
10 @setRuntimeSafety(builtin.is_test);10 @setRuntimeSafety(builtin.is_test);
1111
12 const s_a = a >> (i128.bit_count - 1); // s = a < 0 ? -1 : 012 const s_a = a >> (i128.bit_count - 1); // s = a < 0 ? -1 : 0
...@@ -21,7 +21,7 @@ pub extern fn __modti3(a: i128, b: i128) i128 {...@@ -21,7 +21,7 @@ pub extern fn __modti3(a: i128, b: i128) i128 {
21}21}
2222
23const v128 = @Vector(2, u64);23const v128 = @Vector(2, u64);
24pub extern fn __modti3_windows_x86_64(a: v128, b: v128) v128 {24pub fn __modti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
25 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __modti3, .{25 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __modti3, .{
26 @bitCast(i128, a),26 @bitCast(i128, a),
27 @bitCast(i128, b),27 @bitCast(i128, b),
lib/std/special/compiler_rt/mulXf3.zig+3-3
...@@ -6,13 +6,13 @@ const std = @import("std");...@@ -6,13 +6,13 @@ const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const compiler_rt = @import("../compiler_rt.zig");7const compiler_rt = @import("../compiler_rt.zig");
88
9pub extern fn __multf3(a: f128, b: f128) f128 {9pub fn __multf3(a: f128, b: f128) callconv(.C) f128 {
10 return mulXf3(f128, a, b);10 return mulXf3(f128, a, b);
11}11}
12pub extern fn __muldf3(a: f64, b: f64) f64 {12pub fn __muldf3(a: f64, b: f64) callconv(.C) f64 {
13 return mulXf3(f64, a, b);13 return mulXf3(f64, a, b);
14}14}
15pub extern fn __mulsf3(a: f32, b: f32) f32 {15pub fn __mulsf3(a: f32, b: f32) callconv(.C) f32 {
16 return mulXf3(f32, a, b);16 return mulXf3(f32, a, b);
17}17}
1818
lib/std/special/compiler_rt/muldi3.zig+1-1
...@@ -39,7 +39,7 @@ fn __muldsi3(a: u32, b: u32) i64 {...@@ -39,7 +39,7 @@ fn __muldsi3(a: u32, b: u32) i64 {
39 return r.all;39 return r.all;
40}40}
4141
42pub extern fn __muldi3(a: i64, b: i64) i64 {42pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
43 @setRuntimeSafety(builtin.is_test);43 @setRuntimeSafety(builtin.is_test);
4444
45 const x = dwords{ .all = a };45 const x = dwords{ .all = a };
lib/std/special/compiler_rt/mulodi4.zig+1-1
...@@ -3,7 +3,7 @@ const compiler_rt = @import("../compiler_rt.zig");...@@ -3,7 +3,7 @@ const compiler_rt = @import("../compiler_rt.zig");
3const maxInt = std.math.maxInt;3const maxInt = std.math.maxInt;
4const minInt = std.math.minInt;4const minInt = std.math.minInt;
55
6pub extern fn __mulodi4(a: i64, b: i64, overflow: *c_int) i64 {6pub fn __mulodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
7 @setRuntimeSafety(builtin.is_test);7 @setRuntimeSafety(builtin.is_test);
88
9 const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1)));9 const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1)));
lib/std/special/compiler_rt/muloti4.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const compiler_rt = @import("../compiler_rt.zig");2const compiler_rt = @import("../compiler_rt.zig");
33
4pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 {4pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
66
7 const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1)));7 const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1)));
lib/std/special/compiler_rt/multi3.zig+2-2
...@@ -5,7 +5,7 @@ const compiler_rt = @import("../compiler_rt.zig");...@@ -5,7 +5,7 @@ const compiler_rt = @import("../compiler_rt.zig");
5// ae684fad6d34858c014c94da69c15e7774a633c35// ae684fad6d34858c014c94da69c15e7774a633c3
6// 2018-08-136// 2018-08-13
77
8pub extern fn __multi3(a: i128, b: i128) i128 {8pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
9 @setRuntimeSafety(builtin.is_test);9 @setRuntimeSafety(builtin.is_test);
10 const x = twords{ .all = a };10 const x = twords{ .all = a };
11 const y = twords{ .all = b };11 const y = twords{ .all = b };
...@@ -15,7 +15,7 @@ pub extern fn __multi3(a: i128, b: i128) i128 {...@@ -15,7 +15,7 @@ pub extern fn __multi3(a: i128, b: i128) i128 {
15}15}
1616
17const v128 = @Vector(2, u64);17const v128 = @Vector(2, u64);
18pub extern fn __multi3_windows_x86_64(a: v128, b: v128) v128 {18pub fn __multi3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
19 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __multi3, .{19 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __multi3, .{
20 @bitCast(i128, a),20 @bitCast(i128, a),
21 @bitCast(i128, b),21 @bitCast(i128, b),
lib/std/special/compiler_rt/negXf2.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1const std = @import("std");1const std = @import("std");
22
3pub extern fn __negsf2(a: f32) f32 {3pub fn __negsf2(a: f32) callconv(.C) f32 {
4 return negXf2(f32, a);4 return negXf2(f32, a);
5}5}
66
7pub extern fn __negdf2(a: f64) f64 {7pub fn __negdf2(a: f64) callconv(.C) f64 {
8 return negXf2(f64, a);8 return negXf2(f64, a);
9}9}
1010
lib/std/special/compiler_rt/popcountdi2.zig+1-1
...@@ -2,7 +2,7 @@ const builtin = @import("builtin");...@@ -2,7 +2,7 @@ const builtin = @import("builtin");
2const compiler_rt = @import("../compiler_rt.zig");2const compiler_rt = @import("../compiler_rt.zig");
33
4// ported from llvm compiler-rt 8.0.0rc3 95e1c294cb0415a377a7b1d6c7c7d4f89e1c04e44// ported from llvm compiler-rt 8.0.0rc3 95e1c294cb0415a377a7b1d6c7c7d4f89e1c04e4
5pub extern fn __popcountdi2(a: i64) i32 {5pub fn __popcountdi2(a: i64) callconv(.C) i32 {
6 var x2 = @bitCast(u64, a);6 var x2 = @bitCast(u64, a);
7 x2 = x2 - ((x2 >> 1) & 0x5555555555555555);7 x2 = x2 - ((x2 >> 1) & 0x5555555555555555);
8 // Every 2 bits holds the sum of every pair of bits (32)8 // Every 2 bits holds the sum of every pair of bits (32)
lib/std/special/compiler_rt/stack_probe.zig+6-6
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
22
3// Zig's own stack-probe routine (available only on x86 and x86_64)3// Zig's own stack-probe routine (available only on x86 and x86_64)
4pub nakedcc fn zig_probe_stack() void {4pub fn zig_probe_stack() callconv(.Naked) void {
5 @setRuntimeSafety(false);5 @setRuntimeSafety(false);
66
7 // Versions of the Linux kernel before 5.1 treat any access below SP as7 // Versions of the Linux kernel before 5.1 treat any access below SP as
...@@ -180,11 +180,11 @@ fn win_probe_stack_adjust_sp() void {...@@ -180,11 +180,11 @@ fn win_probe_stack_adjust_sp() void {
180// ___chkstk (__alloca) | yes | yes |180// ___chkstk (__alloca) | yes | yes |
181// ___chkstk_ms | no | no |181// ___chkstk_ms | no | no |
182182
183pub nakedcc fn _chkstk() void {183pub fn _chkstk() callconv(.Naked) void {
184 @setRuntimeSafety(false);184 @setRuntimeSafety(false);
185 @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{});185 @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{});
186}186}
187pub nakedcc fn __chkstk() void {187pub fn __chkstk() callconv(.Naked) void {
188 @setRuntimeSafety(false);188 @setRuntimeSafety(false);
189 switch (builtin.arch) {189 switch (builtin.arch) {
190 .i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}),190 .i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}),
...@@ -192,15 +192,15 @@ pub nakedcc fn __chkstk() void {...@@ -192,15 +192,15 @@ pub nakedcc fn __chkstk() void {
192 else => unreachable,192 else => unreachable,
193 }193 }
194}194}
195pub nakedcc fn ___chkstk() void {195pub fn ___chkstk() callconv(.Naked) void {
196 @setRuntimeSafety(false);196 @setRuntimeSafety(false);
197 @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{});197 @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{});
198}198}
199pub nakedcc fn __chkstk_ms() void {199pub fn __chkstk_ms() callconv(.Naked) void {
200 @setRuntimeSafety(false);200 @setRuntimeSafety(false);
201 @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{});201 @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{});
202}202}
203pub nakedcc fn ___chkstk_ms() void {203pub fn ___chkstk_ms() callconv(.Naked) void {
204 @setRuntimeSafety(false);204 @setRuntimeSafety(false);
205 @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{});205 @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{});
206}206}
lib/std/special/compiler_rt/truncXfYf2.zig+5-5
...@@ -1,22 +1,22 @@...@@ -1,22 +1,22 @@
1const std = @import("std");1const std = @import("std");
22
3pub extern fn __truncsfhf2(a: f32) u16 {3pub fn __truncsfhf2(a: f32) callconv(.C) u16 {
4 return @bitCast(u16, truncXfYf2(f16, f32, a));4 return @bitCast(u16, truncXfYf2(f16, f32, a));
5}5}
66
7pub extern fn __truncdfhf2(a: f64) u16 {7pub fn __truncdfhf2(a: f64) callconv(.C) u16 {
8 return @bitCast(u16, truncXfYf2(f16, f64, a));8 return @bitCast(u16, truncXfYf2(f16, f64, a));
9}9}
1010
11pub extern fn __trunctfsf2(a: f128) f32 {11pub fn __trunctfsf2(a: f128) callconv(.C) f32 {
12 return truncXfYf2(f32, f128, a);12 return truncXfYf2(f32, f128, a);
13}13}
1414
15pub extern fn __trunctfdf2(a: f128) f64 {15pub fn __trunctfdf2(a: f128) callconv(.C) f64 {
16 return truncXfYf2(f64, f128, a);16 return truncXfYf2(f64, f128, a);
17}17}
1818
19pub extern fn __truncdfsf2(a: f64) f32 {19pub fn __truncdfsf2(a: f64) callconv(.C) f32 {
20 return truncXfYf2(f32, f64, a);20 return truncXfYf2(f32, f64, a);
21}21}
2222
lib/std/special/compiler_rt/udivmoddi4.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const udivmod = @import("udivmod.zig").udivmod;1const udivmod = @import("udivmod.zig").udivmod;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) u64 {4pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return udivmod(u64, a, b, maybe_rem);6 return udivmod(u64, a, b, maybe_rem);
7}7}
lib/std/special/compiler_rt/udivmodti4.zig+2-2
...@@ -2,13 +2,13 @@ const udivmod = @import("udivmod.zig").udivmod;...@@ -2,13 +2,13 @@ const udivmod = @import("udivmod.zig").udivmod;
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const compiler_rt = @import("../compiler_rt.zig");3const compiler_rt = @import("../compiler_rt.zig");
44
5pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) u128 {5pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {
6 @setRuntimeSafety(builtin.is_test);6 @setRuntimeSafety(builtin.is_test);
7 return udivmod(u128, a, b, maybe_rem);7 return udivmod(u128, a, b, maybe_rem);
8}8}
99
10const v128 = @Vector(2, u64);10const v128 = @Vector(2, u64);
11pub extern fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) v128 {11pub fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {
12 @setRuntimeSafety(builtin.is_test);12 @setRuntimeSafety(builtin.is_test);
13 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));13 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));
14}14}
lib/std/special/compiler_rt/udivti3.zig+2-2
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const udivmodti4 = @import("udivmodti4.zig");1const udivmodti4 = @import("udivmodti4.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __udivti3(a: u128, b: u128) u128 {4pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {
5 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return udivmodti4.__udivmodti4(a, b, null);6 return udivmodti4.__udivmodti4(a, b, null);
7}7}
88
9const v128 = @Vector(2, u64);9const v128 = @Vector(2, u64);
10pub extern fn __udivti3_windows_x86_64(a: v128, b: v128) v128 {10pub fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
11 @setRuntimeSafety(builtin.is_test);11 @setRuntimeSafety(builtin.is_test);
12 return udivmodti4.__udivmodti4_windows_x86_64(a, b, null);12 return udivmodti4.__udivmodti4_windows_x86_64(a, b, null);
13}13}
lib/std/special/compiler_rt/umodti3.zig+2-2
...@@ -2,7 +2,7 @@ const udivmodti4 = @import("udivmodti4.zig");...@@ -2,7 +2,7 @@ const udivmodti4 = @import("udivmodti4.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const compiler_rt = @import("../compiler_rt.zig");3const compiler_rt = @import("../compiler_rt.zig");
44
5pub extern fn __umodti3(a: u128, b: u128) u128 {5pub fn __umodti3(a: u128, b: u128) callconv(.C) u128 {
6 @setRuntimeSafety(builtin.is_test);6 @setRuntimeSafety(builtin.is_test);
7 var r: u128 = undefined;7 var r: u128 = undefined;
8 _ = udivmodti4.__udivmodti4(a, b, &r);8 _ = udivmodti4.__udivmodti4(a, b, &r);
...@@ -10,7 +10,7 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {...@@ -10,7 +10,7 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {
10}10}
1111
12const v128 = @Vector(2, u64);12const v128 = @Vector(2, u64);
13pub extern fn __umodti3_windows_x86_64(a: v128, b: v128) v128 {13pub fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
14 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __umodti3, .{14 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __umodti3, .{
15 @bitCast(u128, a),15 @bitCast(u128, a),
16 @bitCast(u128, b),16 @bitCast(u128, b),
lib/std/spinlock.zig+10-2
...@@ -60,8 +60,16 @@ pub const SpinLock = struct {...@@ -60,8 +60,16 @@ pub const SpinLock = struct {
60 switch (builtin.arch) {60 switch (builtin.arch) {
61 // these instructions use a memory clobber as they61 // these instructions use a memory clobber as they
62 // flush the pipeline of any speculated reads/writes.62 // flush the pipeline of any speculated reads/writes.
63 .i386, .x86_64 => asm volatile ("pause" ::: "memory"),63 .i386, .x86_64 => asm volatile ("pause"
64 .arm, .aarch64 => asm volatile ("yield" ::: "memory"),64 :
65 :
66 : "memory"
67 ),
68 .arm, .aarch64 => asm volatile ("yield"
69 :
70 :
71 : "memory"
72 ),
65 else => std.os.sched_yield() catch {},73 else => std.os.sched_yield() catch {},
66 }74 }
67 }75 }
lib/std/start.zig+6-10
...@@ -43,11 +43,7 @@ comptime {...@@ -43,11 +43,7 @@ comptime {
43 }43 }
44}44}
4545
46stdcallcc fn _DllMainCRTStartup(46fn _DllMainCRTStartup(hinstDLL: std.os.windows.HINSTANCE, fdwReason: std.os.windows.DWORD, lpReserved: std.os.windows.LPVOID) callconv(.Stdcall) std.os.windows.BOOL {
47 hinstDLL: std.os.windows.HINSTANCE,
48 fdwReason: std.os.windows.DWORD,
49 lpReserved: std.os.windows.LPVOID,
50) std.os.windows.BOOL {
51 if (@hasDecl(root, "DllMain")) {47 if (@hasDecl(root, "DllMain")) {
52 return root.DllMain(hinstDLL, fdwReason, lpReserved);48 return root.DllMain(hinstDLL, fdwReason, lpReserved);
53 }49 }
...@@ -55,13 +51,13 @@ stdcallcc fn _DllMainCRTStartup(...@@ -55,13 +51,13 @@ stdcallcc fn _DllMainCRTStartup(
55 return std.os.windows.TRUE;51 return std.os.windows.TRUE;
56}52}
5753
58extern fn wasm_freestanding_start() void {54fn wasm_freestanding_start() callconv(.C) void {
59 // This is marked inline because for some reason LLVM in release mode fails to inline it,55 // This is marked inline because for some reason LLVM in release mode fails to inline it,
60 // and we want fewer call frames in stack traces.56 // and we want fewer call frames in stack traces.
61 _ = @call(.{ .modifier = .always_inline }, callMain, .{});57 _ = @call(.{ .modifier = .always_inline }, callMain, .{});
62}58}
6359
64extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) usize {60fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.C) usize {
65 const bad_efi_main_ret = "expected return type of main to be 'void', 'noreturn', or 'usize'";61 const bad_efi_main_ret = "expected return type of main to be 'void', 'noreturn', or 'usize'";
66 uefi.handle = handle;62 uefi.handle = handle;
67 uefi.system_table = system_table;63 uefi.system_table = system_table;
...@@ -84,7 +80,7 @@ extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) u...@@ -84,7 +80,7 @@ extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) u
84 }80 }
85}81}
8682
87nakedcc fn _start() noreturn {83fn _start() callconv(.Naked) noreturn {
88 if (builtin.os == builtin.Os.wasi) {84 if (builtin.os == builtin.Os.wasi) {
89 // This is marked inline because for some reason LLVM in release mode fails to inline it,85 // This is marked inline because for some reason LLVM in release mode fails to inline it,
90 // and we want fewer call frames in stack traces.86 // and we want fewer call frames in stack traces.
...@@ -127,7 +123,7 @@ nakedcc fn _start() noreturn {...@@ -127,7 +123,7 @@ nakedcc fn _start() noreturn {
127 @call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{});123 @call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{});
128}124}
129125
130stdcallcc fn WinMainCRTStartup() noreturn {126fn WinMainCRTStartup() callconv(.Stdcall) noreturn {
131 @setAlignStack(16);127 @setAlignStack(16);
132 if (!builtin.single_threaded) {128 if (!builtin.single_threaded) {
133 _ = @import("start_windows_tls.zig");129 _ = @import("start_windows_tls.zig");
...@@ -198,7 +194,7 @@ fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {...@@ -198,7 +194,7 @@ fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
198 return initEventLoopAndCallMain();194 return initEventLoopAndCallMain();
199}195}
200196
201extern fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) i32 {197fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) callconv(.C) i32 {
202 var env_count: usize = 0;198 var env_count: usize = 0;
203 while (c_envp[env_count] != null) : (env_count += 1) {}199 while (c_envp[env_count] != null) : (env_count += 1) {}
204 const envp = @ptrCast([*][*:0]u8, c_envp)[0..env_count];200 const envp = @ptrCast([*][*:0]u8, c_envp)[0..env_count];
lib/std/thread.zig+3-3
...@@ -156,7 +156,7 @@ pub const Thread = struct {...@@ -156,7 +156,7 @@ pub const Thread = struct {
156 thread: Thread,156 thread: Thread,
157 inner: Context,157 inner: Context,
158 };158 };
159 extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD {159 fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD {
160 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;160 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;
161 switch (@typeId(@TypeOf(startFn).ReturnType)) {161 switch (@typeId(@TypeOf(startFn).ReturnType)) {
162 .Int => {162 .Int => {
...@@ -198,7 +198,7 @@ pub const Thread = struct {...@@ -198,7 +198,7 @@ pub const Thread = struct {
198 }198 }
199199
200 const MainFuncs = struct {200 const MainFuncs = struct {
201 extern fn linuxThreadMain(ctx_addr: usize) u8 {201 fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 {
202 const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;202 const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;
203203
204 switch (@typeId(@TypeOf(startFn).ReturnType)) {204 switch (@typeId(@TypeOf(startFn).ReturnType)) {
...@@ -212,7 +212,7 @@ pub const Thread = struct {...@@ -212,7 +212,7 @@ pub const Thread = struct {
212 else => @compileError("expected return type of startFn to be 'u8', 'noreturn', 'void', or '!void'"),212 else => @compileError("expected return type of startFn to be 'u8', 'noreturn', 'void', or '!void'"),
213 }213 }
214 }214 }
215 extern fn posixThreadMain(ctx: ?*c_void) ?*c_void {215 fn posixThreadMain(ctx: ?*c_void) callconv(.C) ?*c_void {
216 if (@sizeOf(Context) == 0) {216 if (@sizeOf(Context) == 0) {
217 _ = startFn({});217 _ = startFn({});
218 return null;218 return null;
lib/std/unicode/throughput_test.zig+1-1
...@@ -22,7 +22,7 @@ pub fn main() !void {...@@ -22,7 +22,7 @@ pub fn main() !void {
22 const elapsed_ns_orig = timer.lap();22 const elapsed_ns_orig = timer.lap();
23 @fence(.SeqCst);23 @fence(.SeqCst);
2424
25 var buffer2: [32767] u16 align(4096) = undefined;25 var buffer2: [32767]u16 align(4096) = undefined;
26 _ = try std.unicode.utf8ToUtf16Le_better(&buffer2, args[1]);26 _ = try std.unicode.utf8ToUtf16Le_better(&buffer2, args[1]);
2727
28 @fence(.SeqCst);28 @fence(.SeqCst);
lib/std/zig/ast.zig+1
...@@ -860,6 +860,7 @@ pub const Node = struct {...@@ -860,6 +860,7 @@ pub const Node = struct {
860 lib_name: ?*Node, // populated if this is an extern declaration860 lib_name: ?*Node, // populated if this is an extern declaration
861 align_expr: ?*Node, // populated if align(A) is present861 align_expr: ?*Node, // populated if align(A) is present
862 section_expr: ?*Node, // populated if linksection(A) is present862 section_expr: ?*Node, // populated if linksection(A) is present
863 callconv_expr: ?*Node, // populated if callconv(A) is present
863864
864 pub const ParamList = SegmentedList(*Node, 2);865 pub const ParamList = SegmentedList(*Node, 2);
865866
lib/std/zig/parse.zig+13
...@@ -311,6 +311,7 @@ fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {...@@ -311,6 +311,7 @@ fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
311 const rparen = try expectToken(it, tree, .RParen);311 const rparen = try expectToken(it, tree, .RParen);
312 const align_expr = try parseByteAlign(arena, it, tree);312 const align_expr = try parseByteAlign(arena, it, tree);
313 const section_expr = try parseLinkSection(arena, it, tree);313 const section_expr = try parseLinkSection(arena, it, tree);
314 const callconv_expr = try parseCallconv(arena, it, tree);
314 const exclamation_token = eatToken(it, .Bang);315 const exclamation_token = eatToken(it, .Bang);
315316
316 const return_type_expr = (try parseVarType(arena, it, tree)) orelse317 const return_type_expr = (try parseVarType(arena, it, tree)) orelse
...@@ -347,6 +348,7 @@ fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {...@@ -347,6 +348,7 @@ fn parseFnProto(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
347 .lib_name = null,348 .lib_name = null,
348 .align_expr = align_expr,349 .align_expr = align_expr,
349 .section_expr = section_expr,350 .section_expr = section_expr,
351 .callconv_expr = callconv_expr,
350 };352 };
351353
352 if (cc) |kind| {354 if (cc) |kind| {
...@@ -1678,6 +1680,17 @@ fn parseLinkSection(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node...@@ -1678,6 +1680,17 @@ fn parseLinkSection(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
1678 return expr_node;1680 return expr_node;
1679}1681}
16801682
1683/// CallConv <- KEYWORD_callconv LPAREN Expr RPAREN
1684fn parseCallconv(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
1685 _ = eatToken(it, .Keyword_callconv) orelse return null;
1686 _ = try expectToken(it, tree, .LParen);
1687 const expr_node = try expectNode(arena, it, tree, parseExpr, AstError{
1688 .ExpectedExpr = AstError.ExpectedExpr{ .token = it.index },
1689 });
1690 _ = try expectToken(it, tree, .RParen);
1691 return expr_node;
1692}
1693
1681/// FnCC1694/// FnCC
1682/// <- KEYWORD_nakedcc1695/// <- KEYWORD_nakedcc
1683/// / KEYWORD_stdcallcc1696/// / KEYWORD_stdcallcc
lib/std/zig/parser_test.zig+16-2
...@@ -9,6 +9,20 @@ test "zig fmt: change @typeOf to @TypeOf" {...@@ -9,6 +9,20 @@ test "zig fmt: change @typeOf to @TypeOf" {
9 );9 );
10}10}
1111
12// TODO: Remove nakedcc/stdcallcc once zig 0.6.0 is released. See https://github.com/ziglang/zig/pull/3977
13test "zig fmt: convert extern/nakedcc/stdcallcc into callconv(...)" {
14 try testTransform(
15 \\nakedcc fn foo1() void {}
16 \\stdcallcc fn foo2() void {}
17 \\extern fn foo3() void {}
18 ,
19 \\fn foo1() callconv(.Naked) void {}
20 \\fn foo2() callconv(.Stdcall) void {}
21 \\fn foo3() callconv(.C) void {}
22 \\
23 );
24}
25
12test "zig fmt: comptime struct field" {26test "zig fmt: comptime struct field" {
13 try testCanonical(27 try testCanonical(
14 \\const Foo = struct {28 \\const Foo = struct {
...@@ -234,7 +248,7 @@ test "zig fmt: threadlocal" {...@@ -234,7 +248,7 @@ test "zig fmt: threadlocal" {
234test "zig fmt: linksection" {248test "zig fmt: linksection" {
235 try testCanonical(249 try testCanonical(
236 \\export var aoeu: u64 linksection(".text.derp") = 1234;250 \\export var aoeu: u64 linksection(".text.derp") = 1234;
237 \\export nakedcc fn _start() linksection(".text.boot") noreturn {}251 \\export fn _start() linksection(".text.boot") callconv(.Naked) noreturn {}
238 \\252 \\
239 );253 );
240}254}
...@@ -2326,7 +2340,7 @@ test "zig fmt: fn type" {...@@ -2326,7 +2340,7 @@ test "zig fmt: fn type" {
2326 \\2340 \\
2327 \\const a: fn (u8) u8 = undefined;2341 \\const a: fn (u8) u8 = undefined;
2328 \\const b: extern fn (u8) u8 = undefined;2342 \\const b: extern fn (u8) u8 = undefined;
2329 \\const c: nakedcc fn (u8) u8 = undefined;2343 \\const c: fn (u8) callconv(.Naked) u8 = undefined;
2330 \\const ap: fn (u8) u8 = a;2344 \\const ap: fn (u8) u8 = a;
2331 \\2345 \\
2332 );2346 );
lib/std/zig/render.zig+30-2
...@@ -1311,8 +1311,16 @@ fn renderExpression(...@@ -1311,8 +1311,16 @@ fn renderExpression(
1311 try renderToken(tree, stream, visib_token_index, indent, start_col, Space.Space); // pub1311 try renderToken(tree, stream, visib_token_index, indent, start_col, Space.Space); // pub
1312 }1312 }
13131313
1314 // Some extra machinery is needed to rewrite the old-style cc
1315 // notation to the new callconv one
1316 var cc_rewrite_str: ?[*:0]const u8 = null;
1314 if (fn_proto.extern_export_inline_token) |extern_export_inline_token| {1317 if (fn_proto.extern_export_inline_token) |extern_export_inline_token| {
1315 try renderToken(tree, stream, extern_export_inline_token, indent, start_col, Space.Space); // extern/export1318 const tok = tree.tokens.at(extern_export_inline_token);
1319 if (tok.id != .Keyword_extern or fn_proto.body_node == null) {
1320 try renderToken(tree, stream, extern_export_inline_token, indent, start_col, Space.Space); // extern/export
1321 } else {
1322 cc_rewrite_str = ".C";
1323 }
1316 }1324 }
13171325
1318 if (fn_proto.lib_name) |lib_name| {1326 if (fn_proto.lib_name) |lib_name| {
...@@ -1320,7 +1328,12 @@ fn renderExpression(...@@ -1320,7 +1328,12 @@ fn renderExpression(
1320 }1328 }
13211329
1322 if (fn_proto.cc_token) |cc_token| {1330 if (fn_proto.cc_token) |cc_token| {
1323 try renderToken(tree, stream, cc_token, indent, start_col, Space.Space); // stdcallcc1331 var str = tree.tokenSlicePtr(tree.tokens.at(cc_token));
1332 if (mem.eql(u8, str, "stdcallcc")) {
1333 cc_rewrite_str = ".Stdcall";
1334 } else if (mem.eql(u8, str, "nakedcc")) {
1335 cc_rewrite_str = ".Naked";
1336 } else try renderToken(tree, stream, cc_token, indent, start_col, Space.Space); // stdcallcc
1324 }1337 }
13251338
1326 const lparen = if (fn_proto.name_token) |name_token| blk: {1339 const lparen = if (fn_proto.name_token) |name_token| blk: {
...@@ -1392,6 +1405,21 @@ fn renderExpression(...@@ -1392,6 +1405,21 @@ fn renderExpression(
1392 try renderToken(tree, stream, section_rparen, indent, start_col, Space.Space); // )1405 try renderToken(tree, stream, section_rparen, indent, start_col, Space.Space); // )
1393 }1406 }
13941407
1408 if (fn_proto.callconv_expr) |callconv_expr| {
1409 const callconv_rparen = tree.nextToken(callconv_expr.lastToken());
1410 const callconv_lparen = tree.prevToken(callconv_expr.firstToken());
1411 const callconv_kw = tree.prevToken(callconv_lparen);
1412
1413 try renderToken(tree, stream, callconv_kw, indent, start_col, Space.None); // callconv
1414 try renderToken(tree, stream, callconv_lparen, indent, start_col, Space.None); // (
1415 try renderExpression(allocator, stream, tree, indent, start_col, callconv_expr, Space.None);
1416 try renderToken(tree, stream, callconv_rparen, indent, start_col, Space.Space); // )
1417 } else if (cc_rewrite_str) |str| {
1418 try stream.write("callconv(");
1419 try stream.write(mem.toSliceConst(u8, str));
1420 try stream.write(") ");
1421 }
1422
1395 switch (fn_proto.return_type) {1423 switch (fn_proto.return_type) {
1396 ast.Node.FnProto.ReturnType.Explicit => |node| {1424 ast.Node.FnProto.ReturnType.Explicit => |node| {
1397 return renderExpression(allocator, stream, tree, indent, start_col, node, space);1425 return renderExpression(allocator, stream, tree, indent, start_col, node, space);
lib/std/zig/tokenizer.zig+3
...@@ -30,6 +30,7 @@ pub const Token = struct {...@@ -30,6 +30,7 @@ pub const Token = struct {
30 Keyword.init("async", .Keyword_async),30 Keyword.init("async", .Keyword_async),
31 Keyword.init("await", .Keyword_await),31 Keyword.init("await", .Keyword_await),
32 Keyword.init("break", .Keyword_break),32 Keyword.init("break", .Keyword_break),
33 Keyword.init("callconv", .Keyword_callconv),
33 Keyword.init("catch", .Keyword_catch),34 Keyword.init("catch", .Keyword_catch),
34 Keyword.init("comptime", .Keyword_comptime),35 Keyword.init("comptime", .Keyword_comptime),
35 Keyword.init("const", .Keyword_const),36 Keyword.init("const", .Keyword_const),
...@@ -162,6 +163,7 @@ pub const Token = struct {...@@ -162,6 +163,7 @@ pub const Token = struct {
162 Keyword_async,163 Keyword_async,
163 Keyword_await,164 Keyword_await,
164 Keyword_break,165 Keyword_break,
166 Keyword_callconv,
165 Keyword_catch,167 Keyword_catch,
166 Keyword_comptime,168 Keyword_comptime,
167 Keyword_const,169 Keyword_const,
...@@ -286,6 +288,7 @@ pub const Token = struct {...@@ -286,6 +288,7 @@ pub const Token = struct {
286 .Keyword_async => "async",288 .Keyword_async => "async",
287 .Keyword_await => "await",289 .Keyword_await => "await",
288 .Keyword_break => "break",290 .Keyword_break => "break",
291 .Keyword_callconv => "callconv",
289 .Keyword_catch => "catch",292 .Keyword_catch => "catch",
290 .Keyword_comptime => "comptime",293 .Keyword_comptime => "comptime",
291 .Keyword_const => "const",294 .Keyword_const => "const",
src-self-hosted/translate_c.zig+19-4
...@@ -11,7 +11,7 @@ const CToken = ctok.CToken;...@@ -11,7 +11,7 @@ const CToken = ctok.CToken;
11const mem = std.mem;11const mem = std.mem;
12const math = std.math;12const math = std.math;
1313
14const CallingConvention = std.builtin.TypeInfo.CallingConvention;14const CallingConvention = std.builtin.CallingConvention;
1515
16pub const ClangErrMsg = Stage2ErrorMsg;16pub const ClangErrMsg = Stage2ErrorMsg;
1717
...@@ -3690,6 +3690,7 @@ fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: *ast.Node, proto_a...@@ -3690,6 +3690,7 @@ fn transCreateNodeMacroFn(c: *Context, name: []const u8, ref: *ast.Node, proto_a
3690 .lib_name = null,3690 .lib_name = null,
3691 .align_expr = null,3691 .align_expr = null,
3692 .section_expr = null,3692 .section_expr = null,
3693 .callconv_expr = null,
3693 };3694 };
36943695
3695 const block = try transCreateNodeBlock(c, null);3696 const block = try transCreateNodeBlock(c, null);
...@@ -4141,6 +4142,11 @@ fn transCC(...@@ -4141,6 +4142,11 @@ fn transCC(
4141 switch (clang_cc) {4142 switch (clang_cc) {
4142 .C => return CallingConvention.C,4143 .C => return CallingConvention.C,
4143 .X86StdCall => return CallingConvention.Stdcall,4144 .X86StdCall => return CallingConvention.Stdcall,
4145 .X86FastCall => return CallingConvention.Fastcall,
4146 .X86VectorCall, .AArch64VectorCall => return CallingConvention.Vectorcall,
4147 .X86ThisCall => return CallingConvention.Thiscall,
4148 .AAPCS => return CallingConvention.AAPCS,
4149 .AAPCS_VFP => return CallingConvention.AAPCSVFP,
4144 else => return revertAndWarn(4150 else => return revertAndWarn(
4145 rp,4151 rp,
4146 error.UnsupportedType,4152 error.UnsupportedType,
...@@ -4189,14 +4195,13 @@ fn finishTransFnProto(...@@ -4189,14 +4195,13 @@ fn finishTransFnProto(
4189 is_pub: bool,4195 is_pub: bool,
4190) !*ast.Node.FnProto {4196) !*ast.Node.FnProto {
4191 const is_export = if (fn_decl_context) |ctx| ctx.is_export else false;4197 const is_export = if (fn_decl_context) |ctx| ctx.is_export else false;
4192 const is_extern = if (fn_decl_context) |ctx| !ctx.has_body else true;4198 const is_extern = if (fn_decl_context) |ctx| !ctx.has_body else false;
41934199
4194 // TODO check for always_inline attribute4200 // TODO check for always_inline attribute
4195 // TODO check for align attribute4201 // TODO check for align attribute
41964202
4197 // pub extern fn name(...) T4203 // pub extern fn name(...) T
4198 const pub_tok = if (is_pub) try appendToken(rp.c, .Keyword_pub, "pub") else null;4204 const pub_tok = if (is_pub) try appendToken(rp.c, .Keyword_pub, "pub") else null;
4199 const cc_tok = if (cc == .Stdcall) try appendToken(rp.c, .Keyword_stdcallcc, "stdcallcc") else null;
4200 const extern_export_inline_tok = if (is_export)4205 const extern_export_inline_tok = if (is_export)
4201 try appendToken(rp.c, .Keyword_export, "export")4206 try appendToken(rp.c, .Keyword_export, "export")
4202 else if (cc == .C and is_extern)4207 else if (cc == .C and is_extern)
...@@ -4303,6 +4308,14 @@ fn finishTransFnProto(...@@ -4303,6 +4308,14 @@ fn finishTransFnProto(
4303 break :blk null;4308 break :blk null;
4304 };4309 };
43054310
4311 const callconv_expr = if ((is_export or is_extern) and cc == .C) null else blk: {
4312 _ = try appendToken(rp.c, .Keyword_callconv, "callconv");
4313 _ = try appendToken(rp.c, .LParen, "(");
4314 const expr = try transCreateNodeEnumLiteral(rp.c, @tagName(cc));
4315 _ = try appendToken(rp.c, .RParen, ")");
4316 break :blk expr;
4317 };
4318
4306 const return_type_node = blk: {4319 const return_type_node = blk: {
4307 if (ZigClangFunctionType_getNoReturnAttr(fn_ty)) {4320 if (ZigClangFunctionType_getNoReturnAttr(fn_ty)) {
4308 break :blk try transCreateNodeIdentifier(rp.c, "noreturn");4321 break :blk try transCreateNodeIdentifier(rp.c, "noreturn");
...@@ -4333,11 +4346,12 @@ fn finishTransFnProto(...@@ -4333,11 +4346,12 @@ fn finishTransFnProto(
4333 .return_type = .{ .Explicit = return_type_node },4346 .return_type = .{ .Explicit = return_type_node },
4334 .var_args_token = null, // TODO this field is broken in the AST data model4347 .var_args_token = null, // TODO this field is broken in the AST data model
4335 .extern_export_inline_token = extern_export_inline_tok,4348 .extern_export_inline_token = extern_export_inline_tok,
4336 .cc_token = cc_tok,4349 .cc_token = null,
4337 .body_node = null,4350 .body_node = null,
4338 .lib_name = null,4351 .lib_name = null,
4339 .align_expr = align_expr,4352 .align_expr = align_expr,
4340 .section_expr = linksection_expr,4353 .section_expr = linksection_expr,
4354 .callconv_expr = callconv_expr,
4341 };4355 };
4342 return fn_proto;4356 return fn_proto;
4343}4357}
...@@ -4686,6 +4700,7 @@ fn transMacroFnDefine(c: *Context, it: *ctok.TokenList.Iterator, name: []const u...@@ -4686,6 +4700,7 @@ fn transMacroFnDefine(c: *Context, it: *ctok.TokenList.Iterator, name: []const u
4686 .lib_name = null,4700 .lib_name = null,
4687 .align_expr = null,4701 .align_expr = null,
4688 .section_expr = null,4702 .section_expr = null,
4703 .callconv_expr = null,
4689 };4704 };
46904705
4691 const block = try transCreateNodeBlock(c, null);4706 const block = try transCreateNodeBlock(c, null);
src-self-hosted/type.zig+2-1
...@@ -337,7 +337,7 @@ pub const Type = struct {...@@ -337,7 +337,7 @@ pub const Type = struct {
337 }337 }
338 };338 };
339339
340 const CallingConvention = builtin.TypeInfo.CallingConvention;340 const CallingConvention = builtin.CallingConvention;
341341
342 pub const Param = struct {342 pub const Param = struct {
343 is_noalias: bool,343 is_noalias: bool,
...@@ -352,6 +352,7 @@ pub const Type = struct {...@@ -352,6 +352,7 @@ pub const Type = struct {
352 .Naked => "nakedcc ",352 .Naked => "nakedcc ",
353 .Stdcall => "stdcallcc ",353 .Stdcall => "stdcallcc ",
354 .Async => "async ",354 .Async => "async ",
355 else => unreachable,
355 };356 };
356 }357 }
357358
src/all_types.hpp+22-10
...@@ -57,6 +57,23 @@ enum PtrLen {...@@ -57,6 +57,23 @@ enum PtrLen {
57 PtrLenC,57 PtrLenC,
58};58};
5959
60enum CallingConvention {
61 CallingConventionUnspecified,
62 CallingConventionC,
63 CallingConventionCold,
64 CallingConventionNaked,
65 CallingConventionAsync,
66 CallingConventionInterrupt,
67 CallingConventionSignal,
68 CallingConventionStdcall,
69 CallingConventionFastcall,
70 CallingConventionVectorcall,
71 CallingConventionThiscall,
72 CallingConventionAPCS,
73 CallingConventionAAPCS,
74 CallingConventionAAPCSVFP,
75};
76
60// This one corresponds to the builtin.zig enum.77// This one corresponds to the builtin.zig enum.
61enum BuiltinPtrSize {78enum BuiltinPtrSize {
62 BuiltinPtrSizeOne,79 BuiltinPtrSizeOne,
...@@ -398,6 +415,7 @@ struct LazyValueFnType {...@@ -398,6 +415,7 @@ struct LazyValueFnType {
398 IrInstruction *align_inst; // can be null415 IrInstruction *align_inst; // can be null
399 IrInstruction *return_type;416 IrInstruction *return_type;
400417
418 CallingConvention cc;
401 bool is_generic;419 bool is_generic;
402};420};
403421
...@@ -612,15 +630,6 @@ enum NodeType {...@@ -612,15 +630,6 @@ enum NodeType {
612 NodeTypeVarFieldType,630 NodeTypeVarFieldType,
613};631};
614632
615enum CallingConvention {
616 CallingConventionUnspecified,
617 CallingConventionC,
618 CallingConventionCold,
619 CallingConventionNaked,
620 CallingConventionStdcall,
621 CallingConventionAsync,
622};
623
624enum FnInline {633enum FnInline {
625 FnInlineAuto,634 FnInlineAuto,
626 FnInlineAlways,635 FnInlineAlways,
...@@ -639,10 +648,12 @@ struct AstNodeFnProto {...@@ -639,10 +648,12 @@ struct AstNodeFnProto {
639 AstNode *align_expr;648 AstNode *align_expr;
640 // populated if the "section(S)" is present649 // populated if the "section(S)" is present
641 AstNode *section_expr;650 AstNode *section_expr;
651 // populated if the "callconv(S)" is present
652 AstNode *callconv_expr;
642 Buf doc_comments;653 Buf doc_comments;
643654
644 FnInline fn_inline;655 FnInline fn_inline;
645 CallingConvention cc;656 bool is_async;
646657
647 VisibMod visib_mod;658 VisibMod visib_mod;
648 bool auto_err_set;659 bool auto_err_set;
...@@ -3549,6 +3560,7 @@ struct IrInstructionFnProto {...@@ -3549,6 +3560,7 @@ struct IrInstructionFnProto {
35493560
3550 IrInstruction **param_types;3561 IrInstruction **param_types;
3551 IrInstruction *align_value;3562 IrInstruction *align_value;
3563 IrInstruction *callconv_value;
3552 IrInstruction *return_type;3564 IrInstruction *return_type;
3553 bool is_var_args;3565 bool is_var_args;
3554};3566};
src/analyze.cpp+109-64
...@@ -919,24 +919,20 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {...@@ -919,24 +919,20 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) {
919919
920const char *calling_convention_name(CallingConvention cc) {920const char *calling_convention_name(CallingConvention cc) {
921 switch (cc) {921 switch (cc) {
922 case CallingConventionUnspecified: return "undefined";922 case CallingConventionUnspecified: return "Unspecified";
923 case CallingConventionC: return "ccc";923 case CallingConventionC: return "C";
924 case CallingConventionCold: return "coldcc";924 case CallingConventionCold: return "Cold";
925 case CallingConventionNaked: return "nakedcc";925 case CallingConventionNaked: return "Naked";
926 case CallingConventionStdcall: return "stdcallcc";926 case CallingConventionAsync: return "Async";
927 case CallingConventionAsync: return "async";927 case CallingConventionInterrupt: return "Interrupt";
928 }928 case CallingConventionSignal: return "Signal";
929 zig_unreachable();929 case CallingConventionStdcall: return "Stdcall";
930}930 case CallingConventionFastcall: return "Fastcall";
931931 case CallingConventionVectorcall: return "Vectorcall";
932static const char *calling_convention_fn_type_str(CallingConvention cc) {932 case CallingConventionThiscall: return "Thiscall";
933 switch (cc) {933 case CallingConventionAPCS: return "Apcs";
934 case CallingConventionUnspecified: return "";934 case CallingConventionAAPCS: return "Aapcs";
935 case CallingConventionC: return "extern ";935 case CallingConventionAAPCSVFP: return "Aapcsvfp";
936 case CallingConventionCold: return "coldcc ";
937 case CallingConventionNaked: return "nakedcc ";
938 case CallingConventionStdcall: return "stdcallcc ";
939 case CallingConventionAsync: return "async ";
940 }936 }
941 zig_unreachable();937 zig_unreachable();
942}938}
...@@ -949,7 +945,15 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {...@@ -949,7 +945,15 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {
949 case CallingConventionC:945 case CallingConventionC:
950 case CallingConventionCold:946 case CallingConventionCold:
951 case CallingConventionNaked:947 case CallingConventionNaked:
948 case CallingConventionInterrupt:
949 case CallingConventionSignal:
952 case CallingConventionStdcall:950 case CallingConventionStdcall:
951 case CallingConventionFastcall:
952 case CallingConventionVectorcall:
953 case CallingConventionThiscall:
954 case CallingConventionAPCS:
955 case CallingConventionAAPCS:
956 case CallingConventionAAPCSVFP:
953 return false;957 return false;
954 }958 }
955 zig_unreachable();959 zig_unreachable();
...@@ -1006,8 +1010,6 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1006,8 +1010,6 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
10061010
1007 // populate the name of the type1011 // populate the name of the type
1008 buf_resize(&fn_type->name, 0);1012 buf_resize(&fn_type->name, 0);
1009 const char *cc_str = calling_convention_fn_type_str(fn_type->data.fn.fn_type_id.cc);
1010 buf_appendf(&fn_type->name, "%s", cc_str);
1011 buf_appendf(&fn_type->name, "fn(");1013 buf_appendf(&fn_type->name, "fn(");
1012 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {1014 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
1013 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];1015 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
...@@ -1026,6 +1028,9 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1026,6 +1028,9 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1026 if (fn_type_id->alignment != 0) {1028 if (fn_type_id->alignment != 0) {
1027 buf_appendf(&fn_type->name, " align(%" PRIu32 ")", fn_type_id->alignment);1029 buf_appendf(&fn_type->name, " align(%" PRIu32 ")", fn_type_id->alignment);
1028 }1030 }
1031 if (fn_type_id->cc != CallingConventionUnspecified) {
1032 buf_appendf(&fn_type->name, " callconv(.%s)", calling_convention_name(fn_type_id->cc));
1033 }
1029 buf_appendf(&fn_type->name, " %s", buf_ptr(&fn_type_id->return_type->name));1034 buf_appendf(&fn_type->name, " %s", buf_ptr(&fn_type_id->return_type->name));
10301035
1031 // The fn_type is a pointer; not to be confused with the raw function type.1036 // The fn_type is a pointer; not to be confused with the raw function type.
...@@ -1444,8 +1449,6 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {...@@ -1444,8 +1449,6 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1444ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {1449ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1445 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);1450 ZigType *fn_type = new_type_table_entry(ZigTypeIdFn);
1446 buf_resize(&fn_type->name, 0);1451 buf_resize(&fn_type->name, 0);
1447 const char *cc_str = calling_convention_fn_type_str(fn_type->data.fn.fn_type_id.cc);
1448 buf_appendf(&fn_type->name, "%s", cc_str);
1449 buf_appendf(&fn_type->name, "fn(");1452 buf_appendf(&fn_type->name, "fn(");
1450 size_t i = 0;1453 size_t i = 0;
1451 for (; i < fn_type_id->next_param_index; i += 1) {1454 for (; i < fn_type_id->next_param_index; i += 1) {
...@@ -1457,7 +1460,11 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1457,7 +1460,11 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1457 const char *comma_str = (i == 0) ? "" : ",";1460 const char *comma_str = (i == 0) ? "" : ",";
1458 buf_appendf(&fn_type->name, "%svar", comma_str);1461 buf_appendf(&fn_type->name, "%svar", comma_str);
1459 }1462 }
1460 buf_appendf(&fn_type->name, ")var");1463 buf_append_str(&fn_type->name, ")");
1464 if (fn_type_id->cc != CallingConventionUnspecified) {
1465 buf_appendf(&fn_type->name, " callconv(.%s)", calling_convention_name(fn_type_id->cc));
1466 }
1467 buf_append_str(&fn_type->name, " var");
14611468
1462 fn_type->data.fn.fn_type_id = *fn_type_id;1469 fn_type->data.fn.fn_type_id = *fn_type_id;
1463 fn_type->data.fn.is_generic = true;1470 fn_type->data.fn.is_generic = true;
...@@ -1467,17 +1474,21 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1467,17 +1474,21 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1467 return fn_type;1474 return fn_type;
1468}1475}
14691476
1470void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc) {1477CallingConvention cc_from_fn_proto(AstNodeFnProto *fn_proto) {
1478 if (fn_proto->is_async)
1479 return CallingConventionAsync;
1480 // Compatible with the C ABI
1481 if (fn_proto->is_extern || fn_proto->is_export)
1482 return CallingConventionC;
1483
1484 return CallingConventionUnspecified;
1485}
1486
1487void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, CallingConvention cc, size_t param_count_alloc) {
1471 assert(proto_node->type == NodeTypeFnProto);1488 assert(proto_node->type == NodeTypeFnProto);
1472 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;1489 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
14731490
1474 if (fn_proto->cc == CallingConventionUnspecified) {1491 fn_type_id->cc = cc;
1475 bool extern_abi = fn_proto->is_extern || fn_proto->is_export;
1476 fn_type_id->cc = extern_abi ? CallingConventionC : CallingConventionUnspecified;
1477 } else {
1478 fn_type_id->cc = fn_proto->cc;
1479 }
1480
1481 fn_type_id->param_count = fn_proto->params.length;1492 fn_type_id->param_count = fn_proto->params.length;
1482 fn_type_id->param_info = allocate<FnTypeParamInfo>(param_count_alloc);1493 fn_type_id->param_info = allocate<FnTypeParamInfo>(param_count_alloc);
1483 fn_type_id->next_param_index = 0;1494 fn_type_id->next_param_index = 0;
...@@ -1691,8 +1702,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {...@@ -1691,8 +1702,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
1691 case ZigTypeIdArray:1702 case ZigTypeIdArray:
1692 return type_allowed_in_extern(g, type_entry->data.array.child_type, result);1703 return type_allowed_in_extern(g, type_entry->data.array.child_type, result);
1693 case ZigTypeIdFn:1704 case ZigTypeIdFn:
1694 *result = type_entry->data.fn.fn_type_id.cc == CallingConventionC ||1705 *result = !calling_convention_allows_zig_types(type_entry->data.fn.fn_type_id.cc);
1695 type_entry->data.fn.fn_type_id.cc == CallingConventionStdcall;
1696 return ErrorNone;1706 return ErrorNone;
1697 case ZigTypeIdPointer:1707 case ZigTypeIdPointer:
1698 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))1708 if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown)))
...@@ -1746,13 +1756,15 @@ ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {...@@ -1746,13 +1756,15 @@ ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
1746 return err_set_type;1756 return err_set_type;
1747}1757}
17481758
1749static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, ZigFn *fn_entry) {1759static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, ZigFn *fn_entry,
1760 CallingConvention cc)
1761{
1750 assert(proto_node->type == NodeTypeFnProto);1762 assert(proto_node->type == NodeTypeFnProto);
1751 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;1763 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
1752 Error err;1764 Error err;
17531765
1754 FnTypeId fn_type_id = {0};1766 FnTypeId fn_type_id = {0};
1755 init_fn_type_id(&fn_type_id, proto_node, proto_node->data.fn_proto.params.length);1767 init_fn_type_id(&fn_type_id, proto_node, cc, proto_node->data.fn_proto.params.length);
17561768
1757 for (; fn_type_id.next_param_index < fn_type_id.param_count; fn_type_id.next_param_index += 1) {1769 for (; fn_type_id.next_param_index < fn_type_id.param_count; fn_type_id.next_param_index += 1) {
1758 AstNode *param_node = fn_proto->params.at(fn_type_id.next_param_index);1770 AstNode *param_node = fn_proto->params.at(fn_type_id.next_param_index);
...@@ -2164,7 +2176,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2164,7 +2176,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2164 ZigType *field_type = resolve_struct_field_type(g, field);2176 ZigType *field_type = resolve_struct_field_type(g, field);
2165 if (field_type == nullptr) {2177 if (field_type == nullptr) {
2166 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2178 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2167 return err;2179 return ErrorSemanticAnalyzeFail;
2168 }2180 }
2169 if ((err = type_resolve(g, field->type_entry, ResolveStatusSizeKnown))) {2181 if ((err = type_resolve(g, field->type_entry, ResolveStatusSizeKnown))) {
2170 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2182 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
...@@ -2254,7 +2266,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2254,7 +2266,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2254 ZigType *field_type = resolve_struct_field_type(g, field);2266 ZigType *field_type = resolve_struct_field_type(g, field);
2255 if (field_type == nullptr) {2267 if (field_type == nullptr) {
2256 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2268 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2257 return err;2269 return ErrorSemanticAnalyzeFail;
2258 }2270 }
22592271
2260 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {2272 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
...@@ -2324,7 +2336,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {...@@ -2324,7 +2336,7 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) {
2324 &field->align))2336 &field->align))
2325 {2337 {
2326 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2338 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2327 return err;2339 return ErrorSemanticAnalyzeFail;
2328 }2340 }
2329 add_node_error(g, field->decl_node,2341 add_node_error(g, field->decl_node,
2330 buf_create_from_str("TODO implement field alignment syntax for unions. https://github.com/ziglang/zig/issues/3125"));2342 buf_create_from_str("TODO implement field alignment syntax for unions. https://github.com/ziglang/zig/issues/3125"));
...@@ -2451,6 +2463,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -2451,6 +2463,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
2451 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2463 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2452 return ErrorSemanticAnalyzeFail;2464 return ErrorSemanticAnalyzeFail;
2453 }2465 }
2466
2454 if (is_packed) {2467 if (is_packed) {
2455 if ((err = emit_error_unless_type_allowed_in_packed_union(g, field_type, union_field->decl_node))) {2468 if ((err = emit_error_unless_type_allowed_in_packed_union(g, field_type, union_field->decl_node))) {
2456 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2469 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
...@@ -2909,7 +2922,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {...@@ -2909,7 +2922,7 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
2909 &field->align))2922 &field->align))
2910 {2923 {
2911 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2924 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2912 return err;2925 return ErrorSemanticAnalyzeFail;
2913 }2926 }
2914 } else if (packed) {2927 } else if (packed) {
2915 field->align = 1;2928 field->align = 1;
...@@ -3395,27 +3408,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3395,27 +3408,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3395 get_fully_qualified_decl_name(g, &fn_table_entry->symbol_name, &tld_fn->base, false);3408 get_fully_qualified_decl_name(g, &fn_table_entry->symbol_name, &tld_fn->base, false);
3396 }3409 }
33973410
3398 if (fn_proto->is_export) {
3399 switch (fn_proto->cc) {
3400 case CallingConventionAsync: {
3401 add_node_error(g, fn_def_node,
3402 buf_sprintf("exported function cannot be async"));
3403 } break;
3404 case CallingConventionC:
3405 case CallingConventionNaked:
3406 case CallingConventionCold:
3407 case CallingConventionStdcall:
3408 case CallingConventionUnspecified:
3409 // An exported function without a specific calling
3410 // convention defaults to C
3411 CallingConvention cc = (fn_proto->cc != CallingConventionUnspecified) ?
3412 fn_proto->cc : CallingConventionC;
3413 add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name),
3414 GlobalLinkageIdStrong, cc);
3415 break;
3416 }
3417 }
3418
3419 if (!is_extern) {3411 if (!is_extern) {
3420 fn_table_entry->fndef_scope = create_fndef_scope(g,3412 fn_table_entry->fndef_scope = create_fndef_scope(g,
3421 fn_table_entry->body_node, tld_fn->base.parent_scope, fn_table_entry);3413 fn_table_entry->body_node, tld_fn->base.parent_scope, fn_table_entry);
...@@ -3434,19 +3426,72 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3434,19 +3426,72 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
34343426
3435 Scope *child_scope = fn_table_entry->fndef_scope ? &fn_table_entry->fndef_scope->base : tld_fn->base.parent_scope;3427 Scope *child_scope = fn_table_entry->fndef_scope ? &fn_table_entry->fndef_scope->base : tld_fn->base.parent_scope;
34363428
3437 fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry);3429 CallingConvention cc;
3430 if (fn_proto->callconv_expr != nullptr) {
3431 ZigType *cc_enum_value = get_builtin_type(g, "CallingConvention");
3432
3433 ZigValue *result_val = analyze_const_value(g, child_scope, fn_proto->callconv_expr,
3434 cc_enum_value, nullptr, UndefBad);
3435 if (type_is_invalid(result_val->type)) {
3436 fn_table_entry->type_entry = g->builtin_types.entry_invalid;
3437 tld_fn->base.resolution = TldResolutionInvalid;
3438 return;
3439 }
3440
3441 cc = (CallingConvention)bigint_as_u32(&result_val->data.x_enum_tag);
3442 } else {
3443 cc = cc_from_fn_proto(fn_proto);
3444 }
34383445
3439 if (fn_proto->section_expr != nullptr) {3446 if (fn_proto->section_expr != nullptr) {
3440 if (!analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name)) {3447 if (!analyze_const_string(g, child_scope, fn_proto->section_expr, &fn_table_entry->section_name)) {
3441 fn_table_entry->type_entry = g->builtin_types.entry_invalid;3448 fn_table_entry->type_entry = g->builtin_types.entry_invalid;
3449 tld_fn->base.resolution = TldResolutionInvalid;
3450 return;
3442 }3451 }
3443 }3452 }
34443453
3445 if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) {3454 fn_table_entry->type_entry = analyze_fn_type(g, source_node, child_scope, fn_table_entry, cc);
3455
3456 if (type_is_invalid(fn_table_entry->type_entry)) {
3446 tld_fn->base.resolution = TldResolutionInvalid;3457 tld_fn->base.resolution = TldResolutionInvalid;
3447 return;3458 return;
3448 }3459 }
34493460
3461 const CallingConvention fn_cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc;
3462
3463 if (fn_proto->is_export) {
3464 switch (fn_cc) {
3465 case CallingConventionAsync:
3466 add_node_error(g, fn_def_node,
3467 buf_sprintf("exported function cannot be async"));
3468 fn_table_entry->type_entry = g->builtin_types.entry_invalid;
3469 tld_fn->base.resolution = TldResolutionInvalid;
3470 return;
3471 case CallingConventionC:
3472 case CallingConventionCold:
3473 case CallingConventionNaked:
3474 case CallingConventionInterrupt:
3475 case CallingConventionSignal:
3476 case CallingConventionStdcall:
3477 case CallingConventionFastcall:
3478 case CallingConventionVectorcall:
3479 case CallingConventionThiscall:
3480 case CallingConventionAPCS:
3481 case CallingConventionAAPCS:
3482 case CallingConventionAAPCSVFP:
3483 add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name),
3484 GlobalLinkageIdStrong, fn_cc);
3485 break;
3486 case CallingConventionUnspecified:
3487 // An exported function without a specific calling
3488 // convention defaults to C
3489 add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name),
3490 GlobalLinkageIdStrong, CallingConventionC);
3491 break;
3492 }
3493 }
3494
3450 if (!fn_table_entry->type_entry->data.fn.is_generic) {3495 if (!fn_table_entry->type_entry->data.fn.is_generic) {
3451 if (fn_def_node)3496 if (fn_def_node)
3452 g->fn_defs.append(fn_table_entry);3497 g->fn_defs.append(fn_table_entry);
...@@ -3455,7 +3500,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3455,7 +3500,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3455 // if the calling convention implies that it cannot be async, we save that for later3500 // if the calling convention implies that it cannot be async, we save that for later
3456 // and leave the value to be nullptr to indicate that we have not emitted possible3501 // and leave the value to be nullptr to indicate that we have not emitted possible
3457 // compile errors for improperly calling async functions.3502 // compile errors for improperly calling async functions.
3458 if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) {3503 if (fn_cc == CallingConventionAsync) {
3459 fn_table_entry->inferred_async_node = fn_table_entry->proto_node;3504 fn_table_entry->inferred_async_node = fn_table_entry->proto_node;
3460 }3505 }
3461 } else if (source_node->type == NodeTypeTestDecl) {3506 } else if (source_node->type == NodeTypeTestDecl) {
...@@ -4338,7 +4383,7 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) {...@@ -4338,7 +4383,7 @@ uint32_t get_ptr_align(CodeGen *g, ZigType *type) {
4338 } else if (ptr_type->id == ZigTypeIdFn) {4383 } else if (ptr_type->id == ZigTypeIdFn) {
4339 // I tried making this use LLVMABIAlignmentOfType but it trips this assertion in LLVM:4384 // I tried making this use LLVMABIAlignmentOfType but it trips this assertion in LLVM:
4340 // "Cannot getTypeInfo() on a type that is unsized!"4385 // "Cannot getTypeInfo() on a type that is unsized!"
4341 // when getting the alignment of `?extern fn() void`.4386 // when getting the alignment of `?fn() callconv(.C) void`.
4342 // See http://lists.llvm.org/pipermail/llvm-dev/2018-September/126142.html4387 // See http://lists.llvm.org/pipermail/llvm-dev/2018-September/126142.html
4343 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;4388 return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment;
4344 } else if (ptr_type->id == ZigTypeIdAnyFrame) {4389 } else if (ptr_type->id == ZigTypeIdAnyFrame) {
src/analyze.hpp+2-1
...@@ -100,7 +100,7 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);...@@ -100,7 +100,7 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node);
100void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type);100void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type);
101ZigFn *create_fn(CodeGen *g, AstNode *proto_node);101ZigFn *create_fn(CodeGen *g, AstNode *proto_node);
102ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value);102ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value);
103void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc);103void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, CallingConvention cc, size_t param_count_alloc);
104AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);104AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index);
105Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);105Error ATTRIBUTE_MUST_USE type_resolve(CodeGen *g, ZigType *type_entry, ResolveStatus status);
106void complete_enum(CodeGen *g, ZigType *enum_type);106void complete_enum(CodeGen *g, ZigType *enum_type);
...@@ -259,6 +259,7 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *...@@ -259,6 +259,7 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *
259259
260void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);260void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);
261bool fn_is_async(ZigFn *fn);261bool fn_is_async(ZigFn *fn);
262CallingConvention cc_from_fn_proto(AstNodeFnProto *fn_proto);
262263
263Error type_val_resolve_abi_align(CodeGen *g, AstNode *source_node, ZigValue *type_val, uint32_t *abi_align);264Error type_val_resolve_abi_align(CodeGen *g, AstNode *source_node, ZigValue *type_val, uint32_t *abi_align);
264Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ZigValue *type_val,265Error type_val_resolve_abi_size(CodeGen *g, AstNode *source_node, ZigValue *type_val,
src/ast_render.cpp+5
...@@ -488,6 +488,11 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -488,6 +488,11 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
488 render_node_grouped(ar, node->data.fn_proto.section_expr);488 render_node_grouped(ar, node->data.fn_proto.section_expr);
489 fprintf(ar->f, ")");489 fprintf(ar->f, ")");
490 }490 }
491 if (node->data.fn_proto.callconv_expr) {
492 fprintf(ar->f, " callconv(");
493 render_node_grouped(ar, node->data.fn_proto.callconv_expr);
494 fprintf(ar->f, ")");
495 }
491496
492 if (node->data.fn_proto.return_var_token != nullptr) {497 if (node->data.fn_proto.return_var_token != nullptr) {
493 fprintf(ar->f, "var");498 fprintf(ar->f, "var");
src/codegen.cpp+81-35
...@@ -263,36 +263,66 @@ static const char *get_mangled_name(CodeGen *g, const char *original_name, bool...@@ -263,36 +263,66 @@ static const char *get_mangled_name(CodeGen *g, const char *original_name, bool
263 }263 }
264}264}
265265
266static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {266static ZigLLVM_CallingConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
267 switch (cc) {267 switch (cc) {
268 case CallingConventionUnspecified: return LLVMFastCallConv;268 case CallingConventionUnspecified:
269 case CallingConventionC: return LLVMCCallConv;269 return ZigLLVM_Fast;
270 case CallingConventionC:
271 return ZigLLVM_C;
270 case CallingConventionCold:272 case CallingConventionCold:
271 // cold calling convention only works on x86.273 if ((g->zig_target->arch == ZigLLVM_x86 ||
272 if (g->zig_target->arch == ZigLLVM_x86 ||274 g->zig_target->arch == ZigLLVM_x86_64) &&
273 g->zig_target->arch == ZigLLVM_x86_64)275 g->zig_target->os != OsWindows)
274 {276 return ZigLLVM_Cold;
275 // cold calling convention is not supported on windows277 return ZigLLVM_C;
276 if (g->zig_target->os == OsWindows) {
277 return LLVMCCallConv;
278 } else {
279 return LLVMColdCallConv;
280 }
281 } else {
282 return LLVMCCallConv;
283 }
284 break;
285 case CallingConventionNaked:278 case CallingConventionNaked:
286 zig_unreachable();279 zig_unreachable();
287 case CallingConventionStdcall:280 case CallingConventionStdcall:
288 // stdcall calling convention only works on x86.281 if (g->zig_target->arch == ZigLLVM_x86)
289 if (g->zig_target->arch == ZigLLVM_x86) {282 return ZigLLVM_X86_StdCall;
290 return LLVMX86StdcallCallConv;283 return ZigLLVM_C;
291 } else {284 case CallingConventionFastcall:
292 return LLVMCCallConv;285 if (g->zig_target->arch == ZigLLVM_x86)
293 }286 return ZigLLVM_X86_FastCall;
287 return ZigLLVM_C;
288 case CallingConventionVectorcall:
289 if (g->zig_target->arch == ZigLLVM_x86)
290 return ZigLLVM_X86_VectorCall;
291 if (target_is_arm(g->zig_target) &&
292 target_arch_pointer_bit_width(g->zig_target->arch) == 64)
293 return ZigLLVM_AArch64_VectorCall;
294 return ZigLLVM_C;
295 case CallingConventionThiscall:
296 if (g->zig_target->arch == ZigLLVM_x86)
297 return ZigLLVM_X86_ThisCall;
298 return ZigLLVM_C;
294 case CallingConventionAsync:299 case CallingConventionAsync:
295 return LLVMFastCallConv;300 return ZigLLVM_Fast;
301 case CallingConventionAPCS:
302 if (target_is_arm(g->zig_target))
303 return ZigLLVM_ARM_APCS;
304 return ZigLLVM_C;
305 case CallingConventionAAPCS:
306 if (target_is_arm(g->zig_target))
307 return ZigLLVM_ARM_AAPCS;
308 return ZigLLVM_C;
309 case CallingConventionAAPCSVFP:
310 if (target_is_arm(g->zig_target))
311 return ZigLLVM_ARM_AAPCS_VFP;
312 return ZigLLVM_C;
313 case CallingConventionInterrupt:
314 if (g->zig_target->arch == ZigLLVM_x86 ||
315 g->zig_target->arch == ZigLLVM_x86_64)
316 return ZigLLVM_X86_INTR;
317 if (g->zig_target->arch == ZigLLVM_avr)
318 return ZigLLVM_AVR_INTR;
319 if (g->zig_target->arch == ZigLLVM_msp430)
320 return ZigLLVM_MSP430_INTR;
321 return ZigLLVM_C;
322 case CallingConventionSignal:
323 if (g->zig_target->arch == ZigLLVM_avr)
324 return ZigLLVM_AVR_SIGNAL;
325 return ZigLLVM_C;
296 }326 }
297 zig_unreachable();327 zig_unreachable();
298}328}
...@@ -384,7 +414,15 @@ static bool cc_want_sret_attr(CallingConvention cc) {...@@ -384,7 +414,15 @@ static bool cc_want_sret_attr(CallingConvention cc) {
384 zig_unreachable();414 zig_unreachable();
385 case CallingConventionC:415 case CallingConventionC:
386 case CallingConventionCold:416 case CallingConventionCold:
417 case CallingConventionInterrupt:
418 case CallingConventionSignal:
387 case CallingConventionStdcall:419 case CallingConventionStdcall:
420 case CallingConventionFastcall:
421 case CallingConventionVectorcall:
422 case CallingConventionThiscall:
423 case CallingConventionAPCS:
424 case CallingConventionAAPCS:
425 case CallingConventionAAPCSVFP:
388 return true;426 return true;
389 case CallingConventionAsync:427 case CallingConventionAsync:
390 case CallingConventionUnspecified:428 case CallingConventionUnspecified:
...@@ -481,7 +519,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {...@@ -481,7 +519,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
481 if (cc == CallingConventionNaked) {519 if (cc == CallingConventionNaked) {
482 addLLVMFnAttr(llvm_fn, "naked");520 addLLVMFnAttr(llvm_fn, "naked");
483 } else {521 } else {
484 LLVMSetFunctionCallConv(llvm_fn, get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc));522 ZigLLVMFunctionSetCallingConv(llvm_fn, get_llvm_cc(g, cc));
485 }523 }
486524
487 bool want_cold = fn->is_cold || cc == CallingConventionCold;525 bool want_cold = fn->is_cold || cc == CallingConventionCold;
...@@ -976,7 +1014,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace...@@ -976,7 +1014,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace
976{1014{
977 assert(g->panic_fn != nullptr);1015 assert(g->panic_fn != nullptr);
978 LLVMValueRef fn_val = fn_llvm_value(g, g->panic_fn);1016 LLVMValueRef fn_val = fn_llvm_value(g, g->panic_fn);
979 LLVMCallConv llvm_cc = get_llvm_cc(g, g->panic_fn->type_entry->data.fn.fn_type_id.cc);1017 ZigLLVM_CallingConv llvm_cc = get_llvm_cc(g, g->panic_fn->type_entry->data.fn.fn_type_id.cc);
980 if (stack_trace_arg == nullptr) {1018 if (stack_trace_arg == nullptr) {
981 stack_trace_arg = LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));1019 stack_trace_arg = LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));
982 }1020 }
...@@ -1087,7 +1125,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {...@@ -1087,7 +1125,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
1087 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);1125 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);
1088 addLLVMFnAttr(fn_val, "alwaysinline");1126 addLLVMFnAttr(fn_val, "alwaysinline");
1089 LLVMSetLinkage(fn_val, LLVMInternalLinkage);1127 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
1090 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));1128 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
1091 addLLVMFnAttr(fn_val, "nounwind");1129 addLLVMFnAttr(fn_val, "nounwind");
1092 add_uwtable_attr(g, fn_val);1130 add_uwtable_attr(g, fn_val);
1093 // Error return trace memory is in the stack, which is impossible to be at address 01131 // Error return trace memory is in the stack, which is impossible to be at address 0
...@@ -1168,7 +1206,7 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) {...@@ -1168,7 +1206,7 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) {
1168 addLLVMFnAttr(fn_val, "noinline"); // so that we can look at return address1206 addLLVMFnAttr(fn_val, "noinline"); // so that we can look at return address
1169 addLLVMFnAttr(fn_val, "cold");1207 addLLVMFnAttr(fn_val, "cold");
1170 LLVMSetLinkage(fn_val, LLVMInternalLinkage);1208 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
1171 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));1209 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
1172 addLLVMFnAttr(fn_val, "nounwind");1210 addLLVMFnAttr(fn_val, "nounwind");
1173 add_uwtable_attr(g, fn_val);1211 add_uwtable_attr(g, fn_val);
1174 if (codegen_have_frame_pointer(g)) {1212 if (codegen_have_frame_pointer(g)) {
...@@ -1252,7 +1290,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {...@@ -1252,7 +1290,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
1252 addLLVMFnAttr(fn_val, "noreturn");1290 addLLVMFnAttr(fn_val, "noreturn");
1253 addLLVMFnAttr(fn_val, "cold");1291 addLLVMFnAttr(fn_val, "cold");
1254 LLVMSetLinkage(fn_val, LLVMInternalLinkage);1292 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
1255 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));1293 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
1256 addLLVMFnAttr(fn_val, "nounwind");1294 addLLVMFnAttr(fn_val, "nounwind");
1257 add_uwtable_attr(g, fn_val);1295 add_uwtable_attr(g, fn_val);
1258 if (codegen_have_frame_pointer(g)) {1296 if (codegen_have_frame_pointer(g)) {
...@@ -2148,7 +2186,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {...@@ -2148,7 +2186,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
2148 const char *fn_name = get_mangled_name(g, "__zig_merge_error_return_traces", false);2186 const char *fn_name = get_mangled_name(g, "__zig_merge_error_return_traces", false);
2149 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);2187 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);
2150 LLVMSetLinkage(fn_val, LLVMInternalLinkage);2188 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
2151 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));2189 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
2152 addLLVMFnAttr(fn_val, "nounwind");2190 addLLVMFnAttr(fn_val, "nounwind");
2153 add_uwtable_attr(g, fn_val);2191 add_uwtable_attr(g, fn_val);
2154 addLLVMArgAttr(fn_val, (unsigned)0, "noalias");2192 addLLVMArgAttr(fn_val, (unsigned)0, "noalias");
...@@ -2325,7 +2363,7 @@ static LLVMValueRef gen_resume(CodeGen *g, LLVMValueRef fn_val, LLVMValueRef tar...@@ -2325,7 +2363,7 @@ static LLVMValueRef gen_resume(CodeGen *g, LLVMValueRef fn_val, LLVMValueRef tar
2325 LLVMValueRef arg_val = LLVMConstSub(LLVMConstAllOnes(usize_type_ref),2363 LLVMValueRef arg_val = LLVMConstSub(LLVMConstAllOnes(usize_type_ref),
2326 LLVMConstInt(usize_type_ref, resume_id, false));2364 LLVMConstInt(usize_type_ref, resume_id, false));
2327 LLVMValueRef args[] = {target_frame_ptr, arg_val};2365 LLVMValueRef args[] = {target_frame_ptr, arg_val};
2328 return ZigLLVMBuildCall(g->builder, fn_val, args, 2, LLVMFastCallConv, ZigLLVM_CallAttrAuto, "");2366 return ZigLLVMBuildCall(g->builder, fn_val, args, 2, ZigLLVM_Fast, ZigLLVM_CallAttrAuto, "");
2329}2367}
23302368
2331static LLVMBasicBlockRef gen_suspend_begin(CodeGen *g, const char *name_hint) {2369static LLVMBasicBlockRef gen_suspend_begin(CodeGen *g, const char *name_hint) {
...@@ -4215,7 +4253,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4215,7 +4253,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4215 break;4253 break;
4216 }4254 }
42174255
4218 LLVMCallConv llvm_cc = get_llvm_cc(g, cc);4256 ZigLLVM_CallingConv llvm_cc = get_llvm_cc(g, cc);
4219 LLVMValueRef result;4257 LLVMValueRef result;
42204258
4221 if (callee_is_async) {4259 if (callee_is_async) {
...@@ -4925,7 +4963,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {...@@ -4925,7 +4963,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
4925 buf_ptr(buf_sprintf("__zig_tag_name_%s", buf_ptr(&enum_type->name))), false);4963 buf_ptr(buf_sprintf("__zig_tag_name_%s", buf_ptr(&enum_type->name))), false);
4926 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);4964 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);
4927 LLVMSetLinkage(fn_val, LLVMInternalLinkage);4965 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
4928 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));4966 ZigLLVMFunctionSetCallingConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
4929 addLLVMFnAttr(fn_val, "nounwind");4967 addLLVMFnAttr(fn_val, "nounwind");
4930 add_uwtable_attr(g, fn_val);4968 add_uwtable_attr(g, fn_val);
4931 if (codegen_have_frame_pointer(g)) {4969 if (codegen_have_frame_pointer(g)) {
...@@ -8463,8 +8501,16 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8463,8 +8501,16 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8463 static_assert(CallingConventionC == 1, "");8501 static_assert(CallingConventionC == 1, "");
8464 static_assert(CallingConventionCold == 2, "");8502 static_assert(CallingConventionCold == 2, "");
8465 static_assert(CallingConventionNaked == 3, "");8503 static_assert(CallingConventionNaked == 3, "");
8466 static_assert(CallingConventionStdcall == 4, "");8504 static_assert(CallingConventionAsync == 4, "");
8467 static_assert(CallingConventionAsync == 5, "");8505 static_assert(CallingConventionInterrupt == 5, "");
8506 static_assert(CallingConventionSignal == 6, "");
8507 static_assert(CallingConventionStdcall == 7, "");
8508 static_assert(CallingConventionFastcall == 8, "");
8509 static_assert(CallingConventionVectorcall == 9, "");
8510 static_assert(CallingConventionThiscall == 10, "");
8511 static_assert(CallingConventionAPCS == 11, "");
8512 static_assert(CallingConventionAAPCS == 12, "");
8513 static_assert(CallingConventionAAPCSVFP == 13, "");
84688514
8469 static_assert(FnInlineAuto == 0, "");8515 static_assert(FnInlineAuto == 0, "");
8470 static_assert(FnInlineAlways == 1, "");8516 static_assert(FnInlineAlways == 1, "");
src/ir.cpp+65-37
...@@ -3248,12 +3248,13 @@ static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope,...@@ -3248,12 +3248,13 @@ static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope,
3248}3248}
32493249
3250static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,3250static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,
3251 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *return_type,3251 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *callconv_value,
3252 bool is_var_args)3252 IrInstruction *return_type, bool is_var_args)
3253{3253{
3254 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);3254 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);
3255 instruction->param_types = param_types;3255 instruction->param_types = param_types;
3256 instruction->align_value = align_value;3256 instruction->align_value = align_value;
3257 instruction->callconv_value = callconv_value;
3257 instruction->return_type = return_type;3258 instruction->return_type = return_type;
3258 instruction->is_var_args = is_var_args;3259 instruction->is_var_args = is_var_args;
32593260
...@@ -3264,6 +3265,7 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3264,6 +3265,7 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s
3264 if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], irb->current_basic_block);3265 if (param_types[i] != nullptr) ir_ref_instruction(param_types[i], irb->current_basic_block);
3265 }3266 }
3266 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);3267 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
3268 if (callconv_value != nullptr) ir_ref_instruction(callconv_value, irb->current_basic_block);
3267 ir_ref_instruction(return_type, irb->current_basic_block);3269 ir_ref_instruction(return_type, irb->current_basic_block);
32683270
3269 return &instruction->base;3271 return &instruction->base;
...@@ -8843,6 +8845,13 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -8843,6 +8845,13 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
8843 return irb->codegen->invalid_instruction;8845 return irb->codegen->invalid_instruction;
8844 }8846 }
88458847
8848 IrInstruction *callconv_value = nullptr;
8849 if (node->data.fn_proto.callconv_expr != nullptr) {
8850 callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope);
8851 if (callconv_value == irb->codegen->invalid_instruction)
8852 return irb->codegen->invalid_instruction;
8853 }
8854
8846 IrInstruction *return_type;8855 IrInstruction *return_type;
8847 if (node->data.fn_proto.return_var_token == nullptr) {8856 if (node->data.fn_proto.return_var_token == nullptr) {
8848 if (node->data.fn_proto.return_type == nullptr) {8857 if (node->data.fn_proto.return_type == nullptr) {
...@@ -8859,7 +8868,7 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -8859,7 +8868,7 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
8859 //return_type = nullptr;8868 //return_type = nullptr;
8860 }8869 }
88618870
8862 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, return_type, is_var_args);8871 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);
8863}8872}
88648873
8865static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) {8874static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) {
...@@ -16729,9 +16738,17 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16729,9 +16738,17 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16729 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));16738 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
16730 } break;16739 } break;
16731 case CallingConventionC:16740 case CallingConventionC:
16732 case CallingConventionNaked:
16733 case CallingConventionCold:16741 case CallingConventionCold:
16742 case CallingConventionNaked:
16743 case CallingConventionInterrupt:
16744 case CallingConventionSignal:
16734 case CallingConventionStdcall:16745 case CallingConventionStdcall:
16746 case CallingConventionFastcall:
16747 case CallingConventionVectorcall:
16748 case CallingConventionThiscall:
16749 case CallingConventionAPCS:
16750 case CallingConventionAAPCS:
16751 case CallingConventionAAPCSVFP:
16735 add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id, cc);16752 add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id, cc);
16736 break;16753 break;
16737 }16754 }
...@@ -18094,7 +18111,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18094,7 +18111,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18094 return ira->codegen->invalid_instruction;18111 return ira->codegen->invalid_instruction;
18095 }18112 }
1809618113
18097
18098 if (fn_type_id->is_var_args) {18114 if (fn_type_id->is_var_args) {
18099 if (call_param_count < src_param_count) {18115 if (call_param_count < src_param_count) {
18100 ErrorMsg *msg = ir_add_error_node(ira, source_node,18116 ErrorMsg *msg = ir_add_error_node(ira, source_node,
...@@ -18248,7 +18264,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18248,7 +18264,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18248 impl_fn->fndef_scope = create_fndef_scope(ira->codegen, impl_fn->body_node, parent_scope, impl_fn);18264 impl_fn->fndef_scope = create_fndef_scope(ira->codegen, impl_fn->body_node, parent_scope, impl_fn);
18249 impl_fn->child_scope = &impl_fn->fndef_scope->base;18265 impl_fn->child_scope = &impl_fn->fndef_scope->base;
18250 FnTypeId inst_fn_type_id = {0};18266 FnTypeId inst_fn_type_id = {0};
18251 init_fn_type_id(&inst_fn_type_id, fn_proto_node, new_fn_arg_count);18267 init_fn_type_id(&inst_fn_type_id, fn_proto_node, fn_type_id->cc, new_fn_arg_count);
18252 inst_fn_type_id.param_count = 0;18268 inst_fn_type_id.param_count = 0;
18253 inst_fn_type_id.is_var_args = false;18269 inst_fn_type_id.is_var_args = false;
1825418270
...@@ -22582,50 +22598,45 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -22582,50 +22598,45 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
22582 fn_decl_fields[1]->special = ConstValSpecialStatic;22598 fn_decl_fields[1]->special = ConstValSpecialStatic;
22583 fn_decl_fields[1]->type = type_info_fn_decl_inline_type;22599 fn_decl_fields[1]->type = type_info_fn_decl_inline_type;
22584 bigint_init_unsigned(&fn_decl_fields[1]->data.x_enum_tag, fn_entry->fn_inline);22600 bigint_init_unsigned(&fn_decl_fields[1]->data.x_enum_tag, fn_entry->fn_inline);
22585 // calling_convention: TypeInfo.CallingConvention
22586 ensure_field_index(fn_decl_val->type, "calling_convention", 2);
22587 fn_decl_fields[2]->special = ConstValSpecialStatic;
22588 fn_decl_fields[2]->type = ir_type_info_get_type(ira, "CallingConvention", nullptr);
22589 bigint_init_unsigned(&fn_decl_fields[2]->data.x_enum_tag, fn_node->cc);
22590 // is_var_args: bool22601 // is_var_args: bool
22591 ensure_field_index(fn_decl_val->type, "is_var_args", 3);22602 ensure_field_index(fn_decl_val->type, "is_var_args", 2);
22592 bool is_varargs = fn_node->is_var_args;22603 bool is_varargs = fn_node->is_var_args;
22604 fn_decl_fields[2]->special = ConstValSpecialStatic;
22605 fn_decl_fields[2]->type = ira->codegen->builtin_types.entry_bool;
22606 fn_decl_fields[2]->data.x_bool = is_varargs;
22607 // is_extern: bool
22608 ensure_field_index(fn_decl_val->type, "is_extern", 3);
22593 fn_decl_fields[3]->special = ConstValSpecialStatic;22609 fn_decl_fields[3]->special = ConstValSpecialStatic;
22594 fn_decl_fields[3]->type = ira->codegen->builtin_types.entry_bool;22610 fn_decl_fields[3]->type = ira->codegen->builtin_types.entry_bool;
22595 fn_decl_fields[3]->data.x_bool = is_varargs;22611 fn_decl_fields[3]->data.x_bool = fn_node->is_extern;
22596 // is_extern: bool22612 // is_export: bool
22597 ensure_field_index(fn_decl_val->type, "is_extern", 4);22613 ensure_field_index(fn_decl_val->type, "is_export", 4);
22598 fn_decl_fields[4]->special = ConstValSpecialStatic;22614 fn_decl_fields[4]->special = ConstValSpecialStatic;
22599 fn_decl_fields[4]->type = ira->codegen->builtin_types.entry_bool;22615 fn_decl_fields[4]->type = ira->codegen->builtin_types.entry_bool;
22600 fn_decl_fields[4]->data.x_bool = fn_node->is_extern;22616 fn_decl_fields[4]->data.x_bool = fn_node->is_export;
22601 // is_export: bool
22602 ensure_field_index(fn_decl_val->type, "is_export", 5);
22603 fn_decl_fields[5]->special = ConstValSpecialStatic;
22604 fn_decl_fields[5]->type = ira->codegen->builtin_types.entry_bool;
22605 fn_decl_fields[5]->data.x_bool = fn_node->is_export;
22606 // lib_name: ?[]const u822617 // lib_name: ?[]const u8
22607 ensure_field_index(fn_decl_val->type, "lib_name", 6);22618 ensure_field_index(fn_decl_val->type, "lib_name", 5);
22608 fn_decl_fields[6]->special = ConstValSpecialStatic;22619 fn_decl_fields[5]->special = ConstValSpecialStatic;
22609 ZigType *u8_ptr = get_pointer_to_type_extra(22620 ZigType *u8_ptr = get_pointer_to_type_extra(
22610 ira->codegen, ira->codegen->builtin_types.entry_u8,22621 ira->codegen, ira->codegen->builtin_types.entry_u8,
22611 true, false, PtrLenUnknown,22622 true, false, PtrLenUnknown,
22612 0, 0, 0, false);22623 0, 0, 0, false);
22613 fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));22624 fn_decl_fields[5]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
22614 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {22625 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
22615 fn_decl_fields[6]->data.x_optional = create_const_vals(1);22626 fn_decl_fields[5]->data.x_optional = create_const_vals(1);
22616 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;22627 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
22617 init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0,22628 init_const_slice(ira->codegen, fn_decl_fields[5]->data.x_optional, lib_name, 0,
22618 buf_len(fn_node->lib_name), true);22629 buf_len(fn_node->lib_name), true);
22619 } else {22630 } else {
22620 fn_decl_fields[6]->data.x_optional = nullptr;22631 fn_decl_fields[5]->data.x_optional = nullptr;
22621 }22632 }
22622 // return_type: type22633 // return_type: type
22623 ensure_field_index(fn_decl_val->type, "return_type", 7);22634 ensure_field_index(fn_decl_val->type, "return_type", 6);
22624 fn_decl_fields[7]->special = ConstValSpecialStatic;22635 fn_decl_fields[6]->special = ConstValSpecialStatic;
22625 fn_decl_fields[7]->type = ira->codegen->builtin_types.entry_type;22636 fn_decl_fields[6]->type = ira->codegen->builtin_types.entry_type;
22626 fn_decl_fields[7]->data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;22637 fn_decl_fields[6]->data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
22627 // arg_names: [][] const u822638 // arg_names: [][] const u8
22628 ensure_field_index(fn_decl_val->type, "arg_names", 8);22639 ensure_field_index(fn_decl_val->type, "arg_names", 7);
22629 size_t fn_arg_count = fn_entry->variable_list.length;22640 size_t fn_arg_count = fn_entry->variable_list.length;
22630 ZigValue *fn_arg_name_array = create_const_vals(1);22641 ZigValue *fn_arg_name_array = create_const_vals(1);
22631 fn_arg_name_array->special = ConstValSpecialStatic;22642 fn_arg_name_array->special = ConstValSpecialStatic;
...@@ -22634,7 +22645,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -22634,7 +22645,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
22634 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;22645 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
22635 fn_arg_name_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);22646 fn_arg_name_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
2263622647
22637 init_const_slice(ira->codegen, fn_decl_fields[8], fn_arg_name_array, 0, fn_arg_count, false);22648 init_const_slice(ira->codegen, fn_decl_fields[7], fn_arg_name_array, 0, fn_arg_count, false);
2263822649
22639 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {22650 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
22640 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);22651 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
...@@ -23273,7 +23284,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -23273,7 +23284,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
23273 // calling_convention: TypeInfo.CallingConvention23284 // calling_convention: TypeInfo.CallingConvention
23274 ensure_field_index(result->type, "calling_convention", 0);23285 ensure_field_index(result->type, "calling_convention", 0);
23275 fields[0]->special = ConstValSpecialStatic;23286 fields[0]->special = ConstValSpecialStatic;
23276 fields[0]->type = ir_type_info_get_type(ira, "CallingConvention", nullptr);23287 fields[0]->type = get_builtin_type(ira->codegen, "CallingConvention");
23277 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);23288 bigint_init_unsigned(&fields[0]->data.x_enum_tag, type_entry->data.fn.fn_type_id.cc);
23278 // is_generic: bool23289 // is_generic: bool
23279 ensure_field_index(result->type, "is_generic", 1);23290 ensure_field_index(result->type, "is_generic", 1);
...@@ -26185,6 +26196,21 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -26185,6 +26196,21 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
26185 return ira->codegen->invalid_instruction;26196 return ira->codegen->invalid_instruction;
26186 }26197 }
2618726198
26199 lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto);
26200 if (instruction->callconv_value != nullptr) {
26201 ZigType *cc_enum_type = get_builtin_type(ira->codegen, "CallingConvention");
26202
26203 IrInstruction *casted_value = ir_implicit_cast(ira, instruction->callconv_value, cc_enum_type);
26204 if (type_is_invalid(casted_value->value->type))
26205 return ira->codegen->invalid_instruction;
26206
26207 ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad);
26208 if (const_value == nullptr)
26209 return ira->codegen->invalid_instruction;
26210
26211 lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag);
26212 }
26213
26188 size_t param_count = proto_node->data.fn_proto.params.length;26214 size_t param_count = proto_node->data.fn_proto.params.length;
26189 lazy_fn_type->proto_node = proto_node;26215 lazy_fn_type->proto_node = proto_node;
26190 lazy_fn_type->param_types = allocate<IrInstruction *>(param_count);26216 lazy_fn_type->param_types = allocate<IrInstruction *>(param_count);
...@@ -26195,9 +26221,11 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -26195,9 +26221,11 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
2619526221
26196 bool param_is_var_args = param_node->data.param_decl.is_var_args;26222 bool param_is_var_args = param_node->data.param_decl.is_var_args;
26197 if (param_is_var_args) {26223 if (param_is_var_args) {
26198 if (proto_node->data.fn_proto.cc == CallingConventionC) {26224 const CallingConvention cc = lazy_fn_type->cc;
26225
26226 if (cc == CallingConventionC) {
26199 break;26227 break;
26200 } else if (proto_node->data.fn_proto.cc == CallingConventionUnspecified) {26228 } else if (cc == CallingConventionUnspecified) {
26201 lazy_fn_type->is_generic = true;26229 lazy_fn_type->is_generic = true;
26202 return result;26230 return result;
26203 } else {26231 } else {
...@@ -29076,7 +29104,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -29076,7 +29104,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
29076 AstNode *proto_node = lazy_fn_type->proto_node;29104 AstNode *proto_node = lazy_fn_type->proto_node;
2907729105
29078 FnTypeId fn_type_id = {0};29106 FnTypeId fn_type_id = {0};
29079 init_fn_type_id(&fn_type_id, proto_node, proto_node->data.fn_proto.params.length);29107 init_fn_type_id(&fn_type_id, proto_node, lazy_fn_type->cc, proto_node->data.fn_proto.params.length);
2908029108
29081 for (; fn_type_id.next_param_index < fn_type_id.param_count; fn_type_id.next_param_index += 1) {29109 for (; fn_type_id.next_param_index < fn_type_id.param_count; fn_type_id.next_param_index += 1) {
29082 AstNode *param_node = proto_node->data.fn_proto.params.at(fn_type_id.next_param_index);29110 AstNode *param_node = proto_node->data.fn_proto.params.at(fn_type_id.next_param_index);
src/parser.cpp+23-16
...@@ -92,6 +92,7 @@ static Token *ast_parse_block_label(ParseContext *pc);...@@ -92,6 +92,7 @@ static Token *ast_parse_block_label(ParseContext *pc);
92static AstNode *ast_parse_field_init(ParseContext *pc);92static AstNode *ast_parse_field_init(ParseContext *pc);
93static AstNode *ast_parse_while_continue_expr(ParseContext *pc);93static AstNode *ast_parse_while_continue_expr(ParseContext *pc);
94static AstNode *ast_parse_link_section(ParseContext *pc);94static AstNode *ast_parse_link_section(ParseContext *pc);
95static AstNode *ast_parse_callconv(ParseContext *pc);
95static Optional<AstNodeFnProto> ast_parse_fn_cc(ParseContext *pc);96static Optional<AstNodeFnProto> ast_parse_fn_cc(ParseContext *pc);
96static AstNode *ast_parse_param_decl(ParseContext *pc);97static AstNode *ast_parse_param_decl(ParseContext *pc);
97static AstNode *ast_parse_param_type(ParseContext *pc);98static AstNode *ast_parse_param_type(ParseContext *pc);
...@@ -676,7 +677,9 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B...@@ -676,7 +677,9 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B
676 fn_proto->column = first->start_column;677 fn_proto->column = first->start_column;
677 fn_proto->data.fn_proto.visib_mod = visib_mod;678 fn_proto->data.fn_proto.visib_mod = visib_mod;
678 fn_proto->data.fn_proto.doc_comments = *doc_comments;679 fn_proto->data.fn_proto.doc_comments = *doc_comments;
679 fn_proto->data.fn_proto.is_extern = first->id == TokenIdKeywordExtern;680 // ast_parse_fn_cc may set it
681 if (!fn_proto->data.fn_proto.is_extern)
682 fn_proto->data.fn_proto.is_extern = first->id == TokenIdKeywordExtern;
680 fn_proto->data.fn_proto.is_export = first->id == TokenIdKeywordExport;683 fn_proto->data.fn_proto.is_export = first->id == TokenIdKeywordExport;
681 switch (first->id) {684 switch (first->id) {
682 case TokenIdKeywordInline:685 case TokenIdKeywordInline:
...@@ -761,7 +764,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {...@@ -761,7 +764,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {
761 // The extern keyword for fn CC is also used for container decls.764 // The extern keyword for fn CC is also used for container decls.
762 // We therefore put it back, as allow container decl to consume it765 // We therefore put it back, as allow container decl to consume it
763 // later.766 // later.
764 if (fn_cc.cc == CallingConventionC) {767 if (fn_cc.is_extern) {
765 fn = eat_token_if(pc, TokenIdKeywordFn);768 fn = eat_token_if(pc, TokenIdKeywordFn);
766 if (fn == nullptr) {769 if (fn == nullptr) {
767 put_back_token(pc);770 put_back_token(pc);
...@@ -784,6 +787,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {...@@ -784,6 +787,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {
784787
785 AstNode *align_expr = ast_parse_byte_align(pc);788 AstNode *align_expr = ast_parse_byte_align(pc);
786 AstNode *section_expr = ast_parse_link_section(pc);789 AstNode *section_expr = ast_parse_link_section(pc);
790 AstNode *callconv_expr = ast_parse_callconv(pc);
787 Token *var = eat_token_if(pc, TokenIdKeywordVar);791 Token *var = eat_token_if(pc, TokenIdKeywordVar);
788 Token *exmark = nullptr;792 Token *exmark = nullptr;
789 AstNode *return_type = nullptr;793 AstNode *return_type = nullptr;
...@@ -798,6 +802,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {...@@ -798,6 +802,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {
798 res->data.fn_proto.params = params;802 res->data.fn_proto.params = params;
799 res->data.fn_proto.align_expr = align_expr;803 res->data.fn_proto.align_expr = align_expr;
800 res->data.fn_proto.section_expr = section_expr;804 res->data.fn_proto.section_expr = section_expr;
805 res->data.fn_proto.callconv_expr = callconv_expr;
801 res->data.fn_proto.return_var_token = var;806 res->data.fn_proto.return_var_token = var;
802 res->data.fn_proto.auto_err_set = exmark != nullptr;807 res->data.fn_proto.auto_err_set = exmark != nullptr;
803 res->data.fn_proto.return_type = return_type;808 res->data.fn_proto.return_type = return_type;
...@@ -2099,27 +2104,29 @@ static AstNode *ast_parse_link_section(ParseContext *pc) {...@@ -2099,27 +2104,29 @@ static AstNode *ast_parse_link_section(ParseContext *pc) {
2099 return res;2104 return res;
2100}2105}
21012106
2107// CallConv <- KEYWORD_callconv LPAREN Expr RPAREN
2108static AstNode *ast_parse_callconv(ParseContext *pc) {
2109 Token *first = eat_token_if(pc, TokenIdKeywordCallconv);
2110 if (first == nullptr)
2111 return nullptr;
2112
2113 expect_token(pc, TokenIdLParen);
2114 AstNode *res = ast_expect(pc, ast_parse_expr);
2115 expect_token(pc, TokenIdRParen);
2116 return res;
2117}
2118
2102// FnCC2119// FnCC
2103// <- KEYWORD_nakedcc2120// <- KEYWORD_extern
2104// / KEYWORD_stdcallcc
2105// / KEYWORD_extern
2106// / KEYWORD_async2121// / KEYWORD_async
2107static Optional<AstNodeFnProto> ast_parse_fn_cc(ParseContext *pc) {2122static Optional<AstNodeFnProto> ast_parse_fn_cc(ParseContext *pc) {
2108 AstNodeFnProto res = {};2123 AstNodeFnProto res = {};
2109 if (eat_token_if(pc, TokenIdKeywordNakedCC) != nullptr) {2124 if (eat_token_if(pc, TokenIdKeywordAsync) != nullptr) {
2110 res.cc = CallingConventionNaked;2125 res.is_async = true;
2111 return Optional<AstNodeFnProto>::some(res);
2112 }
2113 if (eat_token_if(pc, TokenIdKeywordStdcallCC) != nullptr) {
2114 res.cc = CallingConventionStdcall;
2115 return Optional<AstNodeFnProto>::some(res);2126 return Optional<AstNodeFnProto>::some(res);
2116 }2127 }
2117 if (eat_token_if(pc, TokenIdKeywordExtern) != nullptr) {2128 if (eat_token_if(pc, TokenIdKeywordExtern) != nullptr) {
2118 res.cc = CallingConventionC;2129 res.is_extern = true;
2119 return Optional<AstNodeFnProto>::some(res);
2120 }
2121 if (eat_token_if(pc, TokenIdKeywordAsync) != nullptr) {
2122 res.cc = CallingConventionAsync;
2123 return Optional<AstNodeFnProto>::some(res);2130 return Optional<AstNodeFnProto>::some(res);
2124 }2131 }
21252132
src/tokenizer.cpp+2-4
...@@ -110,6 +110,7 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -110,6 +110,7 @@ static const struct ZigKeyword zig_keywords[] = {
110 {"async", TokenIdKeywordAsync},110 {"async", TokenIdKeywordAsync},
111 {"await", TokenIdKeywordAwait},111 {"await", TokenIdKeywordAwait},
112 {"break", TokenIdKeywordBreak},112 {"break", TokenIdKeywordBreak},
113 {"callconv", TokenIdKeywordCallconv},
113 {"catch", TokenIdKeywordCatch},114 {"catch", TokenIdKeywordCatch},
114 {"comptime", TokenIdKeywordCompTime},115 {"comptime", TokenIdKeywordCompTime},
115 {"const", TokenIdKeywordConst},116 {"const", TokenIdKeywordConst},
...@@ -126,7 +127,6 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -126,7 +127,6 @@ static const struct ZigKeyword zig_keywords[] = {
126 {"for", TokenIdKeywordFor},127 {"for", TokenIdKeywordFor},
127 {"if", TokenIdKeywordIf},128 {"if", TokenIdKeywordIf},
128 {"inline", TokenIdKeywordInline},129 {"inline", TokenIdKeywordInline},
129 {"nakedcc", TokenIdKeywordNakedCC},
130 {"noalias", TokenIdKeywordNoAlias},130 {"noalias", TokenIdKeywordNoAlias},
131 {"noasync", TokenIdKeywordNoAsync},131 {"noasync", TokenIdKeywordNoAsync},
132 {"noinline", TokenIdKeywordNoInline},132 {"noinline", TokenIdKeywordNoInline},
...@@ -138,7 +138,6 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -138,7 +138,6 @@ static const struct ZigKeyword zig_keywords[] = {
138 {"resume", TokenIdKeywordResume},138 {"resume", TokenIdKeywordResume},
139 {"return", TokenIdKeywordReturn},139 {"return", TokenIdKeywordReturn},
140 {"linksection", TokenIdKeywordLinkSection},140 {"linksection", TokenIdKeywordLinkSection},
141 {"stdcallcc", TokenIdKeywordStdcallCC},
142 {"struct", TokenIdKeywordStruct},141 {"struct", TokenIdKeywordStruct},
143 {"suspend", TokenIdKeywordSuspend},142 {"suspend", TokenIdKeywordSuspend},
144 {"switch", TokenIdKeywordSwitch},143 {"switch", TokenIdKeywordSwitch},
...@@ -1545,6 +1544,7 @@ const char * token_name(TokenId id) {...@@ -1545,6 +1544,7 @@ const char * token_name(TokenId id) {
1545 case TokenIdKeywordAsm: return "asm";1544 case TokenIdKeywordAsm: return "asm";
1546 case TokenIdKeywordBreak: return "break";1545 case TokenIdKeywordBreak: return "break";
1547 case TokenIdKeywordCatch: return "catch";1546 case TokenIdKeywordCatch: return "catch";
1547 case TokenIdKeywordCallconv: return "callconv";
1548 case TokenIdKeywordCompTime: return "comptime";1548 case TokenIdKeywordCompTime: return "comptime";
1549 case TokenIdKeywordConst: return "const";1549 case TokenIdKeywordConst: return "const";
1550 case TokenIdKeywordContinue: return "continue";1550 case TokenIdKeywordContinue: return "continue";
...@@ -1560,7 +1560,6 @@ const char * token_name(TokenId id) {...@@ -1560,7 +1560,6 @@ const char * token_name(TokenId id) {
1560 case TokenIdKeywordFor: return "for";1560 case TokenIdKeywordFor: return "for";
1561 case TokenIdKeywordIf: return "if";1561 case TokenIdKeywordIf: return "if";
1562 case TokenIdKeywordInline: return "inline";1562 case TokenIdKeywordInline: return "inline";
1563 case TokenIdKeywordNakedCC: return "nakedcc";
1564 case TokenIdKeywordNoAlias: return "noalias";1563 case TokenIdKeywordNoAlias: return "noalias";
1565 case TokenIdKeywordNoAsync: return "noasync";1564 case TokenIdKeywordNoAsync: return "noasync";
1566 case TokenIdKeywordNoInline: return "noinline";1565 case TokenIdKeywordNoInline: return "noinline";
...@@ -1571,7 +1570,6 @@ const char * token_name(TokenId id) {...@@ -1571,7 +1570,6 @@ const char * token_name(TokenId id) {
1571 case TokenIdKeywordPub: return "pub";1570 case TokenIdKeywordPub: return "pub";
1572 case TokenIdKeywordReturn: return "return";1571 case TokenIdKeywordReturn: return "return";
1573 case TokenIdKeywordLinkSection: return "linksection";1572 case TokenIdKeywordLinkSection: return "linksection";
1574 case TokenIdKeywordStdcallCC: return "stdcallcc";
1575 case TokenIdKeywordStruct: return "struct";1573 case TokenIdKeywordStruct: return "struct";
1576 case TokenIdKeywordSwitch: return "switch";1574 case TokenIdKeywordSwitch: return "switch";
1577 case TokenIdKeywordTest: return "test";1575 case TokenIdKeywordTest: return "test";
src/tokenizer.hpp+1-2
...@@ -59,6 +59,7 @@ enum TokenId {...@@ -59,6 +59,7 @@ enum TokenId {
59 TokenIdKeywordAwait,59 TokenIdKeywordAwait,
60 TokenIdKeywordBreak,60 TokenIdKeywordBreak,
61 TokenIdKeywordCatch,61 TokenIdKeywordCatch,
62 TokenIdKeywordCallconv,
62 TokenIdKeywordCompTime,63 TokenIdKeywordCompTime,
63 TokenIdKeywordConst,64 TokenIdKeywordConst,
64 TokenIdKeywordContinue,65 TokenIdKeywordContinue,
...@@ -76,7 +77,6 @@ enum TokenId {...@@ -76,7 +77,6 @@ enum TokenId {
76 TokenIdKeywordInline,77 TokenIdKeywordInline,
77 TokenIdKeywordNoInline,78 TokenIdKeywordNoInline,
78 TokenIdKeywordLinkSection,79 TokenIdKeywordLinkSection,
79 TokenIdKeywordNakedCC,
80 TokenIdKeywordNoAlias,80 TokenIdKeywordNoAlias,
81 TokenIdKeywordNoAsync,81 TokenIdKeywordNoAsync,
82 TokenIdKeywordNull,82 TokenIdKeywordNull,
...@@ -86,7 +86,6 @@ enum TokenId {...@@ -86,7 +86,6 @@ enum TokenId {
86 TokenIdKeywordPub,86 TokenIdKeywordPub,
87 TokenIdKeywordResume,87 TokenIdKeywordResume,
88 TokenIdKeywordReturn,88 TokenIdKeywordReturn,
89 TokenIdKeywordStdcallCC,
90 TokenIdKeywordStruct,89 TokenIdKeywordStruct,
91 TokenIdKeywordSuspend,90 TokenIdKeywordSuspend,
92 TokenIdKeywordSwitch,91 TokenIdKeywordSwitch,
src/zig_llvm.cpp+51-2
...@@ -273,10 +273,10 @@ ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref) {...@@ -273,10 +273,10 @@ ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref) {
273}273}
274274
275LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,275LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
276 unsigned NumArgs, unsigned CC, ZigLLVM_CallAttr attr, const char *Name)276 unsigned NumArgs, ZigLLVM_CallingConv CC, ZigLLVM_CallAttr attr, const char *Name)
277{277{
278 CallInst *call_inst = CallInst::Create(unwrap(Fn), makeArrayRef(unwrap(Args), NumArgs), Name);278 CallInst *call_inst = CallInst::Create(unwrap(Fn), makeArrayRef(unwrap(Args), NumArgs), Name);
279 call_inst->setCallingConv(CC);279 call_inst->setCallingConv(static_cast<CallingConv::ID>(CC));
280 switch (attr) {280 switch (attr) {
281 case ZigLLVM_CallAttrAuto:281 case ZigLLVM_CallAttrAuto:
282 break;282 break;
...@@ -932,6 +932,9 @@ void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) {...@@ -932,6 +932,9 @@ void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) {
932 unwrap<Function>(function)->setPrefixData(unwrap<Constant>(data));932 unwrap<Function>(function)->setPrefixData(unwrap<Constant>(data));
933}933}
934934
935void ZigLLVMFunctionSetCallingConv(LLVMValueRef function, ZigLLVM_CallingConv cc) {
936 unwrap<Function>(function)->setCallingConv(static_cast<CallingConv::ID>(cc));
937}
935938
936class MyOStream: public raw_ostream {939class MyOStream: public raw_ostream {
937 public:940 public:
...@@ -1315,3 +1318,49 @@ static_assert((Triple::ObjectFormatType)ZigLLVM_ELF == Triple::ELF, "");...@@ -1315,3 +1318,49 @@ static_assert((Triple::ObjectFormatType)ZigLLVM_ELF == Triple::ELF, "");
1315static_assert((Triple::ObjectFormatType)ZigLLVM_MachO == Triple::MachO, "");1318static_assert((Triple::ObjectFormatType)ZigLLVM_MachO == Triple::MachO, "");
1316static_assert((Triple::ObjectFormatType)ZigLLVM_Wasm == Triple::Wasm, "");1319static_assert((Triple::ObjectFormatType)ZigLLVM_Wasm == Triple::Wasm, "");
1317static_assert((Triple::ObjectFormatType)ZigLLVM_XCOFF == Triple::XCOFF, "");1320static_assert((Triple::ObjectFormatType)ZigLLVM_XCOFF == Triple::XCOFF, "");
1321
1322static_assert((CallingConv::ID)ZigLLVM_C == llvm::CallingConv::C, "");
1323static_assert((CallingConv::ID)ZigLLVM_Fast == llvm::CallingConv::Fast, "");
1324static_assert((CallingConv::ID)ZigLLVM_Cold == llvm::CallingConv::Cold, "");
1325static_assert((CallingConv::ID)ZigLLVM_GHC == llvm::CallingConv::GHC, "");
1326static_assert((CallingConv::ID)ZigLLVM_HiPE == llvm::CallingConv::HiPE, "");
1327static_assert((CallingConv::ID)ZigLLVM_WebKit_JS == llvm::CallingConv::WebKit_JS, "");
1328static_assert((CallingConv::ID)ZigLLVM_AnyReg == llvm::CallingConv::AnyReg, "");
1329static_assert((CallingConv::ID)ZigLLVM_PreserveMost == llvm::CallingConv::PreserveMost, "");
1330static_assert((CallingConv::ID)ZigLLVM_PreserveAll == llvm::CallingConv::PreserveAll, "");
1331static_assert((CallingConv::ID)ZigLLVM_Swift == llvm::CallingConv::Swift, "");
1332static_assert((CallingConv::ID)ZigLLVM_CXX_FAST_TLS == llvm::CallingConv::CXX_FAST_TLS, "");
1333static_assert((CallingConv::ID)ZigLLVM_FirstTargetCC == llvm::CallingConv::FirstTargetCC, "");
1334static_assert((CallingConv::ID)ZigLLVM_X86_StdCall == llvm::CallingConv::X86_StdCall, "");
1335static_assert((CallingConv::ID)ZigLLVM_X86_FastCall == llvm::CallingConv::X86_FastCall, "");
1336static_assert((CallingConv::ID)ZigLLVM_ARM_APCS == llvm::CallingConv::ARM_APCS, "");
1337static_assert((CallingConv::ID)ZigLLVM_ARM_AAPCS == llvm::CallingConv::ARM_AAPCS, "");
1338static_assert((CallingConv::ID)ZigLLVM_ARM_AAPCS_VFP == llvm::CallingConv::ARM_AAPCS_VFP, "");
1339static_assert((CallingConv::ID)ZigLLVM_MSP430_INTR == llvm::CallingConv::MSP430_INTR, "");
1340static_assert((CallingConv::ID)ZigLLVM_X86_ThisCall == llvm::CallingConv::X86_ThisCall, "");
1341static_assert((CallingConv::ID)ZigLLVM_PTX_Kernel == llvm::CallingConv::PTX_Kernel, "");
1342static_assert((CallingConv::ID)ZigLLVM_PTX_Device == llvm::CallingConv::PTX_Device, "");
1343static_assert((CallingConv::ID)ZigLLVM_SPIR_FUNC == llvm::CallingConv::SPIR_FUNC, "");
1344static_assert((CallingConv::ID)ZigLLVM_SPIR_KERNEL == llvm::CallingConv::SPIR_KERNEL, "");
1345static_assert((CallingConv::ID)ZigLLVM_Intel_OCL_BI == llvm::CallingConv::Intel_OCL_BI, "");
1346static_assert((CallingConv::ID)ZigLLVM_X86_64_SysV == llvm::CallingConv::X86_64_SysV, "");
1347static_assert((CallingConv::ID)ZigLLVM_Win64 == llvm::CallingConv::Win64, "");
1348static_assert((CallingConv::ID)ZigLLVM_X86_VectorCall == llvm::CallingConv::X86_VectorCall, "");
1349static_assert((CallingConv::ID)ZigLLVM_HHVM == llvm::CallingConv::HHVM, "");
1350static_assert((CallingConv::ID)ZigLLVM_HHVM_C == llvm::CallingConv::HHVM_C, "");
1351static_assert((CallingConv::ID)ZigLLVM_X86_INTR == llvm::CallingConv::X86_INTR, "");
1352static_assert((CallingConv::ID)ZigLLVM_AVR_INTR == llvm::CallingConv::AVR_INTR, "");
1353static_assert((CallingConv::ID)ZigLLVM_AVR_SIGNAL == llvm::CallingConv::AVR_SIGNAL, "");
1354static_assert((CallingConv::ID)ZigLLVM_AVR_BUILTIN == llvm::CallingConv::AVR_BUILTIN, "");
1355static_assert((CallingConv::ID)ZigLLVM_AMDGPU_VS == llvm::CallingConv::AMDGPU_VS, "");
1356static_assert((CallingConv::ID)ZigLLVM_AMDGPU_GS == llvm::CallingConv::AMDGPU_GS, "");
1357static_assert((CallingConv::ID)ZigLLVM_AMDGPU_PS == llvm::CallingConv::AMDGPU_PS, "");
1358static_assert((CallingConv::ID)ZigLLVM_AMDGPU_CS == llvm::CallingConv::AMDGPU_CS, "");
1359static_assert((CallingConv::ID)ZigLLVM_AMDGPU_KERNEL == llvm::CallingConv::AMDGPU_KERNEL, "");
1360static_assert((CallingConv::ID)ZigLLVM_X86_RegCall == llvm::CallingConv::X86_RegCall, "");
1361static_assert((CallingConv::ID)ZigLLVM_AMDGPU_HS == llvm::CallingConv::AMDGPU_HS, "");
1362static_assert((CallingConv::ID)ZigLLVM_MSP430_BUILTIN == llvm::CallingConv::MSP430_BUILTIN, "");
1363static_assert((CallingConv::ID)ZigLLVM_AMDGPU_LS == llvm::CallingConv::AMDGPU_LS, "");
1364static_assert((CallingConv::ID)ZigLLVM_AMDGPU_ES == llvm::CallingConv::AMDGPU_ES, "");
1365static_assert((CallingConv::ID)ZigLLVM_AArch64_VectorCall == llvm::CallingConv::AArch64_VectorCall, "");
1366static_assert((CallingConv::ID)ZigLLVM_MaxID == llvm::CallingConv::MaxID, "");
src/zig_llvm.h+50-1
...@@ -64,6 +64,54 @@ ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, co...@@ -64,6 +64,54 @@ ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, co
6464
65ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref);65ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref);
6666
67enum ZigLLVM_CallingConv {
68 ZigLLVM_C = 0,
69 ZigLLVM_Fast = 8,
70 ZigLLVM_Cold = 9,
71 ZigLLVM_GHC = 10,
72 ZigLLVM_HiPE = 11,
73 ZigLLVM_WebKit_JS = 12,
74 ZigLLVM_AnyReg = 13,
75 ZigLLVM_PreserveMost = 14,
76 ZigLLVM_PreserveAll = 15,
77 ZigLLVM_Swift = 16,
78 ZigLLVM_CXX_FAST_TLS = 17,
79 ZigLLVM_FirstTargetCC = 64,
80 ZigLLVM_X86_StdCall = 64,
81 ZigLLVM_X86_FastCall = 65,
82 ZigLLVM_ARM_APCS = 66,
83 ZigLLVM_ARM_AAPCS = 67,
84 ZigLLVM_ARM_AAPCS_VFP = 68,
85 ZigLLVM_MSP430_INTR = 69,
86 ZigLLVM_X86_ThisCall = 70,
87 ZigLLVM_PTX_Kernel = 71,
88 ZigLLVM_PTX_Device = 72,
89 ZigLLVM_SPIR_FUNC = 75,
90 ZigLLVM_SPIR_KERNEL = 76,
91 ZigLLVM_Intel_OCL_BI = 77,
92 ZigLLVM_X86_64_SysV = 78,
93 ZigLLVM_Win64 = 79,
94 ZigLLVM_X86_VectorCall = 80,
95 ZigLLVM_HHVM = 81,
96 ZigLLVM_HHVM_C = 82,
97 ZigLLVM_X86_INTR = 83,
98 ZigLLVM_AVR_INTR = 84,
99 ZigLLVM_AVR_SIGNAL = 85,
100 ZigLLVM_AVR_BUILTIN = 86,
101 ZigLLVM_AMDGPU_VS = 87,
102 ZigLLVM_AMDGPU_GS = 88,
103 ZigLLVM_AMDGPU_PS = 89,
104 ZigLLVM_AMDGPU_CS = 90,
105 ZigLLVM_AMDGPU_KERNEL = 91,
106 ZigLLVM_X86_RegCall = 92,
107 ZigLLVM_AMDGPU_HS = 93,
108 ZigLLVM_MSP430_BUILTIN = 94,
109 ZigLLVM_AMDGPU_LS = 95,
110 ZigLLVM_AMDGPU_ES = 96,
111 ZigLLVM_AArch64_VectorCall = 97,
112 ZigLLVM_MaxID = 1023,
113};
114
67enum ZigLLVM_CallAttr {115enum ZigLLVM_CallAttr {
68 ZigLLVM_CallAttrAuto,116 ZigLLVM_CallAttrAuto,
69 ZigLLVM_CallAttrNeverTail,117 ZigLLVM_CallAttrNeverTail,
...@@ -72,7 +120,7 @@ enum ZigLLVM_CallAttr {...@@ -72,7 +120,7 @@ enum ZigLLVM_CallAttr {
72 ZigLLVM_CallAttrAlwaysInline,120 ZigLLVM_CallAttrAlwaysInline,
73};121};
74ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,122ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
75 unsigned NumArgs, unsigned CC, enum ZigLLVM_CallAttr attr, const char *Name);123 unsigned NumArgs, enum ZigLLVM_CallingConv CC, enum ZigLLVM_CallAttr attr, const char *Name);
76124
77ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst, unsigned DstAlign,125ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildMemCpy(LLVMBuilderRef B, LLVMValueRef Dst, unsigned DstAlign,
78 LLVMValueRef Src, unsigned SrcAlign, LLVMValueRef Size, bool isVolatile);126 LLVMValueRef Src, unsigned SrcAlign, LLVMValueRef Size, bool isVolatile);
...@@ -215,6 +263,7 @@ ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigne...@@ -215,6 +263,7 @@ ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigne
215ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state);263ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state);
216ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call);264ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call);
217ZIG_EXTERN_C void ZigLLVMFunctionSetPrefixData(LLVMValueRef fn, LLVMValueRef data);265ZIG_EXTERN_C void ZigLLVMFunctionSetPrefixData(LLVMValueRef fn, LLVMValueRef data);
266ZIG_EXTERN_C void ZigLLVMFunctionSetCallingConv(LLVMValueRef function, enum ZigLLVM_CallingConv cc);
218267
219ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value);268ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value);
220ZIG_EXTERN_C void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val);269ZIG_EXTERN_C void ZigLLVMAddByValAttr(LLVMValueRef fn_ref, unsigned ArgNo, LLVMTypeRef type_val);
test/compile_errors.zig+20-20
...@@ -752,7 +752,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -752,7 +752,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
752 \\ _ = @frame();752 \\ _ = @frame();
753 \\}753 \\}
754 , &[_][]const u8{754 , &[_][]const u8{
755 "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",755 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
756 "tmp.zig:5:9: note: @frame() causes function to be async",756 "tmp.zig:5:9: note: @frame() causes function to be async",
757 });757 });
758758
...@@ -765,7 +765,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -765,7 +765,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
765 \\ suspend;765 \\ suspend;
766 \\}766 \\}
767 , &[_][]const u8{767 , &[_][]const u8{
768 "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",768 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
769 "tmp.zig:3:18: note: await here is a suspend point",769 "tmp.zig:3:18: note: await here is a suspend point",
770 });770 });
771771
...@@ -843,7 +843,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -843,7 +843,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
843 \\ suspend;843 \\ suspend;
844 \\}844 \\}
845 , &[_][]const u8{845 , &[_][]const u8{
846 "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",846 "tmp.zig:1:1: error: function with calling convention 'C' cannot be async",
847 "tmp.zig:2:8: note: async function call here",847 "tmp.zig:2:8: note: async function call here",
848 "tmp.zig:5:8: note: async function call here",848 "tmp.zig:5:8: note: async function call here",
849 "tmp.zig:8:5: note: suspends here",849 "tmp.zig:8:5: note: suspends here",
...@@ -1140,7 +1140,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1140,7 +1140,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1140 \\ while (true) {}1140 \\ while (true) {}
1141 \\}1141 \\}
1142 , &[_][]const u8{1142 , &[_][]const u8{
1143 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var)var'",1143 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var) var'",
1144 "note: only one of the functions is generic",1144 "note: only one of the functions is generic",
1145 });1145 });
11461146
...@@ -1362,7 +1362,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1362,7 +1362,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1362 \\ return 0;1362 \\ return 0;
1363 \\}1363 \\}
1364 , &[_][]const u8{1364 , &[_][]const u8{
1365 "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'",1365 "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'C'",
1366 });1366 });
13671367
1368 cases.add("C pointer to c_void",1368 cases.add("C pointer to c_void",
...@@ -2187,7 +2187,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2187,7 +2187,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2187 \\ f(g);2187 \\ f(g);
2188 \\}2188 \\}
2189 , &[_][]const u8{2189 , &[_][]const u8{
2190 "tmp.zig:1:9: error: parameter of type 'fn(var)var' must be declared comptime",2190 "tmp.zig:1:9: error: parameter of type 'fn(var) var' must be declared comptime",
2191 });2191 });
21922192
2193 cases.add("optional pointer to void in extern struct",2193 cases.add("optional pointer to void in extern struct",
...@@ -2843,7 +2843,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2843,7 +2843,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2843 \\export fn entry() void {2843 \\export fn entry() void {
2844 \\ foo();2844 \\ foo();
2845 \\}2845 \\}
2846 \\nakedcc fn foo() void { }2846 \\fn foo() callconv(.Naked) void { }
2847 , &[_][]const u8{2847 , &[_][]const u8{
2848 "tmp.zig:2:5: error: unable to call function with naked calling convention",2848 "tmp.zig:2:5: error: unable to call function with naked calling convention",
2849 "tmp.zig:4:1: note: declared here",2849 "tmp.zig:4:1: note: declared here",
...@@ -2859,7 +2859,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2859,7 +2859,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2859 \\const Foo = enum { A, B, C };2859 \\const Foo = enum { A, B, C };
2860 \\export fn entry(foo: Foo) void { }2860 \\export fn entry(foo: Foo) void { }
2861 , &[_][]const u8{2861 , &[_][]const u8{
2862 "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",2862 "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
2863 });2863 });
28642864
2865 cases.add("function with non-extern non-packed struct parameter",2865 cases.add("function with non-extern non-packed struct parameter",
...@@ -2870,7 +2870,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2870,7 +2870,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2870 \\};2870 \\};
2871 \\export fn entry(foo: Foo) void { }2871 \\export fn entry(foo: Foo) void { }
2872 , &[_][]const u8{2872 , &[_][]const u8{
2873 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",2873 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
2874 });2874 });
28752875
2876 cases.add("function with non-extern non-packed union parameter",2876 cases.add("function with non-extern non-packed union parameter",
...@@ -2881,7 +2881,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2881,7 +2881,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2881 \\};2881 \\};
2882 \\export fn entry(foo: Foo) void { }2882 \\export fn entry(foo: Foo) void { }
2883 , &[_][]const u8{2883 , &[_][]const u8{
2884 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",2884 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'",
2885 });2885 });
28862886
2887 cases.add("switch on enum with 1 field with no prongs",2887 cases.add("switch on enum with 1 field with no prongs",
...@@ -2972,13 +2972,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2972,13 +2972,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2972 \\ foo(bar);2972 \\ foo(bar);
2973 \\}2973 \\}
2974 \\2974 \\
2975 \\extern fn bar(x: *void) void { }2975 \\fn bar(x: *void) callconv(.C) void { }
2976 \\export fn entry2() void {2976 \\export fn entry2() void {
2977 \\ bar(&{});2977 \\ bar(&{});
2978 \\}2978 \\}
2979 , &[_][]const u8{2979 , &[_][]const u8{
2980 "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",2980 "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'",
2981 "tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",2981 "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'",
2982 });2982 });
29832983
2984 cases.add("implicit semicolon - block statement",2984 cases.add("implicit semicolon - block statement",
...@@ -3871,7 +3871,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3871,7 +3871,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3871 \\3871 \\
3872 \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }3872 \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
3873 , &[_][]const u8{3873 , &[_][]const u8{
3874 "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",3874 "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'",
3875 });3875 });
38763876
3877 cases.add("colliding invalid top level functions",3877 cases.add("colliding invalid top level functions",
...@@ -4552,7 +4552,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4552,7 +4552,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4552 \\ return x + y;4552 \\ return x + y;
4553 \\}4553 \\}
4554 , &[_][]const u8{4554 , &[_][]const u8{
4555 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",4555 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'",
4556 });4556 });
45574557
4558 cases.add("extern function with comptime parameter",4558 cases.add("extern function with comptime parameter",
...@@ -4562,7 +4562,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4562,7 +4562,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4562 \\}4562 \\}
4563 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }4563 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
4564 , &[_][]const u8{4564 , &[_][]const u8{
4565 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",4565 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'",
4566 });4566 });
45674567
4568 cases.add("convert fixed size array to slice with invalid size",4568 cases.add("convert fixed size array to slice with invalid size",
...@@ -5618,7 +5618,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5618,7 +5618,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5618 });5618 });
56195619
5620 cases.add("wrong types given to @export",5620 cases.add("wrong types given to @export",
5621 \\extern fn entry() void { }5621 \\fn entry() callconv(.C) void { }
5622 \\comptime {5622 \\comptime {
5623 \\ @export("entry", entry, @as(u32, 1234));5623 \\ @export("entry", entry, @as(u32, 1234));
5624 \\}5624 \\}
...@@ -5663,7 +5663,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5663,7 +5663,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5663 });5663 });
56645664
5665 cases.add("@setAlignStack in naked function",5665 cases.add("@setAlignStack in naked function",
5666 \\export nakedcc fn entry() void {5666 \\export fn entry() callconv(.Naked) void {
5667 \\ @setAlignStack(16);5667 \\ @setAlignStack(16);
5668 \\}5668 \\}
5669 , &[_][]const u8{5669 , &[_][]const u8{
...@@ -6303,7 +6303,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6303,7 +6303,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6303 \\ _ = @TypeOf(generic).ReturnType;6303 \\ _ = @TypeOf(generic).ReturnType;
6304 \\}6304 \\}
6305 , &[_][]const u8{6305 , &[_][]const u8{
6306 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic",6306 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var) var' is generic",
6307 });6307 });
63086308
6309 cases.add("getting @ArgType of generic function",6309 cases.add("getting @ArgType of generic function",
...@@ -6312,7 +6312,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6312,7 +6312,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6312 \\ _ = @ArgType(@TypeOf(generic), 0);6312 \\ _ = @ArgType(@TypeOf(generic), 0);
6313 \\}6313 \\}
6314 , &[_][]const u8{6314 , &[_][]const u8{
6315 "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic",6315 "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var) var' is generic",
6316 });6316 });
63176317
6318 cases.add("unsupported modifier at start of asm output constraint",6318 cases.add("unsupported modifier at start of asm output constraint",
test/src/translate_c.zig+14
...@@ -19,6 +19,7 @@ pub const TranslateCContext = struct {...@@ -19,6 +19,7 @@ pub const TranslateCContext = struct {
19 sources: ArrayList(SourceFile),19 sources: ArrayList(SourceFile),
20 expected_lines: ArrayList([]const u8),20 expected_lines: ArrayList([]const u8),
21 allow_warnings: bool,21 allow_warnings: bool,
22 target: std.Target = .Native,
2223
23 const SourceFile = struct {24 const SourceFile = struct {
24 filename: []const u8,25 filename: []const u8,
...@@ -71,6 +72,18 @@ pub const TranslateCContext = struct {...@@ -71,6 +72,18 @@ pub const TranslateCContext = struct {
71 self.addCase(tc);72 self.addCase(tc);
72 }73 }
7374
75 pub fn addWithTarget(
76 self: *TranslateCContext,
77 name: []const u8,
78 target: std.Target,
79 source: []const u8,
80 expected_lines: []const []const u8,
81 ) void {
82 const tc = self.create(false, "source.h", name, source, expected_lines);
83 tc.target = target;
84 self.addCase(tc);
85 }
86
74 pub fn addAllowWarnings(87 pub fn addAllowWarnings(
75 self: *TranslateCContext,88 self: *TranslateCContext,
76 name: []const u8,89 name: []const u8,
...@@ -101,6 +114,7 @@ pub const TranslateCContext = struct {...@@ -101,6 +114,7 @@ pub const TranslateCContext = struct {
101 .basename = case.sources.toSliceConst()[0].filename,114 .basename = case.sources.toSliceConst()[0].filename,
102 },115 },
103 });116 });
117 translate_c.setTarget(case.target);
104118
105 const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst());119 const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst());
106120
test/stage1/behavior/align.zig+3-3
...@@ -221,14 +221,14 @@ test "alignment of structs" {...@@ -221,14 +221,14 @@ test "alignment of structs" {
221 }) == @alignOf(usize));221 }) == @alignOf(usize));
222}222}
223223
224test "alignment of extern() void" {224test "alignment of function with c calling convention" {
225 var runtime_nothing = nothing;225 var runtime_nothing = nothing;
226 const casted1 = @ptrCast(*const u8, runtime_nothing);226 const casted1 = @ptrCast(*const u8, runtime_nothing);
227 const casted2 = @ptrCast(extern fn () void, casted1);227 const casted2 = @ptrCast(fn () callconv(.C) void, casted1);
228 casted2();228 casted2();
229}229}
230230
231extern fn nothing() void {}231fn nothing() callconv(.C) void {}
232232
233test "return error union with 128-bit integer" {233test "return error union with 128-bit integer" {
234 expect(3 == try give());234 expect(3 == try give());
test/stage1/behavior/bugs/1310.zig+2-2
...@@ -3,7 +3,7 @@ const expect = std.testing.expect;...@@ -3,7 +3,7 @@ const expect = std.testing.expect;
33
4pub const VM = ?[*]const struct_InvocationTable_;4pub const VM = ?[*]const struct_InvocationTable_;
5pub const struct_InvocationTable_ = extern struct {5pub const struct_InvocationTable_ = extern struct {
6 GetVM: ?extern fn (?[*]VM) c_int,6 GetVM: ?fn (?[*]VM) callconv(.C) c_int,
7};7};
88
9pub const struct_VM_ = extern struct {9pub const struct_VM_ = extern struct {
...@@ -15,7 +15,7 @@ pub const struct_VM_ = extern struct {...@@ -15,7 +15,7 @@ pub const struct_VM_ = extern struct {
15pub const InvocationTable_ = struct_InvocationTable_;15pub const InvocationTable_ = struct_InvocationTable_;
16pub const VM_ = struct_VM_;16pub const VM_ = struct_VM_;
1717
18extern fn agent_callback(_vm: [*]VM, options: [*]u8) i32 {18fn agent_callback(_vm: [*]VM, options: [*]u8) callconv(.C) i32 {
19 return 11;19 return 11;
20}20}
2121
test/stage1/behavior/cast.zig+2-2
...@@ -477,7 +477,7 @@ test "compile time int to ptr of function" {...@@ -477,7 +477,7 @@ test "compile time int to ptr of function" {
477}477}
478478
479pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));479pub const FUNCTION_CONSTANT = @intToPtr(PFN_void, maxInt(usize));
480pub const PFN_void = extern fn (*c_void) void;480pub const PFN_void = fn (*c_void) callconv(.C) void;
481481
482fn foobar(func: PFN_void) void {482fn foobar(func: PFN_void) void {
483 std.testing.expect(@ptrToInt(func) == maxInt(usize));483 std.testing.expect(@ptrToInt(func) == maxInt(usize));
...@@ -587,7 +587,7 @@ test "peer cast *[0]T to []const T" {...@@ -587,7 +587,7 @@ test "peer cast *[0]T to []const T" {
587587
588var global_array: [4]u8 = undefined;588var global_array: [4]u8 = undefined;
589test "cast from array reference to fn" {589test "cast from array reference to fn" {
590 const f = @ptrCast(extern fn () void, &global_array);590 const f = @ptrCast(fn () callconv(.C) void, &global_array);
591 expect(@ptrToInt(f) == @ptrToInt(&global_array));591 expect(@ptrToInt(f) == @ptrToInt(&global_array));
592}592}
593593
test/stage1/behavior/fn.zig+2-2
...@@ -186,9 +186,9 @@ test "return inner function which references comptime variable of outer function...@@ -186,9 +186,9 @@ test "return inner function which references comptime variable of outer function
186186
187test "extern struct with stdcallcc fn pointer" {187test "extern struct with stdcallcc fn pointer" {
188 const S = extern struct {188 const S = extern struct {
189 ptr: stdcallcc fn () i32,189 ptr: fn () callconv(.Stdcall) i32,
190190
191 stdcallcc fn foo() i32 {191 fn foo() callconv(.Stdcall) i32 {
192 return 1234;192 return 1234;
193 }193 }
194 };194 };
test/stage1/behavior/misc.zig+1-1
...@@ -19,7 +19,7 @@ comptime {...@@ -19,7 +19,7 @@ comptime {
19 @export("disabledExternFn", disabledExternFn, builtin.GlobalLinkage.Internal);19 @export("disabledExternFn", disabledExternFn, builtin.GlobalLinkage.Internal);
20}20}
2121
22extern fn disabledExternFn() void {}22fn disabledExternFn() callconv(.C) void {}
2323
24test "call disabled extern fn" {24test "call disabled extern fn" {
25 disabledExternFn();25 disabledExternFn();
test/stage1/behavior/struct.zig+2-2
...@@ -580,7 +580,7 @@ test "default struct initialization fields" {...@@ -580,7 +580,7 @@ test "default struct initialization fields" {
580 expectEqual(1239, x.a + x.b);580 expectEqual(1239, x.a + x.b);
581}581}
582582
583test "extern fn returns struct by value" {583test "fn with C calling convention returns struct by value" {
584 const S = struct {584 const S = struct {
585 fn entry() void {585 fn entry() void {
586 var x = makeBar(10);586 var x = makeBar(10);
...@@ -591,7 +591,7 @@ test "extern fn returns struct by value" {...@@ -591,7 +591,7 @@ test "extern fn returns struct by value" {
591 handle: i32,591 handle: i32,
592 };592 };
593593
594 extern fn makeBar(t: i32) ExternBar {594 fn makeBar(t: i32) callconv(.C) ExternBar {
595 return ExternBar{595 return ExternBar{
596 .handle = t,596 .handle = t,
597 };597 };
test/stage1/behavior/type_info.zig+2-2
...@@ -202,7 +202,7 @@ fn testUnion() void {...@@ -202,7 +202,7 @@ fn testUnion() void {
202 expect(typeinfo_info.Union.fields[4].enum_field != null);202 expect(typeinfo_info.Union.fields[4].enum_field != null);
203 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);203 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
204 expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));204 expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));
205 expect(typeinfo_info.Union.decls.len == 21);205 expect(typeinfo_info.Union.decls.len == 20);
206206
207 const TestNoTagUnion = union {207 const TestNoTagUnion = union {
208 Foo: void,208 Foo: void,
...@@ -266,7 +266,7 @@ test "type info: function type info" {...@@ -266,7 +266,7 @@ test "type info: function type info" {
266fn testFunction() void {266fn testFunction() void {
267 const fn_info = @typeInfo(@TypeOf(foo));267 const fn_info = @typeInfo(@TypeOf(foo));
268 expect(@as(TypeId, fn_info) == TypeId.Fn);268 expect(@as(TypeId, fn_info) == TypeId.Fn);
269 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);269 expect(fn_info.Fn.calling_convention == .Unspecified);
270 expect(fn_info.Fn.is_generic);270 expect(fn_info.Fn.is_generic);
271 expect(fn_info.Fn.args.len == 2);271 expect(fn_info.Fn.args.len == 2);
272 expect(fn_info.Fn.is_var_args);272 expect(fn_info.Fn.is_var_args);
test/standalone/load_dynamic_library/main.zig+1-1
...@@ -9,7 +9,7 @@ pub fn main() !void {...@@ -9,7 +9,7 @@ pub fn main() !void {
9 var lib = try std.DynLib.open(dynlib_name);9 var lib = try std.DynLib.open(dynlib_name);
10 defer lib.close();10 defer lib.close();
1111
12 const addFn = lib.lookup(extern fn (i32, i32) i32, "add") orelse return error.SymbolNotFound;12 const addFn = lib.lookup(fn (i32, i32) callconv(.C) i32, "add") orelse return error.SymbolNotFound;
1313
14 const result = addFn(12, 34);14 const result = addFn(12, 34);
15 std.debug.assert(result == 46);15 std.debug.assert(result == 46);
test/translate_c.zig+55-21
...@@ -205,7 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -205,7 +205,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
205 \\static void bar(void) {}205 \\static void bar(void) {}
206 , &[_][]const u8{206 , &[_][]const u8{
207 \\pub export fn foo() void {}207 \\pub export fn foo() void {}
208 \\pub fn bar() void {}208 \\pub fn bar() callconv(.C) void {}
209 });209 });
210210
211 cases.add("typedef void",211 cases.add("typedef void",
...@@ -238,7 +238,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -238,7 +238,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
238 \\pub extern fn foo() void;238 \\pub extern fn foo() void;
239 \\pub export fn bar() void {239 \\pub export fn bar() void {
240 \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);240 \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);
241 \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @intCast(c_ulong, @ptrToInt(func_ptr)));241 \\ var typed_func_ptr: ?fn () callconv(.C) void = @intToPtr(?fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));
242 \\}242 \\}
243 });243 });
244244
...@@ -295,9 +295,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -295,9 +295,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
295 \\ lws_callback_function *callback_http;295 \\ lws_callback_function *callback_http;
296 \\};296 \\};
297 , &[_][]const u8{297 , &[_][]const u8{
298 \\pub const lws_callback_function = extern fn () void;298 \\pub const lws_callback_function = fn () callconv(.C) void;
299 \\pub const struct_Foo = extern struct {299 \\pub const struct_Foo = extern struct {
300 \\ func: ?extern fn () void,300 \\ func: ?fn () callconv(.C) void,
301 \\ callback_http: ?lws_callback_function,301 \\ callback_http: ?lws_callback_function,
302 \\};302 \\};
303 });303 });
...@@ -377,7 +377,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -377,7 +377,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
377 \\};377 \\};
378 , &[_][]const u8{378 , &[_][]const u8{
379 \\pub const struct_Foo = extern struct {379 \\pub const struct_Foo = extern struct {
380 \\ derp: ?extern fn ([*c]struct_Foo) void,380 \\ derp: ?fn ([*c]struct_Foo) callconv(.C) void,
381 \\};381 \\};
382 ,382 ,
383 \\pub const Foo = struct_Foo;383 \\pub const Foo = struct_Foo;
...@@ -611,7 +611,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -611,7 +611,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
611 cases.add("__cdecl doesn't mess up function pointers",611 cases.add("__cdecl doesn't mess up function pointers",
612 \\void foo(void (__cdecl *fn_ptr)(void));612 \\void foo(void (__cdecl *fn_ptr)(void));
613 , &[_][]const u8{613 , &[_][]const u8{
614 \\pub extern fn foo(fn_ptr: ?extern fn () void) void;614 \\pub extern fn foo(fn_ptr: ?fn () callconv(.C) void) void;
615 });615 });
616616
617 cases.add("void cast",617 cases.add("void cast",
...@@ -953,8 +953,42 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -953,8 +953,42 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
953 \\typedef void (*fn0)();953 \\typedef void (*fn0)();
954 \\typedef void (*fn1)(char);954 \\typedef void (*fn1)(char);
955 , &[_][]const u8{955 , &[_][]const u8{
956 \\pub const fn0 = ?extern fn (...) void;956 \\pub const fn0 = ?fn (...) callconv(.C) void;
957 \\pub const fn1 = ?extern fn (u8) void;957 \\pub const fn1 = ?fn (u8) callconv(.C) void;
958 });
959
960 cases.addWithTarget("Calling convention", tests.Target{
961 .Cross = .{ .os = .linux, .arch = .i386, .abi = .none },
962 },
963 \\void __attribute__((fastcall)) foo1(float *a);
964 \\void __attribute__((stdcall)) foo2(float *a);
965 \\void __attribute__((vectorcall)) foo3(float *a);
966 \\void __attribute__((cdecl)) foo4(float *a);
967 \\void __attribute__((thiscall)) foo5(float *a);
968 , &[_][]const u8{
969 \\pub fn foo1(a: [*c]f32) callconv(.Fastcall) void;
970 \\pub fn foo2(a: [*c]f32) callconv(.Stdcall) void;
971 \\pub fn foo3(a: [*c]f32) callconv(.Vectorcall) void;
972 \\pub extern fn foo4(a: [*c]f32) void;
973 \\pub fn foo5(a: [*c]f32) callconv(.Thiscall) void;
974 });
975
976 cases.addWithTarget("Calling convention", tests.Target{
977 .Cross = .{ .os = .linux, .arch = .{ .arm = .v8_5a }, .abi = .none },
978 },
979 \\void __attribute__((pcs("aapcs"))) foo1(float *a);
980 \\void __attribute__((pcs("aapcs-vfp"))) foo2(float *a);
981 , &[_][]const u8{
982 \\pub fn foo1(a: [*c]f32) callconv(.AAPCS) void;
983 \\pub fn foo2(a: [*c]f32) callconv(.AAPCSVFP) void;
984 });
985
986 cases.addWithTarget("Calling convention", tests.Target{
987 .Cross = .{ .os = .linux, .arch = .{ .aarch64 = .v8_5a }, .abi = .none },
988 },
989 \\void __attribute__((aarch64_vector_pcs)) foo1(float *a);
990 , &[_][]const u8{
991 \\pub fn foo1(a: [*c]f32) callconv(.Vectorcall) void;
958 });992 });
959993
960 cases.add("Parameterless function prototypes",994 cases.add("Parameterless function prototypes",
...@@ -985,7 +1019,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -985,7 +1019,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
985 \\ char *arr1[10] ={0};1019 \\ char *arr1[10] ={0};
986 \\}1020 \\}
987 , &[_][]const u8{1021 , &[_][]const u8{
988 \\pub fn foo() void {1022 \\pub fn foo() callconv(.C) void {
989 \\ var arr: [10]u8 = .{1023 \\ var arr: [10]u8 = .{
990 \\ @bitCast(u8, @truncate(i8, @as(c_int, 1))),1024 \\ @bitCast(u8, @truncate(i8, @as(c_int, 1))),
991 \\ } ++ .{0} ** 9;1025 \\ } ++ .{0} ** 9;
...@@ -1123,13 +1157,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1123,13 +1157,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1123 \\extern char (*fn_ptr2)(int, float);1157 \\extern char (*fn_ptr2)(int, float);
1124 \\#define bar fn_ptr21158 \\#define bar fn_ptr2
1125 , &[_][]const u8{1159 , &[_][]const u8{
1126 \\pub extern var fn_ptr: ?extern fn () void;1160 \\pub extern var fn_ptr: ?fn () callconv(.C) void;
1127 ,1161 ,
1128 \\pub inline fn foo() void {1162 \\pub inline fn foo() void {
1129 \\ return fn_ptr.?();1163 \\ return fn_ptr.?();
1130 \\}1164 \\}
1131 ,1165 ,
1132 \\pub extern var fn_ptr2: ?extern fn (c_int, f32) u8;1166 \\pub extern var fn_ptr2: ?fn (c_int, f32) callconv(.C) u8;
1133 ,1167 ,
1134 \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {1168 \\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {
1135 \\ return fn_ptr2.?(arg_1, arg_2);1169 \\ return fn_ptr2.?(arg_1, arg_2);
...@@ -1151,8 +1185,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1151,8 +1185,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1151 \\#define glClearPFN PFNGLCLEARPROC1185 \\#define glClearPFN PFNGLCLEARPROC
1152 , &[_][]const u8{1186 , &[_][]const u8{
1153 \\pub const GLbitfield = c_uint;1187 \\pub const GLbitfield = c_uint;
1154 \\pub const PFNGLCLEARPROC = ?extern fn (GLbitfield) void;1188 \\pub const PFNGLCLEARPROC = ?fn (GLbitfield) callconv(.C) void;
1155 \\pub const OpenGLProc = ?extern fn () void;1189 \\pub const OpenGLProc = ?fn () callconv(.C) void;
1156 \\const struct_unnamed_1 = extern struct {1190 \\const struct_unnamed_1 = extern struct {
1157 \\ Clear: PFNGLCLEARPROC,1191 \\ Clear: PFNGLCLEARPROC,
1158 \\};1192 \\};
...@@ -1942,8 +1976,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1942,8 +1976,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1942 \\ return 0;1976 \\ return 0;
1943 \\}1977 \\}
1944 \\pub export fn bar() void {1978 \\pub export fn bar() void {
1945 \\ var f: ?extern fn () void = foo;1979 \\ var f: ?fn () callconv(.C) void = foo;
1946 \\ var b: ?extern fn () c_int = baz;1980 \\ var b: ?fn () callconv(.C) c_int = baz;
1947 \\ f.?();1981 \\ f.?();
1948 \\ (f).?();1982 \\ (f).?();
1949 \\ foo();1983 \\ foo();
...@@ -2262,8 +2296,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2262,8 +2296,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2262 \\ baz();2296 \\ baz();
2263 \\}2297 \\}
2264 , &[_][]const u8{2298 , &[_][]const u8{
2265 \\pub fn bar() void {}2299 \\pub fn bar() callconv(.C) void {}
2266 \\pub export fn foo(arg_baz: ?extern fn () [*c]c_int) void {2300 \\pub export fn foo(arg_baz: ?fn () callconv(.C) [*c]c_int) void {
2267 \\ var baz = arg_baz;2301 \\ var baz = arg_baz;
2268 \\ bar();2302 \\ bar();
2269 \\ _ = baz.?();2303 \\ _ = baz.?();
...@@ -2321,7 +2355,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2321,7 +2355,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2321 \\ do {} while (0);2355 \\ do {} while (0);
2322 \\}2356 \\}
2323 , &[_][]const u8{2357 , &[_][]const u8{
2324 \\pub fn foo() void {2358 \\pub fn foo() callconv(.C) void {
2325 \\ if (@as(c_int, 1) != 0) while (true) {2359 \\ if (@as(c_int, 1) != 0) while (true) {
2326 \\ if (!(@as(c_int, 0) != 0)) break;2360 \\ if (!(@as(c_int, 0) != 0)) break;
2327 \\ };2361 \\ };
...@@ -2413,9 +2447,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2413,9 +2447,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2413 \\void c(void) {}2447 \\void c(void) {}
2414 \\static void foo() {}2448 \\static void foo() {}
2415 , &[_][]const u8{2449 , &[_][]const u8{
2416 \\pub fn a() void {}2450 \\pub fn a() callconv(.C) void {}
2417 \\pub fn b() void {}2451 \\pub fn b() callconv(.C) void {}
2418 \\pub export fn c() void {}2452 \\pub export fn c() void {}
2419 \\pub fn foo() void {}2453 \\pub fn foo() callconv(.C) void {}
2420 });2454 });
2421}2455}