Fix various malformed program crashes.

This commit is contained in:
Matt Pharr
2012-05-18 10:44:45 -07:00
parent 8d3ac3ac1e
commit 72c41f104e
3 changed files with 24 additions and 2 deletions

11
ctx.cpp
View File

@@ -2206,6 +2206,17 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum,
if (resultPtrType != NULL)
Assert(ptrRefType != NULL);
llvm::PointerType *llvmPtrType =
llvm::dyn_cast<llvm::PointerType>(fullBasePtr->getType());
if (llvmPtrType != NULL) {
llvm::StructType *llvmStructType =
llvm::dyn_cast<llvm::StructType>(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;

View File

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

View File

@@ -520,7 +520,10 @@ Target::StructOffset(llvm::Type *type, int element,
Assert(td != NULL);
llvm::StructType *structType =
llvm::dyn_cast<llvm::StructType>(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);