Fix crash in codegen for assert() with malformed program.

Issue #302.
This commit is contained in:
Matt Pharr
2012-06-26 11:54:55 -07:00
parent 79ebcbec4b
commit ceb8ca680c

View File

@@ -3137,11 +3137,12 @@ AssertStmt::EmitCode(FunctionEmitContext *ctx) const {
if (!ctx->GetCurrentBasicBlock()) if (!ctx->GetCurrentBasicBlock())
return; return;
if (expr == NULL) const Type *type;
return; if (expr == NULL ||
const Type *type = expr->GetType(); (type = expr->GetType()) == NULL) {
if (type == NULL) AssertPos(pos, m->errorCount > 0);
return; return;
}
bool isUniform = type->IsUniformType(); bool isUniform = type->IsUniformType();
// The actual functionality to do the check and then handle falure is // The actual functionality to do the check and then handle falure is
@@ -3162,7 +3163,12 @@ AssertStmt::EmitCode(FunctionEmitContext *ctx) const {
std::vector<llvm::Value *> args; std::vector<llvm::Value *> args;
args.push_back(ctx->GetStringPtr(errorString)); args.push_back(ctx->GetStringPtr(errorString));
args.push_back(expr->GetValue(ctx)); llvm::Value *exprValue = expr->GetValue(ctx);
if (exprValue == NULL) {
AssertPos(pos, m->errorCount > 0);
return;
}
args.push_back(exprValue);
args.push_back(ctx->GetFullMask()); args.push_back(ctx->GetFullMask());
ctx->CallInst(assertFunc, NULL, args, ""); ctx->CallInst(assertFunc, NULL, args, "");