Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed compiler segmentation fault when given an invalid target triple. #1406

Merged
merged 1 commit into from
Nov 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/libponyc/codegen/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ static void init_runtime(compile_t* c)
c->personality = LLVMAddFunction(c->module, "pony_personality_v0", type);
}

static void init_module(compile_t* c, ast_t* program, pass_opt_t* opt)
static bool init_module(compile_t* c, ast_t* program, pass_opt_t* opt)
{
c->opt = opt;

Expand All @@ -710,10 +710,6 @@ static void init_module(compile_t* c, ast_t* program, pass_opt_t* opt)
if(builtin == NULL)
builtin = package;

c->reach = reach_new();

c->tbaa_mds = tbaa_metadatas_new();

// The name of the first package is the name of the program.
c->filename = package_filename(package);

Expand All @@ -728,9 +724,13 @@ static void init_module(compile_t* c, ast_t* program, pass_opt_t* opt)
else
c->linkage = LLVMPrivateLinkage;

c->context = LLVMContextCreate();
c->machine = make_machine(opt);

if(c->machine == NULL)
return false;

c->context = LLVMContextCreate();

// Create a module.
c->module = LLVMModuleCreateWithNameInContext(c->filename, c->context);

Expand Down Expand Up @@ -758,6 +758,11 @@ static void init_module(compile_t* c, ast_t* program, pass_opt_t* opt)

// Empty frame stack.
c->frame = NULL;

c->reach = reach_new();
c->tbaa_mds = tbaa_metadatas_new();

return true;
}

bool codegen_merge_runtime_bitcode(compile_t* c)
Expand Down Expand Up @@ -888,7 +893,9 @@ bool codegen(ast_t* program, pass_opt_t* opt)
compile_t c;
memset(&c, 0, sizeof(compile_t));

init_module(&c, program, opt);
if(!init_module(&c, program, opt))
return false;

init_runtime(&c);
genprim_reachable_init(&c, program);

Expand Down