From 31a51becd29b5f56f75cab9dd8b8635074ada83f Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Tue, 19 Jul 2016 14:32:52 -0600 Subject: [PATCH] Fix issue #391: input stack underflow on too few macro arguments. --- Test/badMacroArgs.frag | 4 ++++ Test/baseResults/badMacroArgs.frag.out | 7 +++++++ Test/cppIndent.vert | 2 +- Test/runtests | 7 +++++++ glslang/MachineIndependent/preprocessor/PpContext.h | 4 ++-- glslang/MachineIndependent/preprocessor/PpTokens.cpp | 2 +- 6 files changed, 22 insertions(+), 4 deletions(-) create mode 100755 Test/badMacroArgs.frag create mode 100644 Test/baseResults/badMacroArgs.frag.out diff --git a/Test/badMacroArgs.frag b/Test/badMacroArgs.frag new file mode 100755 index 00000000..7d7de870 --- /dev/null +++ b/Test/badMacroArgs.frag @@ -0,0 +1,4 @@ +#version 400 + +#define m(a) a +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 index 00000000..6a46a0f3 --- /dev/null +++ b/Test/baseResults/badMacroArgs.frag.out @@ -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. + + diff --git a/Test/cppIndent.vert b/Test/cppIndent.vert index 49ec8ba3..41bb12e4 100644 --- a/Test/cppIndent.vert +++ b/Test/cppIndent.vert @@ -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 ) diff --git a/Test/runtests b/Test/runtests index ae7ed450..5e777a8b 100755 --- a/Test/runtests +++ b/Test/runtests @@ -18,6 +18,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 # diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index 23021e24..013c90e5 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -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(); } diff --git a/glslang/MachineIndependent/preprocessor/PpTokens.cpp b/glslang/MachineIndependent/preprocessor/PpTokens.cpp index 54d495e1..7a1a2447 100644 --- a/glslang/MachineIndependent/preprocessor/PpTokens.cpp +++ b/glslang/MachineIndependent/preprocessor/PpTokens.cpp @@ -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 (##)");