diff options
author | marha <marha@users.sourceforge.net> | 2011-02-03 11:20:18 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-02-03 11:20:18 +0000 |
commit | 46fbac6f1b19416ee1dbca883f0d09d9fd75d1eb (patch) | |
tree | 2ddc90cb6bc4f04db80d66a334ecaabf139c0176 /mesalib/src/glsl | |
parent | 97f3d3043a79d6031787c246a67d2a02ff0a8d08 (diff) | |
parent | 83a4fe0dc71aafbef11477b284abe530d3877556 (diff) | |
download | vcxsrv-46fbac6f1b19416ee1dbca883f0d09d9fd75d1eb.tar.gz vcxsrv-46fbac6f1b19416ee1dbca883f0d09d9fd75d1eb.tar.bz2 vcxsrv-46fbac6f1b19416ee1dbca883f0d09d9fd75d1eb.zip |
svn merge ^/branches/released .
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r-- | mesalib/src/glsl/ast_function.cpp | 2 | ||||
-rw-r--r-- | mesalib/src/glsl/glcpp/glcpp-parse.y | 7 | ||||
-rw-r--r-- | mesalib/src/glsl/ir_constant_expression.cpp | 36 |
3 files changed, 36 insertions, 9 deletions
diff --git a/mesalib/src/glsl/ast_function.cpp b/mesalib/src/glsl/ast_function.cpp index 28d49ee0d..7611617df 100644 --- a/mesalib/src/glsl/ast_function.cpp +++ b/mesalib/src/glsl/ast_function.cpp @@ -75,7 +75,7 @@ prototype_string(const glsl_type *return_type, const char *name, char *str = NULL; if (return_type != NULL) - ralloc_asprintf(&str, "%s ", return_type->name); + str = ralloc_asprintf(NULL, "%s ", return_type->name); ralloc_asprintf_append(&str, "%s(", name); diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y index aa5a0c4f2..1f6e67fa0 100644 --- a/mesalib/src/glsl/glcpp/glcpp-parse.y +++ b/mesalib/src/glsl/glcpp/glcpp-parse.y @@ -388,7 +388,12 @@ expression: $$ = $1 + $3; } | expression '%' expression { - $$ = $1 % $3; + if ($3 == 0) { + yyerror (& @1, parser, + "zero modulus in preprocessor directive"); + } else { + $$ = $1 % $3; + } } | expression '/' expression { if ($3 == 0) { diff --git a/mesalib/src/glsl/ir_constant_expression.cpp b/mesalib/src/glsl/ir_constant_expression.cpp index cf958aa7a..2841fb350 100644 --- a/mesalib/src/glsl/ir_constant_expression.cpp +++ b/mesalib/src/glsl/ir_constant_expression.cpp @@ -288,20 +288,24 @@ ir_expression::constant_expression_value() break; case ir_unop_rcp: + /* FINISHME: Emit warning when division-by-zero is detected. */ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (this->type->base_type) { case GLSL_TYPE_UINT: - if (op[0]->value.u[c] != 0.0) - data.u[c] = 1 / op[0]->value.u[c]; + if (op[0]->value.u[c] == 0.0) + return NULL; + data.u[c] = 1 / op[0]->value.u[c]; break; case GLSL_TYPE_INT: - if (op[0]->value.i[c] != 0.0) - data.i[c] = 1 / op[0]->value.i[c]; + if (op[0]->value.i[c] == 0.0) + return NULL; + data.i[c] = 1 / op[0]->value.i[c]; break; case GLSL_TYPE_FLOAT: - if (op[0]->value.f[c] != 0.0) - data.f[c] = 1.0F / op[0]->value.f[c]; + if (op[0]->value.f[c] == 0.0) + return NULL; + data.f[c] = 1.0F / op[0]->value.f[c]; break; default: assert(0); @@ -310,9 +314,13 @@ ir_expression::constant_expression_value() break; case ir_unop_rsq: + /* FINISHME: Emit warning when division-by-zero is detected. */ assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < op[0]->type->components(); c++) { - data.f[c] = 1.0F / sqrtf(op[0]->value.f[c]); + float s = sqrtf(op[0]->value.f[c]); + if (s == 0) + return NULL; + data.f[c] = 1.0F / s; } break; @@ -507,6 +515,7 @@ ir_expression::constant_expression_value() break; case ir_binop_div: + /* FINISHME: Emit warning when division-by-zero is detected. */ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; @@ -514,12 +523,18 @@ ir_expression::constant_expression_value() switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: + if (op[1]->value.u[c1] == 0) + return NULL; data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1]; break; case GLSL_TYPE_INT: + if (op[1]->value.i[c1] == 0) + return NULL; data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1]; break; case GLSL_TYPE_FLOAT: + if (op[1]->value.f[c1] == 0) + return NULL; data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1]; break; default: @@ -529,6 +544,7 @@ ir_expression::constant_expression_value() break; case ir_binop_mod: + /* FINISHME: Emit warning when division-by-zero is detected. */ assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; c < components; @@ -536,12 +552,18 @@ ir_expression::constant_expression_value() switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: + if (op[1]->value.u[c1] == 0) + return NULL; data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1]; break; case GLSL_TYPE_INT: + if (op[1]->value.i[c1] == 0) + return NULL; data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1]; break; case GLSL_TYPE_FLOAT: + if (op[1]->value.f[c1] == 0) + return NULL; /* We don't use fmod because it rounds toward zero; GLSL specifies * the use of floor. */ |