Fix issue #391: input stack underflow on too few macro arguments.
authorJohn Kessenich <cepheus@frii.com>
Tue, 19 Jul 2016 20:32:52 +0000 (14:32 -0600)
committerJohn Kessenich <cepheus@frii.com>
Tue, 19 Jul 2016 20:32:52 +0000 (14:32 -0600)
Test/badMacroArgs.frag [new file with mode: 0755]
Test/baseResults/badMacroArgs.frag.out [new file with mode: 0644]
Test/cppIndent.vert
Test/runtests
glslang/MachineIndependent/preprocessor/PpContext.h
glslang/MachineIndependent/preprocessor/PpTokens.cpp

diff --git a/Test/badMacroArgs.frag b/Test/badMacroArgs.frag
new file mode 100755 (executable)
index 0000000..7d7de87
--- /dev/null
@@ -0,0 +1,4 @@
+#version 400\r
+\r
+#define m(a) a\r
+m()
\ No newline at end of file
diff --git a/Test/baseResults/badMacroArgs.frag.out b/Test/baseResults/badMacroArgs.frag.out
new file mode 100644 (file)
index 0000000..6a46a0f
--- /dev/null
@@ -0,0 +1,7 @@
+badMacroArgs.frag
+Warning, version 400 is not yet complete; most version-specific features are present, but some are missing.
+ERROR: 0:4: 'macro expansion' : Too few args in Macro m
+ERROR: 0:4: '' :  syntax error
+ERROR: 2 compilation errors.  No code generated.
+
+
index 49ec8ba..41bb12e 100644 (file)
@@ -58,4 +58,4 @@ sum += 900000000.0;
 
 #define FUNC(a,b)              a+b
 // needs to be last test in file due to syntax error
-void foo986(){ FUNC( (((2)))), 4); }  // ERROR, too many )
+void foo986(){ FUNC( (((2)))), 4); }  // ERROR, too few arguments )
index ae7ed45..5e777a8 100755 (executable)
@@ -19,6 +19,13 @@ fi
 rm -f comp.spv frag.spv geom.spv tesc.spv tese.spv vert.spv
 
 #
+# special tests
+#
+
+$EXE badMacroArgs.frag > $TARGETDIR/badMacroArgs.frag.out
+diff -b $BASEDIR/badMacroArgs.frag.out $TARGETDIR/badMacroArgs.frag.out || HASERROR=1
+
+#
 # reflection tests
 #
 echo Running reflection...
index 23021e2..013c90e 100644 (file)
@@ -218,7 +218,7 @@ protected:
     TParseContextBase& parseContext;
 
     // Get the next token from *stack* of input sources, popping input sources
-    // that are out of tokens, down until an input sources is found that has a token.
+    // that are out of tokens, down until an input source is found that has a token.
     // Return EndOfInput when there are no more tokens to be found by doing this.
     int scanToken(TPpToken* ppToken)
     {
@@ -226,7 +226,7 @@ protected:
 
         while (! inputStack.empty()) {
             token = inputStack.back()->scan(ppToken);
-            if (token != EndOfInput)
+            if (token != EndOfInput || inputStack.empty())
                 break;
             popInput();
         }
index 54d495e..7a1a244 100644 (file)
@@ -179,7 +179,7 @@ int TPpContext::ReadToken(TokenStream *pTok, TPpToken *ppToken)
     if (ltoken > 127)
         ltoken += 128;
     switch (ltoken) {
-    case '#':        
+    case '#':
         if (lReadByte(pTok) == '#') {
             parseContext.requireProfile(ppToken->loc, ~EEsProfile, "token pasting (##)");
             parseContext.profileRequires(ppToken->loc, ~EEsProfile, 130, 0, "token pasting (##)");