Bug 33885 - [glsl] GLSL compiler allows recursion
Summary: [glsl] GLSL compiler allows recursion
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: git
Hardware: All All
: low normal
Assignee: Ian Romanick
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-03 16:04 UTC by Vinson Lee
Modified: 2011-12-22 17:06 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Vinson Lee 2011-02-03 16:04:42 UTC
mesa: 2271c793e8650e0e55c054301ab85b5b92b9bf11

The Mesa GLSL compiler allows recursion in GLSL 1.20 shaders. According to the GLSL 1.20 specification this is not allowed.


GLSL 1.20
6.1.1 Function Calling Conventions
Recursion is not allowed, not even statically. Static recursion is present if the static function call graph of the program contains cycles.



piglit/tests/glslparsertest/glsl2/function-12.vert
    12	#version 120
    13	
    14	int A()
    15	{
    16	    return A();
    17	}
    18	
    19	void main()
    20	{
    21	    gl_Position = gl_Vertex;
    22	}
Comment 1 Ian Romanick 2011-02-04 13:25:14 UTC
We do need to fix this.  Many GLSL compilers crash in the presence of recursion (ours probably does too at link-time).  I'm not too worried about not generating a compile-time error for this.  Because of that, I'm lowering the priority.

Thanks for the test case, though.
Comment 2 Ian Romanick 2011-12-22 17:06:17 UTC
This should have been fixed on the 7.11 branch by:

commit 7c98381ed4a2293c5797a2ff003584566a0ce762
Author: Ian Romanick <ian.d.romanick@intel.com>
Date:   Mon Jul 11 10:46:01 2011 -0700

    glsl: Reject shaders that contain static recursion
    
    The GLSL 1.20 and later specs say:
    
        "Recursion is not allowed, not even statically. Static recursion is
        present if the static function call graph of the program contains
        cycles."
    
    Recursion is detected and rejected both a compile-time and at
    link-time.  The complie-time check happens to detect some cases that
    may be removed by various optimization passes.  The spec doesn't seem
    to allow this, but other vendors (e.g., NVIDIA) appear to only check
    at link-time after all optimizations.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=33885
    Reviewed-by: Paul Berry <stereotype441@gmail.com>
    Reviewed-by: Eric Anholt <eric@anholt.net>
    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
    (cherry picked from commit 02c5ae1b3fef75d5c0a715313a69e6b95ebd5b95)
    
    This also squashes in the following commit to make sure that bisects
    in scons builds work:
    
    glsl: Add ir_function_detect_recursion.cpp to SConscript.
    (cherry picked from commit 76bccaff0c54aed10ffbc7c7dc744f1708921409)


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.