Mesa (master): glcpp: Generate an error for division by zero
Ian Romanick
idr at kemper.freedesktop.org
Tue Jan 11 01:49:07 UTC 2011
Module: Mesa
Branch: master
Commit: 9ca5300b6e781150cec903c73cf5fd8e1deee2f1
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9ca5300b6e781150cec903c73cf5fd8e1deee2f1
Author: Ian Romanick <ian.d.romanick at 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.
---
src/glsl/glcpp/glcpp-parse.y | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 148b0ff..e71c0e8 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -398,7 +398,12 @@ expression:
$$ = $1 % $3;
}
| expression '/' expression {
- $$ = $1 / $3;
+ if ($3 == 0) {
+ yyerror (& @1, parser,
+ "division by 0 in preprocessor directive");
+ } else {
+ $$ = $1 / $3;
+ }
}
| expression '*' expression {
$$ = $1 * $3;
More information about the mesa-commit
mailing list