Fix some crashes from malformed programs

This commit is contained in:
Matt Pharr
2011-10-11 08:28:50 -07:00
parent ecda4561bd
commit 7cd7ca82d6
2 changed files with 21 additions and 4 deletions

View File

@@ -95,8 +95,9 @@ Function::Function(DeclSpecs *ds, Declarator *decl, Stmt *c) {
type = dynamic_cast<const FunctionType *>(decl->GetType(ds));
assert(type != NULL);
sym = m->symbolTable->LookupFunction(decl->sym->name.c_str(), type);
assert(sym != NULL);
sym->pos = decl->pos;
if (sym != NULL)
// May be NULL due to error earlier in compilation
sym->pos = decl->pos;
isExported = (ds->storageClass == SC_EXPORT);
@@ -572,6 +573,10 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
void
Function::GenerateIR() {
if (sym == NULL)
// May be NULL due to error earlier in compilation
return;
llvm::Function *function = sym->function;
assert(function != NULL);