From b06127c51348feb8257cfeb65b470e383f7e2146 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Sat, 16 May 2015 01:15:41 +0000 Subject: [PATCH] glslang PP: make decimal number parser clearer and add boundary tests. Also, disable the warning for "do {} while (true);" 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 | 76 ++++++++++++++++++- Test/numeral.frag | 7 ++ .../preprocessor/PpContext.h | 2 + .../preprocessor/PpScanner.cpp | 14 ++-- 4 files changed, 92 insertions(+), 7 deletions(-) diff --git a/Test/baseResults/numeral.frag.out b/Test/baseResults/numeral.frag.out index c8421a97..63119fa1 100644 --- a/Test/baseResults/numeral.frag.out +++ b/Test/baseResults/numeral.frag.out @@ -10,7 +10,9 @@ ERROR: 0:24: '' : octal literal digit too large ERROR: 0:49: '' : bad digit in hexidecimal literal ERROR: 0:50: '' : hexidecimal literal too big ERROR: 0:88: '' : float literal needs a decimal point or exponent -ERROR: 10 compilation errors. No code generated. +ERROR: 0:98: '' : numeric literal too big +ERROR: 0:101: '' : numeric literal too big +ERROR: 12 compilation errors. No code generated. Shader version: 400 @@ -373,6 +375,36 @@ ERROR: node is still EOpNull! 0:88 'e5' (temp float) 0:88 Constant: 0:88 5.000000 +0:98 Sequence +0:98 move second child to first child (temp uint) +0:98 'g1' (global uint) +0:98 Constant: +0:98 4294967295 (const uint) +0:99 Sequence +0:99 move second child to first child (temp uint) +0:99 'g2' (global uint) +0:99 Constant: +0:99 4294967295 (const uint) +0:100 Sequence +0:100 move second child to first child (temp uint) +0:100 'g3' (global uint) +0:100 Constant: +0:100 4294967294 (const uint) +0:101 Sequence +0:101 move second child to first child (temp int) +0:101 'g4' (global int) +0:101 Constant: +0:101 -1 (const int) +0:102 Sequence +0:102 move second child to first child (temp int) +0:102 'g5' (global int) +0:102 Constant: +0:102 -1 (const int) +0:103 Sequence +0:103 move second child to first child (temp int) +0:103 'g6' (global int) +0:103 Constant: +0:103 -2 (const int) 0:? Linker Objects 0:? 'c2' (layout(location=2 ) out 4-component vector of float) 0:? 'c3' (layout(location=3 ) out 4-component vector of float) @@ -380,6 +412,12 @@ ERROR: node is still EOpNull! 0:? 'c5' (layout(location=5 ) out 4-component vector of float) 0:? 'c6' (layout(location=6 ) out 4-component vector of float) 0:? 'c7' (layout(location=7 ) out 4-component vector of float) +0:? 'g1' (global uint) +0:? 'g2' (global uint) +0:? 'g3' (global uint) +0:? 'g4' (global int) +0:? 'g5' (global int) +0:? 'g6' (global int) Linked fragment stage: @@ -745,6 +783,36 @@ ERROR: node is still EOpNull! 0:88 'e5' (temp float) 0:88 Constant: 0:88 5.000000 +0:98 Sequence +0:98 move second child to first child (temp uint) +0:98 'g1' (global uint) +0:98 Constant: +0:98 4294967295 (const uint) +0:99 Sequence +0:99 move second child to first child (temp uint) +0:99 'g2' (global uint) +0:99 Constant: +0:99 4294967295 (const uint) +0:100 Sequence +0:100 move second child to first child (temp uint) +0:100 'g3' (global uint) +0:100 Constant: +0:100 4294967294 (const uint) +0:101 Sequence +0:101 move second child to first child (temp int) +0:101 'g4' (global int) +0:101 Constant: +0:101 -1 (const int) +0:102 Sequence +0:102 move second child to first child (temp int) +0:102 'g5' (global int) +0:102 Constant: +0:102 -1 (const int) +0:103 Sequence +0:103 move second child to first child (temp int) +0:103 'g6' (global int) +0:103 Constant: +0:103 -2 (const int) 0:? Linker Objects 0:? 'c2' (layout(location=2 ) out 4-component vector of float) 0:? 'c3' (layout(location=3 ) out 4-component vector of float) @@ -752,4 +820,10 @@ ERROR: node is still EOpNull! 0:? 'c5' (layout(location=5 ) out 4-component vector of float) 0:? 'c6' (layout(location=6 ) out 4-component vector of float) 0:? 'c7' (layout(location=7 ) out 4-component vector of float) +0:? 'g1' (global uint) +0:? 'g2' (global uint) +0:? 'g3' (global uint) +0:? 'g4' (global int) +0:? 'g5' (global int) +0:? 'g6' (global int) diff --git a/Test/numeral.frag b/Test/numeral.frag index 379da126..cc0862cc 100644 --- a/Test/numeral.frag +++ b/Test/numeral.frag @@ -94,3 +94,10 @@ layout (location = 04) out vec4 c4; layout (location = 005u) out vec4 c5; layout (location = 0x6) out vec4 c6; layout (location = 0x7u) out vec4 c7; + +uint g1 = 4294967296u; // ERROR, too big +uint g2 = 4294967295u; +uint g3 = 4294967294u; +int g4 = 4294967296; // ERROR, too big +int g5 = 4294967295; +int g6 = 4294967294; diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index 0a1c2b39..97081a34 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -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 { diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index 5c301d3a..fe1fcdd3 100644 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -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;