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.
This commit is contained in:
Matt Pharr
2012-03-27 17:01:31 -07:00
parent ca0310e335
commit 8368ba8539

View File

@@ -2228,6 +2228,9 @@ GotoStmt::GotoStmt(const char *l, SourcePos gotoPos, SourcePos ip)
void void
GotoStmt::EmitCode(FunctionEmitContext *ctx) const { GotoStmt::EmitCode(FunctionEmitContext *ctx) const {
if (!ctx->GetCurrentBasicBlock())
return;
if (ctx->VaryingCFDepth() > 0) { if (ctx->VaryingCFDepth() > 0) {
Error(pos, "\"goto\" statements are only legal under \"uniform\" " Error(pos, "\"goto\" statements are only legal under \"uniform\" "
"control flow."); "control flow.");
@@ -2478,6 +2481,9 @@ lProcessPrintArg(Expr *expr, FunctionEmitContext *ctx, std::string &argTypes) {
*/ */
void void
PrintStmt::EmitCode(FunctionEmitContext *ctx) const { PrintStmt::EmitCode(FunctionEmitContext *ctx) const {
if (!ctx->GetCurrentBasicBlock())
return;
ctx->SetDebugPos(pos); ctx->SetDebugPos(pos);
// __do_print takes 5 arguments; we'll get them stored in the args[] array // __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 void
AssertStmt::EmitCode(FunctionEmitContext *ctx) const { AssertStmt::EmitCode(FunctionEmitContext *ctx) const {
if (!ctx->GetCurrentBasicBlock())
return;
if (expr == NULL) if (expr == NULL)
return; return;
const Type *type = expr->GetType(); const Type *type = expr->GetType();
@@ -2658,6 +2667,9 @@ DeleteStmt::DeleteStmt(Expr *e, SourcePos p)
void void
DeleteStmt::EmitCode(FunctionEmitContext *ctx) const { DeleteStmt::EmitCode(FunctionEmitContext *ctx) const {
if (!ctx->GetCurrentBasicBlock())
return;
const Type *exprType; const Type *exprType;
if (expr == NULL || ((exprType = expr->GetType()) == NULL)) { if (expr == NULL || ((exprType = expr->GetType()) == NULL)) {
Assert(m->errorCount > 0); Assert(m->errorCount > 0);