From 8e789e8d624297fa7ef12aea7ba9789abc26e0ba Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Thu, 5 Dec 2013 21:51:40 +0000
Subject: [PATCH] Fixed a couple places that missed the error check for
 #else/#elif after #else.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24378 e7fa87d3-cd2b-0410-9028-fcbf551c1848
---
 Test/baseResults/cppNest.vert.out             |  8 ++++-
 Test/baseResults/cppSimple.vert.out           |  2 +-
 Test/cppNest.vert                             | 36 +++++++++++++++++++
 glslang/Include/revision.h                    |  4 +--
 .../MachineIndependent/preprocessor/Pp.cpp    | 27 +++++++-------
 5 files changed, 60 insertions(+), 17 deletions(-)

diff --git a/Test/baseResults/cppNest.vert.out b/Test/baseResults/cppNest.vert.out
index c9406ba31..641e2ce5e 100644
--- a/Test/baseResults/cppNest.vert.out
+++ b/Test/baseResults/cppNest.vert.out
@@ -1,6 +1,12 @@
 cppNest.vert
+ERROR: 0:144: '#elif' : #elif after #else 
+ERROR: 0:152: '#else' : #else after #else 
+ERROR: 0:161: '#elif' : #elif after #else 
+ERROR: 0:169: '#else' : #else after #else 
+ERROR: 4 compilation errors.  No code generated.
 
-0:? Sequence
+
+ERROR: node is still EOpNull!
 0:5  Sequence
 0:5    move second child to first child (float)
 0:5      'sum' (float)
diff --git a/Test/baseResults/cppSimple.vert.out b/Test/baseResults/cppSimple.vert.out
index f41a1e28f..139afdbd9 100644
--- a/Test/baseResults/cppSimple.vert.out
+++ b/Test/baseResults/cppSimple.vert.out
@@ -31,7 +31,7 @@ ERROR: 0:143: '#define' : can't use with built-in names (containing consecutive
 ERROR: 0:144: '#define' : can't use with built-in names (containing consecutive underscores) 
 ERROR: 0:145: '#define' : can't use with built-in names (containing consecutive underscores) 
 ERROR: 0:148: '#else' : unexpected tokens following directive 
-ERROR: 0:149: '#else' : #elif after #else 
+ERROR: 0:149: '#elif' : #elif after #else 
 ERROR: 0:155: '#else' : unexpected tokens following directive 
 ERROR: 0:158: '#else' : #else after #else 
 ERROR: 0:160: '#endif' : unexpected tokens following directive 
diff --git a/Test/cppNest.vert b/Test/cppNest.vert
index a3dc5fa56..c4bcb70e0 100644
--- a/Test/cppNest.vert
+++ b/Test/cppNest.vert
@@ -134,3 +134,39 @@ sum += 600000.0;
         #endif
     #endif
 #endif
+
+// ERROR cases...
+
+#if 0
+int;
+#else
+int;
+#elif 1
+int;
+#endif
+
+#if 0
+int;
+#else
+int;
+#else
+int;
+#endif
+
+#if 0
+    #if 0
+    int;
+    #else
+    int;
+    #elif 1
+    int;
+    #endif
+
+    #if 0
+    int;
+    #else
+    int;
+    #else
+    int;
+    #endif
+#endif
diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h
index 200110ab9..bd4220144 100644
--- a/glslang/Include/revision.h
+++ b/glslang/Include/revision.h
@@ -9,5 +9,5 @@
 // source have to figure out how to create revision.h just to get a build
 // going.  However, if it is not updated, it can be a version behind.
 
-#define GLSLANG_REVISION "24376"
-#define GLSLANG_DATE     "2013/12/05 13:07:56"
+#define GLSLANG_REVISION "24377"
+#define GLSLANG_DATE     "2013/12/05 13:58:16"
diff --git a/glslang/MachineIndependent/preprocessor/Pp.cpp b/glslang/MachineIndependent/preprocessor/Pp.cpp
index 785cbfc11..eccf359d3 100644
--- a/glslang/MachineIndependent/preprocessor/Pp.cpp
+++ b/glslang/MachineIndependent/preprocessor/Pp.cpp
@@ -307,11 +307,14 @@ int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
             --depth;
             --ifdepth;
         } else if (matchelse && depth == 0) {
-            if (atom == elseAtom ) {
+            if (atom == elseAtom) {
+                elseSeen[elsetracker] = true;
                 token = extraTokenCheck(atom, ppToken, currentInput->scan(this, currentInput, ppToken));
                 // found the #else we are looking for
                 break;
             } else if (atom == elifAtom) {
+                if (elseSeen[elsetracker])
+                    parseContext.error(ppToken->loc, "#elif after #else", "#elif", "");
                 /* we decrement ifdepth here, because CPPif will increment
                 * it and we really want to leave it alone */
                 if (ifdepth) {
@@ -330,7 +333,7 @@ int TPpContext::CPPelse(int matchelse, TPpToken* ppToken)
             token = extraTokenCheck(atom, ppToken, currentInput->scan(this, currentInput, ppToken));
         } else if (atom == elifAtom) {
             if (elseSeen[elsetracker])
-                parseContext.error(ppToken->loc, "#elif after #else", "#else", "");
+                parseContext.error(ppToken->loc, "#elif after #else", "#elif", "");
         }
     }
 
@@ -778,20 +781,18 @@ int TPpContext::readCPPline(TPpToken* ppToken)
         if (ppToken->atom == defineAtom) {
             token = CPPdefine(ppToken);
         } else if (ppToken->atom == elseAtom) {
-            if (! elsetracker[elseSeen]) {
-                elsetracker[elseSeen] = true;
-                if (! ifdepth)
-                    parseContext.error(ppToken->loc, "mismatched statements", "#else", "");
-                token = extraTokenCheck(elseAtom, ppToken, currentInput->scan(this, currentInput, ppToken));
-                token = CPPelse(0, ppToken);
-            } else {
-                parseContext.error(ppToken->loc, "#else after a #else", "#else", "");
-                ifdepth = 0;
-                return 0;
-            }
+            if (elsetracker[elseSeen])
+                parseContext.error(ppToken->loc, "#else after #else", "#else", "");
+            elsetracker[elseSeen] = true;
+            if (! ifdepth)
+                parseContext.error(ppToken->loc, "mismatched statements", "#else", "");
+            token = extraTokenCheck(elseAtom, ppToken, currentInput->scan(this, currentInput, ppToken));
+            token = CPPelse(0, ppToken);
         } else if (ppToken->atom == elifAtom) {
             if (! ifdepth)
                 parseContext.error(ppToken->loc, "mismatched statements", "#elif", "");
+            if (elseSeen[elsetracker])
+                parseContext.error(ppToken->loc, "#elif after #else", "#elif", "");
             // this token is really a dont care, but we still need to eat the tokens
             token = currentInput->scan(this, currentInput, ppToken); 
             while (token != '\n')
-- 
GitLab