Only allow zero indexes for gl_FragData when the draw buffers extension is disabled.

TRAC #23509

Signed-off-by: Shannon Woods
Signed-off-by: Nicolas Capens
Authored-by: Jamie Madill
diff --git a/src/compiler/ParseHelper.cpp b/src/compiler/ParseHelper.cpp
index 1bab3ce..aff7641 100644
--- a/src/compiler/ParseHelper.cpp
+++ b/src/compiler/ParseHelper.cpp
@@ -964,6 +964,19 @@
     return (iter != extbehavior.end());
 }
 
+bool TParseContext::isExtensionEnabled(const char* extension) const
+{
+    const TExtensionBehavior& extbehavior = extensionBehavior();
+    auto iter = extbehavior.find(extension);
+
+    if (iter == extbehavior.end())
+    {
+        return false;
+    }
+
+    return (iter->second == EBhEnable || iter->second == EBhRequire);
+}
+
 void TParseContext::handleExtensionDirective(const TSourceLoc& loc, const char* extName, const char* behavior)
 {
     pp::SourceLocation srcLoc;
@@ -2100,6 +2113,12 @@
                     recover();
                     index = baseExpression->getType().getArraySize() - 1;
                 }
+                else if (baseExpression->getQualifier() == EvqFragData && index > 0 && !isExtensionEnabled("GL_EXT_draw_buffers"))
+                {
+                    error(location, "", "[", "array indexes for gl_FragData must be zero when GL_EXT_draw_buffers is disabled");
+                    recover();
+                    index = 0;
+                }
             }
             else if ((baseExpression->isVector() || baseExpression->isMatrix()) && baseExpression->getType().getNominalSize() <= index)
             {
diff --git a/src/compiler/ParseHelper.h b/src/compiler/ParseHelper.h
index 79abe43..51951e6 100644
--- a/src/compiler/ParseHelper.h
+++ b/src/compiler/ParseHelper.h
@@ -111,6 +111,7 @@
     const TPragma& pragma() const { return directiveHandler.pragma(); }
     const TExtensionBehavior& extensionBehavior() const { return directiveHandler.extensionBehavior(); }
     bool supportsExtension(const char* extension);
+    bool isExtensionEnabled(const char* extension) const;
     void handleExtensionDirective(const TSourceLoc& loc, const char* extName, const char* behavior);
     void handlePragmaDirective(const TSourceLoc& loc, const char* name, const char* value);