authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-11-20 11:46:04+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-03 12:49:08-05:00
logfd7c7be33c95fd1bd77010378b407fc9fb4933e2
tree6bd90fa20bfe8176dec84c9e43df85a11a254a9a
parent0d48b60794f5a8deff61afb79fbac10621083538

Pick up WinMain with proper CC


4 files changed, 31 insertions(+), 18 deletions(-)

src/analyze.cpp+25-15
...@@ -3333,21 +3333,15 @@ void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLink...@@ -3333,21 +3333,15 @@ void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLink
3333 global_export->linkage = linkage;3333 global_export->linkage = linkage;
3334}3334}
33353335
3336void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc) {3336void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, CallingConvention cc) {
3337 if (ccc) {3337 if (cc == CallingConventionC && strcmp(symbol_name, "main") == 0 && g->libc_link_lib != nullptr) {
3338 if (strcmp(symbol_name, "main") == 0 && g->libc_link_lib != nullptr) {3338 g->have_c_main = true;
3339 g->have_c_main = true;3339 } else if (cc == CallingConventionStdcall && g->zig_target->os == OsWindows) {
3340 } else if (strcmp(symbol_name, "WinMain") == 0 &&3340 if (strcmp(symbol_name, "WinMain") == 0) {
3341 g->zig_target->os == OsWindows)
3342 {
3343 g->have_winmain = true;3341 g->have_winmain = true;
3344 } else if (strcmp(symbol_name, "WinMainCRTStartup") == 0 &&3342 } else if (strcmp(symbol_name, "WinMainCRTStartup") == 0) {
3345 g->zig_target->os == OsWindows)
3346 {
3347 g->have_winmain_crt_startup = true;3343 g->have_winmain_crt_startup = true;
3348 } else if (strcmp(symbol_name, "DllMainCRTStartup") == 0 &&3344 } else if (strcmp(symbol_name, "DllMainCRTStartup") == 0) {
3349 g->zig_target->os == OsWindows)
3350 {
3351 g->have_dllmain_crt_startup = true;3345 g->have_dllmain_crt_startup = true;
3352 }3346 }
3353 }3347 }
...@@ -3377,8 +3371,24 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3377,8 +3371,24 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3377 }3371 }
33783372
3379 if (fn_proto->is_export) {3373 if (fn_proto->is_export) {
3380 bool ccc = (fn_proto->cc == CallingConventionUnspecified || fn_proto->cc == CallingConventionC);3374 switch (fn_proto->cc) {
3381 add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name), GlobalLinkageIdStrong, ccc);3375 case CallingConventionAsync: {
3376 add_node_error(g, fn_def_node,
3377 buf_sprintf("exported function cannot be async"));
3378 } break;
3379 case CallingConventionC:
3380 case CallingConventionNaked:
3381 case CallingConventionCold:
3382 case CallingConventionStdcall:
3383 case CallingConventionUnspecified:
3384 // An exported function without a specific calling
3385 // convention defaults to C
3386 CallingConvention cc = (fn_proto->cc != CallingConventionUnspecified) ?
3387 fn_proto->cc : CallingConventionC;
3388 add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name),
3389 GlobalLinkageIdStrong, cc);
3390 break;
3391 }
3382 }3392 }
33833393
3384 if (!is_extern) {3394 if (!is_extern) {
src/analyze.hpp+1-1
...@@ -202,7 +202,7 @@ ZigType *get_align_amt_type(CodeGen *g);...@@ -202,7 +202,7 @@ ZigType *get_align_amt_type(CodeGen *g);
202ZigPackage *new_anonymous_package(void);202ZigPackage *new_anonymous_package(void);
203203
204Buf *const_value_to_buffer(ZigValue *const_val);204Buf *const_value_to_buffer(ZigValue *const_val);
205void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc);205void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, CallingConvention cc);
206void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage);206void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage);
207207
208208
src/ir.cpp+1-2
...@@ -16134,8 +16134,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16134,8 +16134,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16134 case CallingConventionNaked:16134 case CallingConventionNaked:
16135 case CallingConventionCold:16135 case CallingConventionCold:
16136 case CallingConventionStdcall:16136 case CallingConventionStdcall:
16137 add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id,16137 add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id, cc);
16138 cc == CallingConventionC);
16139 break;16138 break;
16140 }16139 }
16141 } break;16140 } break;
test/compile_errors.zig+4
...@@ -2,6 +2,10 @@ const tests = @import("tests.zig");...@@ -2,6 +2,10 @@ const tests = @import("tests.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub fn addCases(cases: *tests.CompileErrorContext) void {4pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 \\export async fn foo() void {}
7 , "tmp.zig:1:1: error: exported function cannot be async");
8
5 cases.addCase(x: {9 cases.addCase(x: {
6 var tc = cases.create("@newStackCall on unsupported target",10 var tc = cases.create("@newStackCall on unsupported target",
7 \\export fn entry() void {11 \\export fn entry() void {