Summary: | [glsl] division by zero crashes GLSL compiler | ||
---|---|---|---|
Product: | Mesa | Reporter: | Vinson Lee <vlee> |
Component: | glsl-compiler | Assignee: | Ian Romanick <idr> |
Status: | CLOSED FIXED | QA Contact: | |
Severity: | critical | ||
Priority: | medium | ||
Version: | 7.10 | ||
Hardware: | All | ||
OS: | All | ||
Whiteboard: | |||
i915 platform: | i915 features: | ||
Attachments: | Generate an error for division by zero in a preprocessor directive |
Description
Vinson Lee
2011-01-04 13:29:39 UTC
Created attachment 41859 [details] [review] Generate an error for division by zero in a preprocessor directive This matches GCCs behavior, so it should be correct for GLSL as well. Is this test from an application that is expecting some other behavior? If so, what is it expecting? Does this work on other GLSL implementations? (In reply to comment #1) > This matches GCCs behavior, so it should be correct for GLSL as well. Is this > test from an application that is expecting some other behavior? If so, what is > it expecting? Does this work on other GLSL implementations? This test was not from any known application. NVIDIA, ATI, Intel, and S3 GLSL compilers also crash with a floating point exception. The Apple GLSL compiler does not crash and interprets the division by zero as true. (In reply to comment #2) > (In reply to comment #1) > > This matches GCCs behavior, so it should be correct for GLSL as well. Is this > > test from an application that is expecting some other behavior? If so, what is > > it expecting? Does this work on other GLSL implementations? > > This test was not from any known application. > > NVIDIA, ATI, Intel, and S3 GLSL compilers also crash with a floating point > exception. The Apple GLSL compiler does not crash and interprets the division > by zero as true. Out of curiosity, what does Apple do for 0/0? It would be interesting to know the actual value generated for arbitrary x/0. My guess is that it's either x or maximum representable integer with same sign as x. The crash is fixed in master by the following patch series. I'm leaving the bug open, but I'm reassigning it to version 7.10. I want to wait on the cherry pick until we get some resolution as to what the correct behavior is. commit a302d740bd1e90d3db2b8cee79b2d5ee1220f8bf Author: Ian Romanick <ian.d.romanick@intel.com> Date: Mon Jan 10 17:38:56 2011 -0800 glcpp: Refresh autogenerated lexer and parser files. For the previous commit. commit 9ca5300b6e781150cec903c73cf5fd8e1deee2f1 Author: Ian Romanick <ian.d.romanick@intel.com> Date: Mon Jan 10 13:33:07 2011 -0800 glcpp: Generate an error for division by zero When GCC encounters a division by zero in a preprocessor directive, it generates an error. Since the GLSL spec says that the GLSL preprocessor behaves like the C preprocessor, we should generate that same error. It's worth noting that I cannot find any text in the C99 spec that says this should be an error. The only text that I can find is line 5 on page 82 (section 6.5.5 Multiplicative Opertors), which says, "The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined." Fixes 093-divide-by-zero.c test and bugzilla #32831. NOTE: This is a candidate for the 7.9 and 7.10 branches. (In reply to comment #3) > Out of curiosity, what does Apple do for 0/0? It would be interesting to know > the actual value generated for arbitrary x/0. My guess is that it's either x > or maximum representable integer with same sign as x. The Apple GLSL compiler's preprocessor interprets 0/0 as true. (0 / 0) - true (1 / 0) - true (0 / 1) - false (1 / 1) - true ((0 / 0) > 0) - true ((1 / 0) > 0) - true ((0 / 0) < 0) - false ((1 / 0) < 0) - false ((-1 / 0) > 0) - true ((-1 / 0) < 0) - false Fixed by ef2f4b546946a4f97af602e5f52227d552a58247 (7.9) and 50d40edb8ce24e9725a00b8eb3ce3b2d4bb16d63 (7.10). mesa: a9a02c8a39620515ec9fd0d774ce329cf67ecb4e (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.