From fb22b69fc6295bbeed75d4269b4d6ae440cb158c Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Tue, 28 Feb 2017 18:04:47 -0700
Subject: [PATCH] PP: Partially address issue #738: handle premature end of
 argument when token pasting.

---
 Test/baseResults/tokenPaste.vert.out           | 5 ++++-
 Test/tokenPaste.vert                           | 3 +++
 glslang/Include/revision.h                     | 2 +-
 glslang/MachineIndependent/preprocessor/Pp.cpp | 2 ++
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Test/baseResults/tokenPaste.vert.out b/Test/baseResults/tokenPaste.vert.out
index 9a06c34da..4bab57b0b 100755
--- a/Test/baseResults/tokenPaste.vert.out
+++ b/Test/baseResults/tokenPaste.vert.out
@@ -5,7 +5,10 @@ ERROR: 0:40: '##' : unexpected location; end of replacement list
 ERROR: 0:49: '##' : combined tokens are too long 
 ERROR: 0:52: '##' : not supported for these tokens 
 ERROR: 0:69: '##' : combined token is invalid 
-ERROR: 5 compilation errors.  No code generated.
+ERROR: 0:82: 'macro expansion' : Too few args in Macro rec
+ERROR: 0:82: '##' : unexpected location 
+ERROR: 0:82: '##' : unexpected location 
+ERROR: 8 compilation errors.  No code generated.
 
 
 Shader version: 450
diff --git a/Test/tokenPaste.vert b/Test/tokenPaste.vert
index 369b7b887..7aa113a29 100644
--- a/Test/tokenPaste.vert
+++ b/Test/tokenPaste.vert
@@ -77,3 +77,6 @@ uniform M_OUTER(argPaste);
 #define M_NEST2(q) int q ## suff
 #define M_OUTER2(p) M_NEST2(p ## 20)
 uniform M_OUTER2(argPaste);
+
+#define rec(x)##
+rec(rec())
\ No newline at end of file
diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h
index f9f4ec50a..d1bce528c 100644
--- a/glslang/Include/revision.h
+++ b/glslang/Include/revision.h
@@ -2,5 +2,5 @@
 // For the version, it uses the latest git tag followed by the number of commits.
 // For the date, it uses the current date (when then script is run).
 
-#define GLSLANG_REVISION "Overload400-PrecQual.1858"
+#define GLSLANG_REVISION "Overload400-PrecQual.1861"
 #define GLSLANG_DATE "28-Feb-2017"
diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp
index ef8e83e17..4da1649eb 100644
--- a/glslang/MachineIndependent/preprocessor/Pp.cpp
+++ b/glslang/MachineIndependent/preprocessor/Pp.cpp
@@ -986,6 +986,8 @@ TPpContext::TokenStream* TPpContext::PrescanMacroArg(TokenStream& arg, TPpToken*
     int token;
     while ((token = scanToken(ppToken)) != tMarkerInput::marker && token != EndOfInput) {
         token = tokenPaste(token, *ppToken);
+        if (token == tMarkerInput::marker || token == EndOfInput)
+            break;
         if (token == PpAtomIdentifier && MacroExpand(ppToken, false, newLineOkay) != 0)
             continue;
         expandedArg->putToken(token, ppToken);
-- 
GitLab