Pick up WinMain with proper CC

This commit is contained in:
LemonBoy 2019-11-20 11:46:04 +01:00 committed by Andrew Kelley
parent 0d48b60794
commit fd7c7be33c
4 changed files with 31 additions and 18 deletions

View file

@ -3333,21 +3333,15 @@ void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLink
global_export->linkage = linkage; global_export->linkage = linkage;
} }
void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc) { void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, CallingConvention cc) {
if (ccc) { if (cc == CallingConventionC && strcmp(symbol_name, "main") == 0 && g->libc_link_lib != nullptr) {
if (strcmp(symbol_name, "main") == 0 && g->libc_link_lib != nullptr) { g->have_c_main = true;
g->have_c_main = true; } else if (cc == CallingConventionStdcall && g->zig_target->os == OsWindows) {
} else if (strcmp(symbol_name, "WinMain") == 0 && if (strcmp(symbol_name, "WinMain") == 0) {
g->zig_target->os == OsWindows)
{
g->have_winmain = true; g->have_winmain = true;
} else if (strcmp(symbol_name, "WinMainCRTStartup") == 0 && } else if (strcmp(symbol_name, "WinMainCRTStartup") == 0) {
g->zig_target->os == OsWindows)
{
g->have_winmain_crt_startup = true; g->have_winmain_crt_startup = true;
} else if (strcmp(symbol_name, "DllMainCRTStartup") == 0 && } else if (strcmp(symbol_name, "DllMainCRTStartup") == 0) {
g->zig_target->os == OsWindows)
{
g->have_dllmain_crt_startup = true; g->have_dllmain_crt_startup = true;
} }
} }
@ -3377,8 +3371,24 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
} }
if (fn_proto->is_export) { if (fn_proto->is_export) {
bool ccc = (fn_proto->cc == CallingConventionUnspecified || fn_proto->cc == CallingConventionC); switch (fn_proto->cc) {
add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name), GlobalLinkageIdStrong, ccc); case CallingConventionAsync: {
add_node_error(g, fn_def_node,
buf_sprintf("exported function cannot be async"));
} break;
case CallingConventionC:
case CallingConventionNaked:
case CallingConventionCold:
case CallingConventionStdcall:
case CallingConventionUnspecified:
// An exported function without a specific calling
// convention defaults to C
CallingConvention cc = (fn_proto->cc != CallingConventionUnspecified) ?
fn_proto->cc : CallingConventionC;
add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name),
GlobalLinkageIdStrong, cc);
break;
}
} }
if (!is_extern) { if (!is_extern) {

View file

@ -202,7 +202,7 @@ ZigType *get_align_amt_type(CodeGen *g);
ZigPackage *new_anonymous_package(void); ZigPackage *new_anonymous_package(void);
Buf *const_value_to_buffer(ZigValue *const_val); Buf *const_value_to_buffer(ZigValue *const_val);
void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc); void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, CallingConvention cc);
void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage); void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage);

View file

@ -16134,8 +16134,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
case CallingConventionNaked: case CallingConventionNaked:
case CallingConventionCold: case CallingConventionCold:
case CallingConventionStdcall: case CallingConventionStdcall:
add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id, add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id, cc);
cc == CallingConventionC);
break; break;
} }
} break; } break;

View file

@ -2,6 +2,10 @@ const tests = @import("tests.zig");
const builtin = @import("builtin"); const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void { pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
\\export async fn foo() void {}
, "tmp.zig:1:1: error: exported function cannot be async");
cases.addCase(x: { cases.addCase(x: {
var tc = cases.create("@newStackCall on unsupported target", var tc = cases.create("@newStackCall on unsupported target",
\\export fn entry() void { \\export fn entry() void {