Skip to content

Commit

Permalink
Do not ignore LLVM target creation errors (#1406)
Browse files Browse the repository at this point in the history
Fixed compiler segmentation fault when given an invalid target triple.
  • Loading branch information
Benoit Vey authored and jemc committed Nov 9, 2016
1 parent 1eb5fd6 commit a9fc0de
Showing 1 changed file with 14 additions and 7 deletions.
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

0 comments on commit a9fc0de

Please sign in to comment.