From 8368ba853945ab50fe84208d5b944317dc974b11 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Tue, 27 Mar 2012 17:01:31 -0700 Subject: [PATCH] Add missing checks for NULL current basic block in stmt code. Fixes crashes if, for example, these statement types appeared after early returns in the middle of functions. --- stmt.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stmt.cpp b/stmt.cpp index 9aad4291..d7098ff0 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -2228,6 +2228,9 @@ GotoStmt::GotoStmt(const char *l, SourcePos gotoPos, SourcePos ip) void GotoStmt::EmitCode(FunctionEmitContext *ctx) const { + if (!ctx->GetCurrentBasicBlock()) + return; + if (ctx->VaryingCFDepth() > 0) { Error(pos, "\"goto\" statements are only legal under \"uniform\" " "control flow."); @@ -2478,6 +2481,9 @@ lProcessPrintArg(Expr *expr, FunctionEmitContext *ctx, std::string &argTypes) { */ void PrintStmt::EmitCode(FunctionEmitContext *ctx) const { + if (!ctx->GetCurrentBasicBlock()) + return; + ctx->SetDebugPos(pos); // __do_print takes 5 arguments; we'll get them stored in the args[] array @@ -2583,6 +2589,9 @@ AssertStmt::AssertStmt(const std::string &msg, Expr *e, SourcePos p) void AssertStmt::EmitCode(FunctionEmitContext *ctx) const { + if (!ctx->GetCurrentBasicBlock()) + return; + if (expr == NULL) return; const Type *type = expr->GetType(); @@ -2658,6 +2667,9 @@ DeleteStmt::DeleteStmt(Expr *e, SourcePos p) void DeleteStmt::EmitCode(FunctionEmitContext *ctx) const { + if (!ctx->GetCurrentBasicBlock()) + return; + const Type *exprType; if (expr == NULL || ((exprType = expr->GetType()) == NULL)) { Assert(m->errorCount > 0);