diff --git a/ctx.cpp b/ctx.cpp index cb99ac91..e15ee72b 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -2206,6 +2206,17 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, if (resultPtrType != NULL) Assert(ptrRefType != NULL); + llvm::PointerType *llvmPtrType = + llvm::dyn_cast(fullBasePtr->getType()); + if (llvmPtrType != NULL) { + llvm::StructType *llvmStructType = + llvm::dyn_cast(llvmPtrType->getElementType()); + if (llvmStructType->isSized() == false) { + Assert(m->errorCount > 0); + return NULL; + } + } + // (Unfortunately) it's not required to pass a non-NULL ptrRefType, but // if we have one, regularize into a pointer type. const PointerType *ptrType = NULL; diff --git a/expr.cpp b/expr.cpp index 8236e8e4..99cd5bf5 100644 --- a/expr.cpp +++ b/expr.cpp @@ -4813,6 +4813,9 @@ MemberExpr::GetValue(FunctionEmitContext *ctx) const { llvm::Value *mask = NULL; if (lvalue == NULL) { + if (m->errorCount > 0) + return NULL; + // As in the array case, this may be a temporary that hasn't hit // memory; get the full value and stuff it into a temporary array // so that we can index from there... @@ -4889,6 +4892,10 @@ MemberExpr::GetLValue(FunctionEmitContext *ctx) const { llvm::Value *ptr = ctx->AddElementOffset(basePtr, elementNumber, exprLValueType, basePtr->getName().str().c_str()); + if (ptr == NULL) { + Assert(m->errorCount > 0); + return NULL; + } ptr = lAddVaryingOffsetsIfNeeded(ctx, ptr, GetLValueType()); @@ -6606,7 +6613,8 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { // The only legal type conversions for structs are to go from a // uniform to a varying instance of the same struct type. Assert(toStruct->IsVaryingType() && fromStruct->IsUniformType() && - Type::Equal(toStruct, fromStruct->GetAsVaryingType())); + Type::EqualIgnoringConst(toStruct, + fromStruct->GetAsVaryingType())); llvm::Value *origValue = expr->GetValue(ctx); if (!origValue) diff --git a/ispc.cpp b/ispc.cpp index 99155056..ac429cb9 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -520,7 +520,10 @@ Target::StructOffset(llvm::Type *type, int element, Assert(td != NULL); llvm::StructType *structType = llvm::dyn_cast(type); - Assert(structType != NULL); + if (structType == NULL || structType->isSized() == false) { + Assert(m->errorCount > 0); + return NULL; + } const llvm::StructLayout *sl = td->getStructLayout(structType); Assert(sl != NULL);