Bug 33306 - [glsl] GLSL integer division by zero crashes GLSL compiler
[glsl] GLSL integer division by zero crashes GLSL compiler
Status: CLOSED FIXED
Product: Mesa
Classification: Unclassified
Component: glsl-compiler
git
All All
: medium critical
Assigned To: Chad Versace
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-01-20 14:48 UTC by Vinson Lee
Modified: 2011-04-13 20:06 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vinson Lee 2011-01-20 14:48:11 UTC
mesa: 2fb0aebd4a248d2a0725099cd5646253c30c1dc3 (master)

This fragment shader triggers a floating point exception in the Mesa GLSL compiler.

void main() {
   int a = 1 / 0;

   gl_FragColor = vec4(0.0);
}


Program terminated with signal 8, Arithmetic exception.
#0  0x00ab1f89 in ir_expression::constant_expression_value (this=0x8e2e7e0) at ir_constant_expression.cpp:520
520		    data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1];
(gdb) bt
#0  0x00ab1f89 in ir_expression::constant_expression_value (this=0x8e2e7e0) at ir_constant_expression.cpp:520
#1  0x00acee3a in ir_constant_variable_visitor::visit_enter (this=0xbffae640, ir=0x8e2e630) at opt_constant_variable.cpp:117
#2  0x00ab8b9e in ir_assignment::accept (this=0x8e2e630, v=0xbffae640) at ir_hv_accept.cpp:276
#3  0x00ab8615 in visit_list_elements (v=0xbffae640, l=0x90522b8) at ir_hv_accept.cpp:48
#4  0x00ab85d4 in ir_hierarchical_visitor::run (this=0xbffae640, instructions=0x90522b8) at ir_hierarchical_visitor.cpp:282
#5  0x00acec5d in do_constant_variable (instructions=0x90522b8) at opt_constant_variable.cpp:161
#6  0x00aced25 in do_constant_variable_unlinked (instructions=0x8d621f0) at opt_constant_variable.cpp:191
#7  0x00aa9068 in do_common_optimization (ir=0x8d621f0, linked=false, max_unroll_iterations=32) at glsl_parser_extras.cpp:731
#8  0x00a89bc3 in _mesa_glsl_compile_shader (ctx=0x8ced628, shader=0x8d58b78) at program/ir_to_mesa.cpp:2981
#9  0x00a38e1a in compile_shader (shaderObj=1) at main/shaderapi.c:854
#10 _mesa_CompileShaderARB (shaderObj=1) at main/shaderapi.c:1185

(gdb) frame 0
#0  0x00ab1f89 in ir_expression::constant_expression_value (this=0x8e2e7e0) at ir_constant_expression.cpp:520
520		    data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1];
(gdb) print op[0]->value.i[c0]
value has been optimized out
(gdb) print op[1]->value.i[c1]
value has been optimized out
(gdb) l
515		 switch (op[0]->type->base_type) {
516		 case GLSL_TYPE_UINT:
517		    data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1];
518		    break;
519		 case GLSL_TYPE_INT:
520		    data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1];
521		    break;
522		 case GLSL_TYPE_FLOAT:
523		    data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1];
524		    break;
Comment 1 Chad Versace 2011-02-02 10:04:32 UTC
Fixed by commit:
e7c1f058d18f62aa4871aec623f994d7b68cb8c1
glsl: Avoid division-by-zero during constant-folding

Added new Piglit tests:
glslparsertest/glsl2/division-by-zero-01.frag
glslparsertest/glsl2/division-by-zero-02.frag
glslparsertest/glsl2/division-by-zero-03.frag
Comment 2 Vinson Lee 2011-04-13 20:06:28 UTC
mesa: a9a02c8a39620515ec9fd0d774ce329cf67ecb4e (master)

Verified fixed.