Bug 27216 - Assignment with a function call in an if statement causes an assertion failure
Summary: Assignment with a function call in an if statement causes an assertion failure
Status: CLOSED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: git
Hardware: Other All
: medium critical
Assignee: Brian Paul
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 29044
  Show dependency treegraph
 
Reported: 2010-03-20 14:52 UTC by Neil Roberts
Modified: 2010-07-14 13:35 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Neil Roberts 2010-03-20 14:52:34 UTC
This GLSL fragment shader causes an assertion failure from Mesa:

 void
 main ()
 {
   float thing;

   if ((thing = sqrt (5.0)) > 1.0)
     gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0);
 }

The assertion is "assert(index >= 0);" in storage_to_src_reg in slang_emit.c

Taking away the assignment or the function call avoids the problem. As does moving the expression to outside the if condition.
Comment 1 Vinson Lee 2010-03-21 22:36:50 UTC
mesa: 9fc6c8b831e5b43ae86ece6a531fc892f6f66356 (master)

(gdb) bt
#0  0x0073f422 in __kernel_vsyscall ()
#1  0x009ff4d1 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2  0x00a02932 in *__GI_abort () at abort.c:92
#3  0x009f8648 in *__GI___assert_fail (assertion=0x424373 "index >= 0", file=0x424300 "shader/slang/slang_emit.c", line=350, 
    function=0x424dd4 "storage_to_src_reg") at assert.c:81
#4  0x003a2373 in storage_to_src_reg (src=0x97f965c, st=0xb65a7de0) at shader/slang/slang_emit.c:350
#5  0x003a2bf4 in emit_instruction (emitInfo=0xbfb05680, opcode=OPCODE_IF, dst=0x0, src0=0xb65a7de0, src1=0x0, src2=0x0) at shader/slang/slang_emit.c:593
#6  0x003a4c85 in emit_if (emitInfo=0xbfb05680, n=0xb65a7f40) at shader/slang/slang_emit.c:1700
#7  0x003a6722 in emit (emitInfo=0xbfb05680, n=0xb65a7f40) at shader/slang/slang_emit.c:2488
#8  0x003a64ae in emit (emitInfo=0xbfb05680, n=0xb65a7f80) at shader/slang/slang_emit.c:2361
#9  0x003a64eb in emit (emitInfo=0xbfb05680, n=0xb65a7fc0) at shader/slang/slang_emit.c:2371
#10 0x003a6482 in emit (emitInfo=0xbfb05680, n=0xb65a8040) at shader/slang/slang_emit.c:2358
#11 0x003a6bf2 in _slang_emit_code (n=0xb65a8040, vt=0xb659fc10, prog=0x97f51e0, pragmas=0x94f1d78, withEnd=1 '\001', log=0xbfb06bfc)
    at shader/slang/slang_emit.c:2645
#12 0x003a1acc in _slang_codegen_function (A=0xbfb0571c, fun=0xb65a2b88) at shader/slang/slang_codegen.c:5345
#13 0x002d6da1 in parse_code_unit (C=0xbfb05924, unit=0xbfb05bd4, shader=0x94f1d58) at shader/slang/slang_compile.c:2636
#14 0x002d6e7b in compile_binary (prod=0x980bd78 "\005\001", unit=0xbfb05bd4, version=110, type=SLANG_UNIT_FRAGMENT_SHADER, infolog=0xbfb06bfc, 
    builtin=0xbfb05b24, downlink=0xbfb05ba8, shader=0x94f1d58) at shader/slang/slang_compile.c:2679
#15 0x002d71f7 in compile_with_grammar (
    source=0x97f5160 "void\n main ()\n {\n   float thing;\n\n   if ((thing = sqrt (5.0)) > 1.0)\n     gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0);\n }\n\n\n", 
    unit=0xbfb05bd4, type=SLANG_UNIT_FRAGMENT_SHADER, infolog=0xbfb06bfc, builtin=0xbfb05b24, shader=0x94f1d58, pragmas=0x94f1d78, shader_type=1, 
    parsing_builtin=0) at shader/slang/slang_compile.c:2786
#16 0x002d74fe in compile_object (
    source=0x97f5160 "void\n main ()\n {\n   float thing;\n\n   if ((thing = sqrt (5.0)) > 1.0)\n     gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0);\n }\n\n\n", 
    object=0xbfb05b24, type=SLANG_UNIT_FRAGMENT_SHADER, infolog=0xbfb06bfc, shader=0x94f1d58, pragmas=0x94f1d78) at shader/slang/slang_compile.c:2912
#17 0x002d767e in _slang_compile (ctx=0x94c5248, shader=0x94f1d58) at shader/slang/slang_compile.c:2964
#18 0x0028a42a in _mesa_compile_shader (ctx=0x94c5248, shaderObj=1) at shader/shader_api.c:1466
#19 0x0034e742 in _mesa_CompileShaderARB (shaderObj=1) at main/shaders.c:80

#4  0x003a2373 in storage_to_src_reg (src=0x97f965c, st=0xb65a7de0) at shader/slang/slang_emit.c:350
350	   assert(index >= 0);
(gdb) print index
$1 = -1


src/mesa/shader/slang/slang_emit.c
   342  static void
   343  storage_to_src_reg(struct prog_src_register *src, const slang_ir_storage *st)
   344  {
   345     const GLboolean relAddr = st->RelAddr;
   346     GLint index = st->Index;
   347     GLuint swizzle = st->Swizzle;
   348  
   349     /* if this is storage relative to some parent storage, walk up the tree */
   350     assert(index >= 0);
   351     while (st->Parent) {
   352        st = st->Parent;
   353        if (st->Index < 0) {
   354           /* an error should have been reported already */
   355           return;
   356        }
   357        assert(st->Index >= 0);
   358        index += st->Index;
   359        swizzle = _slang_swizzle_swizzle(fix_swizzle(st->Swizzle), swizzle);
   360     }
Comment 2 Brian Paul 2010-07-08 08:26:33 UTC
This is fixed with commit 3751e6e1fc385739022d0942b46e175632ad0d4b to Mesa/master.

The piglit test "./bin/shader_runner ./tests/shaders/glsl-if-assign-call.shader_test" also exercises this.
Comment 3 Vinson Lee 2010-07-14 13:35:23 UTC
mesa: f8d81c31cee30821da3aab331a57f484f6a07a5d (master)

Verified fixed.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.