glslang PP: make decimal number parser clearer and add boundary tests. Also, disable...
authorJohn Kessenich <cepheus@frii.com>
Sat, 16 May 2015 01:15:41 +0000 (01:15 +0000)
committerJohn Kessenich <cepheus@frii.com>
Sat, 16 May 2015 01:15:41 +0000 (01:15 +0000)
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31215 e7fa87d3-cd2b-0410-9028-fcbf551c1848

Test/baseResults/numeral.frag.out
Test/numeral.frag
glslang/MachineIndependent/preprocessor/PpContext.h
glslang/MachineIndependent/preprocessor/PpScanner.cpp

index c8421a9..63119fa 100644 (file)
@@ -10,7 +10,9 @@ ERROR: 0:24: '' : octal literal digit too large
 ERROR: 0:49: '' : bad digit in hexidecimal literal \r
 ERROR: 0:50: '' : hexidecimal literal too big \r
 ERROR: 0:88: '' : float literal needs a decimal point or exponent \r
-ERROR: 10 compilation errors.  No code generated.\r
+ERROR: 0:98: '' : numeric literal too big \r
+ERROR: 0:101: '' : numeric literal too big \r
+ERROR: 12 compilation errors.  No code generated.\r
 \r
 \r
 Shader version: 400\r
@@ -373,6 +375,36 @@ ERROR: node is still EOpNull!
 0:88          'e5' (temp float)\r
 0:88          Constant:\r
 0:88            5.000000\r
+0:98  Sequence\r
+0:98    move second child to first child (temp uint)\r
+0:98      'g1' (global uint)\r
+0:98      Constant:\r
+0:98        4294967295 (const uint)\r
+0:99  Sequence\r
+0:99    move second child to first child (temp uint)\r
+0:99      'g2' (global uint)\r
+0:99      Constant:\r
+0:99        4294967295 (const uint)\r
+0:100  Sequence\r
+0:100    move second child to first child (temp uint)\r
+0:100      'g3' (global uint)\r
+0:100      Constant:\r
+0:100        4294967294 (const uint)\r
+0:101  Sequence\r
+0:101    move second child to first child (temp int)\r
+0:101      'g4' (global int)\r
+0:101      Constant:\r
+0:101        -1 (const int)\r
+0:102  Sequence\r
+0:102    move second child to first child (temp int)\r
+0:102      'g5' (global int)\r
+0:102      Constant:\r
+0:102        -1 (const int)\r
+0:103  Sequence\r
+0:103    move second child to first child (temp int)\r
+0:103      'g6' (global int)\r
+0:103      Constant:\r
+0:103        -2 (const int)\r
 0:?   Linker Objects\r
 0:?     'c2' (layout(location=2 ) out 4-component vector of float)\r
 0:?     'c3' (layout(location=3 ) out 4-component vector of float)\r
@@ -380,6 +412,12 @@ ERROR: node is still EOpNull!
 0:?     'c5' (layout(location=5 ) out 4-component vector of float)\r
 0:?     'c6' (layout(location=6 ) out 4-component vector of float)\r
 0:?     'c7' (layout(location=7 ) out 4-component vector of float)\r
+0:?     'g1' (global uint)\r
+0:?     'g2' (global uint)\r
+0:?     'g3' (global uint)\r
+0:?     'g4' (global int)\r
+0:?     'g5' (global int)\r
+0:?     'g6' (global int)\r
 \r
 \r
 Linked fragment stage:\r
@@ -745,6 +783,36 @@ ERROR: node is still EOpNull!
 0:88          'e5' (temp float)\r
 0:88          Constant:\r
 0:88            5.000000\r
+0:98  Sequence\r
+0:98    move second child to first child (temp uint)\r
+0:98      'g1' (global uint)\r
+0:98      Constant:\r
+0:98        4294967295 (const uint)\r
+0:99  Sequence\r
+0:99    move second child to first child (temp uint)\r
+0:99      'g2' (global uint)\r
+0:99      Constant:\r
+0:99        4294967295 (const uint)\r
+0:100  Sequence\r
+0:100    move second child to first child (temp uint)\r
+0:100      'g3' (global uint)\r
+0:100      Constant:\r
+0:100        4294967294 (const uint)\r
+0:101  Sequence\r
+0:101    move second child to first child (temp int)\r
+0:101      'g4' (global int)\r
+0:101      Constant:\r
+0:101        -1 (const int)\r
+0:102  Sequence\r
+0:102    move second child to first child (temp int)\r
+0:102      'g5' (global int)\r
+0:102      Constant:\r
+0:102        -1 (const int)\r
+0:103  Sequence\r
+0:103    move second child to first child (temp int)\r
+0:103      'g6' (global int)\r
+0:103      Constant:\r
+0:103        -2 (const int)\r
 0:?   Linker Objects\r
 0:?     'c2' (layout(location=2 ) out 4-component vector of float)\r
 0:?     'c3' (layout(location=3 ) out 4-component vector of float)\r
@@ -752,4 +820,10 @@ ERROR: node is still EOpNull!
 0:?     'c5' (layout(location=5 ) out 4-component vector of float)\r
 0:?     'c6' (layout(location=6 ) out 4-component vector of float)\r
 0:?     'c7' (layout(location=7 ) out 4-component vector of float)\r
+0:?     'g1' (global uint)\r
+0:?     'g2' (global uint)\r
+0:?     'g3' (global uint)\r
+0:?     'g4' (global int)\r
+0:?     'g5' (global int)\r
+0:?     'g6' (global int)\r
 \r
index 379da12..cc0862c 100644 (file)
@@ -94,3 +94,10 @@ layout (location = 04) out vec4 c4;
 layout (location = 005u) out vec4 c5;\r
 layout (location = 0x6) out vec4 c6;\r
 layout (location = 0x7u) out vec4 c7;\r
+\r
+uint g1 = 4294967296u; // ERROR, too big\r
+uint g2 = 4294967295u;\r
+uint g3 = 4294967294u;\r
+int g4 = 4294967296;   // ERROR, too big\r
+int g5 = 4294967295;\r
+int g6 = 4294967294;\r
index 0a1c2b3..97081a3 100644 (file)
@@ -80,6 +80,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "../ParseHelper.h"
 
+#pragma warning(disable : 4127)
+
 namespace glslang {
 
 class TPpToken {
index 5c301d3..fe1fcdd 100644 (file)
@@ -432,19 +432,21 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken)
             } else {
                 // Finish handling signed and unsigned integers
                 int numericLen = len;
-                int uint = 0;
+                bool uint = false;
                 if (ch == 'u' || ch == 'U') {
                     if (len < TPpToken::maxTokenLength)
                         ppToken->name[len++] = (char)ch;
-                    uint = 1;
+                    uint = true;
                 } else
                     pp->ungetChar();
 
-                ppToken->name[len] = '\0';                             
+                ppToken->name[len] = '\0';
                 ival = 0;
-                for (ii = 0; ii < numericLen; ii++) {
-                    ch = ppToken->name[ii] - '0';
-                    if ((ival > 0x19999999u) || (ival == 0x19999999u && ch >= 6)) {
+                const unsigned oneTenthMaxInt  = 0xFFFFFFFFu / 10;
+                const unsigned remainderMaxInt = 0xFFFFFFFFu - 10 * oneTenthMaxInt;
+                for (int i = 0; i < numericLen; i++) {
+                    ch = ppToken->name[i] - '0';
+                    if ((ival > oneTenthMaxInt) || (ival == oneTenthMaxInt && ch > remainderMaxInt)) {
                         pp->parseContext.error(ppToken->loc, "numeric literal too big", "", "");
                         ival = 0xFFFFFFFFu;
                         break;