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,7 +95,8 @@ 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);
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);

View File

@@ -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)