From c80bfeacf6349ec4c0c6163ed0eb288e007c7d40 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Thu, 9 Aug 2012 14:59:29 -0700 Subject: [PATCH] Fix crashes when input program tried to access undefined struct types. (This in particular would happen when there was an error in the body of a struct definition and we were left with an UndefinedStructType and then later tried to do loads/stores from/to it.) Issue #356. --- ctx.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ctx.cpp b/ctx.cpp index 4f63aeea..8ca1e4a0 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -2484,6 +2484,12 @@ FunctionEmitContext::LoadInst(llvm::Value *ptr, llvm::Value *mask, AssertPos(currentPos, ptrType != NULL); } + if (CastType(ptrType->GetBaseType())) { + Error(currentPos, "Unable to load to undefined struct type \"%s\".", + ptrType->GetBaseType()->GetString().c_str()); + return NULL; + } + if (ptrType->IsUniformType()) { if (ptrType->IsSlice()) { return loadUniformFromSOA(ptr, mask, ptrType, name); @@ -2964,6 +2970,12 @@ FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr, AssertPos(currentPos, ptrType != NULL); } + if (CastType(ptrType->GetBaseType())) { + Error(currentPos, "Unable to store to undefined struct type \"%s\".", + ptrType->GetBaseType()->GetString().c_str()); + return; + } + // Figure out what kind of store we're doing here if (ptrType->IsUniformType()) { if (ptrType->IsSlice())