From 414f735443de27653f8b385dc279c3a1a00d06dd Mon Sep 17 00:00:00 2001
From: John Kessenich <cepheus@frii.com>
Date: Wed, 27 Jul 2016 14:43:01 -0600
Subject: [PATCH] Front-end: Fix issue #409, check for implicitly-sized binding
 arrays.

---
 Test/420.vert                               | 4 +++-
 Test/baseResults/420.vert.out               | 3 +++
 glslang/Include/revision.h                  | 2 +-
 glslang/MachineIndependent/ParseHelper.cpp  | 9 +++++++--
 glslang/MachineIndependent/linkValidate.cpp | 2 +-
 5 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/Test/420.vert b/Test/420.vert
index 49035ea47..ab28140e5 100644
--- a/Test/420.vert
+++ b/Test/420.vert
@@ -156,4 +156,6 @@ void qlod()
 
     levels = textureQueryLevels(samp1D);   // ERROR, not until 430
     levels = textureQueryLevels(samp1Ds);  // ERROR, not until 430
-}
\ No newline at end of file
+}
+
+layout(binding=0) writeonly uniform image1D badArray[];
diff --git a/Test/baseResults/420.vert.out b/Test/baseResults/420.vert.out
index 0f5110cbd..a234970c5 100644
--- a/Test/baseResults/420.vert.out
+++ b/Test/baseResults/420.vert.out
@@ -51,6 +51,7 @@ ERROR: 0:157: 'textureQueryLevels' : no matching overloaded function found
 ERROR: 0:157: 'assign' :  cannot convert from 'const float' to 'temp int'
 ERROR: 0:158: 'textureQueryLevels' : no matching overloaded function found 
 ERROR: 0:158: 'assign' :  cannot convert from 'const float' to 'temp int'
+WARNING: 0:161: '[]' : assuming array size of one for compile-time checking of binding numbers for implicitly-sized array 
 ERROR: 50 compilation errors.  No code generated.
 
 
@@ -299,6 +300,7 @@ ERROR: node is still EOpNull!
 0:?     'offcheckI' (layout(column_major shared ) uniform block{layout(column_major shared offset=16 ) uniform int foo})
 0:?     'samp1D' (uniform sampler1D)
 0:?     'samp1Ds' (uniform sampler1DShadow)
+0:?     'badArray' (layout(binding=0 ) writeonly uniform implicitly-sized array of image1D)
 0:?     'gl_VertexID' (gl_VertexId int VertexId)
 0:?     'gl_InstanceID' (gl_InstanceId int InstanceId)
 
@@ -551,6 +553,7 @@ ERROR: node is still EOpNull!
 0:?     'offcheckI' (layout(column_major shared ) uniform block{layout(column_major shared offset=16 ) uniform int foo})
 0:?     'samp1D' (uniform sampler1D)
 0:?     'samp1Ds' (uniform sampler1DShadow)
+0:?     'badArray' (layout(binding=0 ) writeonly uniform 1-element array of image1D)
 0:?     'gl_VertexID' (gl_VertexId int VertexId)
 0:?     'gl_InstanceID' (gl_InstanceId int InstanceId)
 
diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h
index 55f452749..c3344c1ca 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 "SPIRV99.1351"
+#define GLSLANG_REVISION "SPIRV99.1353"
 #define GLSLANG_DATE "27-Jul-2016"
diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp
index 274f919c9..173969a04 100644
--- a/glslang/MachineIndependent/ParseHelper.cpp
+++ b/glslang/MachineIndependent/ParseHelper.cpp
@@ -4544,8 +4544,13 @@ void TParseContext::layoutTypeCheck(const TSourceLoc& loc, const TType& type)
             error(loc, "requires block, or sampler/image, or atomic-counter type", "binding", "");
         if (type.getBasicType() == EbtSampler) {
             int lastBinding = qualifier.layoutBinding;
-            if (type.isArray())
-                lastBinding += type.getCumulativeArraySize();
+            if (type.isArray()) {
+                if (type.isImplicitlySizedArray()) {
+                    lastBinding += 1;
+                    warn(loc, "assuming array size of one for compile-time checking of binding numbers for implicitly-sized array", "[]", "");
+                } else
+                    lastBinding += type.getCumulativeArraySize();
+            }
             if (lastBinding >= resources.maxCombinedTextureImageUnits)
                 error(loc, "sampler binding not less than gl_MaxCombinedTextureImageUnits", "binding", type.isArray() ? "(using array)" : "");
         }
diff --git a/glslang/MachineIndependent/linkValidate.cpp b/glslang/MachineIndependent/linkValidate.cpp
index af21fbbab..0bc1d918f 100644
--- a/glslang/MachineIndependent/linkValidate.cpp
+++ b/glslang/MachineIndependent/linkValidate.cpp
@@ -651,7 +651,7 @@ int TIntermediate::addUsedLocation(const TQualifier& qualifier, const TType& typ
 
     int size;
     if (qualifier.isUniformOrBuffer()) {
-        if (type.isArray())
+        if (type.isExplicitlySizedArray())
             size = type.getCumulativeArraySize();
         else
             size = 1;
-- 
GitLab