From 6fee94460f40f170ca8db143e2a219d96d81dea2 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Sat, 16 Feb 2019 07:35:13 -0700 Subject: [PATCH] PP: Fix #1694: Rationalize errors on partially expanded macro argument. --- Test/baseResults/cppBad2.vert.out | 3 ++- Test/baseResults/cppBad3.vert.out | 3 ++- Test/baseResults/cppBad4.vert.out | 19 +++++++++++++++++++ Test/baseResults/cppBad5.vert.out | 19 +++++++++++++++++++ Test/cppBad4.vert | 4 ++++ Test/cppBad5.vert | 4 ++++ glslang/MachineIndependent/preprocessor/Pp.cpp | 11 +++++------ glslang/MachineIndependent/preprocessor/PpScanner.cpp | 2 +- gtests/AST.FromFile.cpp | 2 ++ 9 files changed, 58 insertions(+), 9 deletions(-) create mode 100755 Test/baseResults/cppBad4.vert.out create mode 100755 Test/baseResults/cppBad5.vert.out create mode 100755 Test/cppBad4.vert create mode 100755 Test/cppBad5.vert diff --git a/Test/baseResults/cppBad2.vert.out b/Test/baseResults/cppBad2.vert.out index af9ff38..0398e5e 100644 --- a/Test/baseResults/cppBad2.vert.out +++ b/Test/baseResults/cppBad2.vert.out @@ -1,6 +1,7 @@ cppBad2.vert ERROR: 0:3: 'macro expansion' : End of input in macro b -ERROR: 1 compilation errors. No code generated. +ERROR: 0:3: '' : compilation terminated +ERROR: 2 compilation errors. No code generated. Shader version: 100 diff --git a/Test/baseResults/cppBad3.vert.out b/Test/baseResults/cppBad3.vert.out index 46f94da..c454c1a 100755 --- a/Test/baseResults/cppBad3.vert.out +++ b/Test/baseResults/cppBad3.vert.out @@ -1,6 +1,7 @@ cppBad3.vert ERROR: 0:3: 'macro expansion' : End of input in macro y -ERROR: 1 compilation errors. No code generated. +ERROR: 0:3: '' : compilation terminated +ERROR: 2 compilation errors. No code generated. Shader version: 100 diff --git a/Test/baseResults/cppBad4.vert.out b/Test/baseResults/cppBad4.vert.out new file mode 100755 index 0000000..693ea8e --- /dev/null +++ b/Test/baseResults/cppBad4.vert.out @@ -0,0 +1,19 @@ +cppBad4.vert +ERROR: 0:4: 'macro expansion' : unexpected '#' g +ERROR: 0:5: '' : syntax error, unexpected SEMICOLON, expecting LEFT_PAREN +ERROR: 2 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/baseResults/cppBad5.vert.out b/Test/baseResults/cppBad5.vert.out new file mode 100755 index 0000000..83043bb --- /dev/null +++ b/Test/baseResults/cppBad5.vert.out @@ -0,0 +1,19 @@ +cppBad5.vert +ERROR: 0:4: 'macro expansion' : End of input in macro g +ERROR: 0:5: '' : compilation terminated +ERROR: 2 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/cppBad4.vert b/Test/cppBad4.vert new file mode 100755 index 0000000..ca43841 --- /dev/null +++ b/Test/cppBad4.vert @@ -0,0 +1,4 @@ +int,i= +#define f g(#g(y +#define g(m) +g(f) diff --git a/Test/cppBad5.vert b/Test/cppBad5.vert new file mode 100755 index 0000000..9ae5056 --- /dev/null +++ b/Test/cppBad5.vert @@ -0,0 +1,4 @@ +int,i= +#define f g($g(y +#define g(m) +g(f) diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp index 0c5d5fe..1b83bda 100755 --- a/glslang/MachineIndependent/preprocessor/Pp.cpp +++ b/glslang/MachineIndependent/preprocessor/Pp.cpp @@ -1027,7 +1027,9 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream& arg, TPpToken* case MacroExpandNotStarted: break; case MacroExpandError: - token = EndOfInput; + // toss the rest of the pushed-input argument by scanning until tMarkerInput + while ((token = scanToken(ppToken)) != tMarkerInput::marker && token != EndOfInput) + ; break; case MacroExpandStarted: case MacroExpandUndef: @@ -1039,13 +1041,10 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream& arg, TPpToken* expandedArg->putToken(token, ppToken); } - if (token == EndOfInput) { + if (token != tMarkerInput::marker) { // Error, or MacroExpand ate the marker, so had bad input, recover delete expandedArg; expandedArg = nullptr; - } else { - // remove the marker - popInput(); } return expandedArg; @@ -1262,7 +1261,7 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b if (token == ')') { // closing paren of call - if (in->mac->args.size() == 1 && tokenRecorded == 0) + if (in->mac->args.size() == 1 && !tokenRecorded) break; arg++; break; diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index 40627f8..8dd1036 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 || token == tMarkerInput::marker) { + if (token == EndOfInput) { missingEndifCheck(); return EndOfInput; } diff --git a/gtests/AST.FromFile.cpp b/gtests/AST.FromFile.cpp index 2f1f011..955e3a8 100644 --- a/gtests/AST.FromFile.cpp +++ b/gtests/AST.FromFile.cpp @@ -97,6 +97,8 @@ INSTANTIATE_TEST_CASE_P( "cppBad.vert", "cppBad2.vert", "cppBad3.vert", + "cppBad4.vert", + "cppBad5.vert", "cppComplexExpr.vert", "cppDeepNest.frag", "cppPassMacroName.frag", -- 2.7.4