diff --git a/func.cpp b/func.cpp index 12fb68a1..4a37994f 100644 --- a/func.cpp +++ b/func.cpp @@ -95,8 +95,9 @@ Function::Function(DeclSpecs *ds, Declarator *decl, Stmt *c) { type = dynamic_cast(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); diff --git a/type.cpp b/type.cpp index 2353b8e0..bf56904a 100644 --- a/type.cpp +++ b/type.cpp @@ -730,7 +730,7 @@ ArrayType::LLVMType(llvm::LLVMContext *ctx) const { bool ArrayType::IsUniformType() const { - return child->IsUniformType(); + return child ? child->IsUniformType() : true; } @@ -760,7 +760,7 @@ ArrayType::IsBoolType() const { bool ArrayType::IsConstType() const { - return child->IsConstType(); + return child ? child->IsConstType() : false; } @@ -779,30 +779,40 @@ ArrayType::GetBaseType() const { const ArrayType * ArrayType::GetAsVaryingType() const { + if (child == NULL) + return NULL; return new ArrayType(child->GetAsVaryingType(), numElements); } const ArrayType * ArrayType::GetAsUniformType() const { + if (child == NULL) + return NULL; return new ArrayType(child->GetAsUniformType(), numElements); } const Type * ArrayType::GetSOAType(int width) const { + if (child == NULL) + return NULL; return new ArrayType(child->GetSOAType(width), numElements); } const ArrayType * ArrayType::GetAsConstType() const { + if (child == NULL) + return NULL; return new ArrayType(child->GetAsConstType(), numElements); } const ArrayType * ArrayType::GetAsNonConstType() const { + if (child == NULL) + return NULL; return new ArrayType(child->GetAsNonConstType(), numElements); } @@ -841,6 +851,8 @@ ArrayType::GetString() const { std::string ArrayType::Mangle() const { + if (child == NULL) + return "(error)"; std::string s = child->Mangle(); char buf[16]; if (numElements > 0)