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

View File

@@ -730,7 +730,7 @@ ArrayType::LLVMType(llvm::LLVMContext *ctx) const {
bool bool
ArrayType::IsUniformType() const { ArrayType::IsUniformType() const {
return child->IsUniformType(); return child ? child->IsUniformType() : true;
} }
@@ -760,7 +760,7 @@ ArrayType::IsBoolType() const {
bool bool
ArrayType::IsConstType() const { ArrayType::IsConstType() const {
return child->IsConstType(); return child ? child->IsConstType() : false;
} }
@@ -779,30 +779,40 @@ ArrayType::GetBaseType() const {
const ArrayType * const ArrayType *
ArrayType::GetAsVaryingType() const { ArrayType::GetAsVaryingType() const {
if (child == NULL)
return NULL;
return new ArrayType(child->GetAsVaryingType(), numElements); return new ArrayType(child->GetAsVaryingType(), numElements);
} }
const ArrayType * const ArrayType *
ArrayType::GetAsUniformType() const { ArrayType::GetAsUniformType() const {
if (child == NULL)
return NULL;
return new ArrayType(child->GetAsUniformType(), numElements); return new ArrayType(child->GetAsUniformType(), numElements);
} }
const Type * const Type *
ArrayType::GetSOAType(int width) const { ArrayType::GetSOAType(int width) const {
if (child == NULL)
return NULL;
return new ArrayType(child->GetSOAType(width), numElements); return new ArrayType(child->GetSOAType(width), numElements);
} }
const ArrayType * const ArrayType *
ArrayType::GetAsConstType() const { ArrayType::GetAsConstType() const {
if (child == NULL)
return NULL;
return new ArrayType(child->GetAsConstType(), numElements); return new ArrayType(child->GetAsConstType(), numElements);
} }
const ArrayType * const ArrayType *
ArrayType::GetAsNonConstType() const { ArrayType::GetAsNonConstType() const {
if (child == NULL)
return NULL;
return new ArrayType(child->GetAsNonConstType(), numElements); return new ArrayType(child->GetAsNonConstType(), numElements);
} }
@@ -841,6 +851,8 @@ ArrayType::GetString() const {
std::string std::string
ArrayType::Mangle() const { ArrayType::Mangle() const {
if (child == NULL)
return "(error)";
std::string s = child->Mangle(); std::string s = child->Mangle();
char buf[16]; char buf[16];
if (numElements > 0) if (numElements > 0)