From 9840f11f8569b5fffa01663b643b1d0cb93bda4b Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Mon, 11 Feb 2019 03:05:00 -0700 Subject: [PATCH] PP: Fix #1694: Handle badly formed argument substitution. Also added a warning for no space after a macro name. --- Test/baseResults/cppBad.vert.out | 11 ++++++----- Test/baseResults/cppBad3.vert.out | 18 ++++++++++++++++++ Test/cppBad.vert | 3 ++- Test/cppBad3.vert | 3 +++ glslang/MachineIndependent/preprocessor/Pp.cpp | 4 ++++ glslang/MachineIndependent/preprocessor/PpScanner.cpp | 2 +- gtests/AST.FromFile.cpp | 1 + 7 files changed, 35 insertions(+), 7 deletions(-) create mode 100755 Test/baseResults/cppBad3.vert.out create mode 100644 Test/cppBad3.vert diff --git a/Test/baseResults/cppBad.vert.out b/Test/baseResults/cppBad.vert.out index a5267ff..13a5fc1 100644 --- a/Test/baseResults/cppBad.vert.out +++ b/Test/baseResults/cppBad.vert.out @@ -1,9 +1,10 @@ cppBad.vert -ERROR: 0:2: 'preprocessor evaluation' : bad expression -ERROR: 0:2: '#if' : unexpected tokens following directive -ERROR: 0:5: 'string' : End of line in string -ERROR: 0:5: '""' : string literals not supported -ERROR: 0:5: '' : syntax error, unexpected INT, expecting COMMA or SEMICOLON +WARNING: 0:1: '#define' : missing space after macro name +ERROR: 0:3: 'preprocessor evaluation' : bad expression +ERROR: 0:3: '#if' : unexpected tokens following directive +ERROR: 0:6: 'string' : End of line in string +ERROR: 0:6: '""' : string literals not supported +ERROR: 0:6: '' : syntax error, unexpected INT, expecting COMMA or SEMICOLON ERROR: 5 compilation errors. No code generated. diff --git a/Test/baseResults/cppBad3.vert.out b/Test/baseResults/cppBad3.vert.out new file mode 100755 index 0000000..46f94da --- /dev/null +++ b/Test/baseResults/cppBad3.vert.out @@ -0,0 +1,18 @@ +cppBad3.vert +ERROR: 0:3: 'macro expansion' : End of input in macro y +ERROR: 1 compilation errors. No code generated. + + +Shader version: 100 +ERROR: node is still EOpNull! +0:? Linker Objects + + +Linked vertex stage: + +ERROR: Linking vertex stage: Missing entry point: Each stage requires one entry point + +Shader version: 100 +ERROR: node is still EOpNull! +0:? Linker Objects + diff --git a/Test/cppBad.vert b/Test/cppBad.vert index 0044c44..c1548c8 100644 --- a/Test/cppBad.vert +++ b/Test/cppBad.vert @@ -1,4 +1,5 @@ -#define m#0# +#define n#0# +#define m #0# #if m #endif #define n() diff --git a/Test/cppBad3.vert b/Test/cppBad3.vert new file mode 100644 index 0000000..95343db --- /dev/null +++ b/Test/cppBad3.vert @@ -0,0 +1,3 @@ +#define f =y(. +#define y(m) +y(f) \ No newline at end of file diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp index 3441948..0c5d5fe 100755 --- a/glslang/MachineIndependent/preprocessor/Pp.cpp +++ b/glslang/MachineIndependent/preprocessor/Pp.cpp @@ -147,6 +147,10 @@ int TPpContext::CPPdefine(TPpToken* ppToken) } token = scanToken(ppToken); + } else if (token != '\n' && token != EndOfInput && !ppToken->space) { + parseContext.ppWarn(ppToken->loc, "missing space after macro name", "#define", ""); + + return token; } // record the definition of the macro diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index 8dd1036..40627f8 100755 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -1056,7 +1056,7 @@ int TPpContext::tokenize(TPpToken& ppToken) // Handle token-pasting logic token = tokenPaste(token, ppToken); - if (token == EndOfInput) { + if (token == EndOfInput || token == tMarkerInput::marker) { missingEndifCheck(); return EndOfInput; } diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index 8755246..2f1f011 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -96,6 +96,7 @@ INSTANTIATE_TEST_CASE_P( "cppNest.vert", "cppBad.vert", "cppBad2.vert", + "cppBad3.vert", "cppComplexExpr.vert", "cppDeepNest.frag", "cppPassMacroName.frag", -- 2.7.4