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
33333333 global_export->linkage = linkage;
33343334}
33353335
3336void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc) {
3337 if (ccc) {
3338 if (strcmp(symbol_name, "main") == 0 && g->libc_link_lib != nullptr) {
3339 g->have_c_main = true;
3340 } else if (strcmp(symbol_name, "WinMain") == 0 &&
3341 g->zig_target->os == OsWindows)
3342 {
3336void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, CallingConvention cc) {
3337 if (cc == CallingConventionC && strcmp(symbol_name, "main") == 0 && g->libc_link_lib != nullptr) {
3338 g->have_c_main = true;
3339 } else if (cc == CallingConventionStdcall && g->zig_target->os == OsWindows) {
3340 if (strcmp(symbol_name, "WinMain") == 0) {
33433341 g->have_winmain = true;
3344 } else if (strcmp(symbol_name, "WinMainCRTStartup") == 0 &&
3345 g->zig_target->os == OsWindows)
3346 {
3342 } else if (strcmp(symbol_name, "WinMainCRTStartup") == 0) {
33473343 g->have_winmain_crt_startup = true;
3348 } else if (strcmp(symbol_name, "DllMainCRTStartup") == 0 &&
3349 g->zig_target->os == OsWindows)
3350 {
3344 } else if (strcmp(symbol_name, "DllMainCRTStartup") == 0) {
33513345 g->have_dllmain_crt_startup = true;
33523346 }
33533347 }
......@@ -3377,8 +3371,24 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
33773371 }
33783372
33793373 if (fn_proto->is_export) {
3380 bool ccc = (fn_proto->cc == CallingConventionUnspecified || fn_proto->cc == CallingConventionC);
3381 add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name), GlobalLinkageIdStrong, ccc);
3374 switch (fn_proto->cc) {
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 }
33823392 }
33833393
33843394 if (!is_extern) {
src/analyze.hpp+1-1
......@@ -202,7 +202,7 @@ ZigType *get_align_amt_type(CodeGen *g);
202202ZigPackage *new_anonymous_package(void);
203203
204204Buf *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);
206206void 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
1613416134 case CallingConventionNaked:
1613516135 case CallingConventionCold:
1613616136 case CallingConventionStdcall:
16137 add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id,
16138 cc == CallingConventionC);
16137 add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id, cc);
1613916138 break;
1614016139 }
1614116140 } break;
test/compile_errors.zig+4
......@@ -2,6 +2,10 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub 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
59 cases.addCase(x: {
610 var tc = cases.create("@newStackCall on unsupported target",
711 \\export fn entry() void {