Fix error in dumping direct struct indexes.

The parser would become confused over the purported array size
of struct indexes. In reality they were always a single direct
index into a struct, but it would take the object size of the
represented type (EG, a vec4 would have size 4) and deference
out-of-bounds memory.

BUG=434033

Change-Id: I92349aa04e6faadc766cb28c04e28d5f19c4e1ec
Reviewed-on: https://chromium-review.googlesource.com/230530
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/compiler/translator/intermOut.cpp b/src/compiler/translator/intermOut.cpp
index 00780f0..ba885d5 100644
--- a/src/compiler/translator/intermOut.cpp
+++ b/src/compiler/translator/intermOut.cpp
@@ -211,6 +211,36 @@
 
     out << "\n";
 
+    // Special handling for direct indexes. Because constant
+    // unions are not aware they are struct indexes, treat them
+    // here where we have that contextual knowledge.
+    if (node->getOp() == EOpIndexDirectStruct ||
+        node->getOp() == EOpIndexDirectInterfaceBlock)
+    {
+        mDepth++;
+        node->getLeft()->traverse(this);
+        mDepth--;
+
+        TIntermConstantUnion *intermConstantUnion = node->getRight()->getAsConstantUnion();
+        ASSERT(intermConstantUnion);
+
+        OutputTreeText(out, intermConstantUnion, mDepth + 1);
+
+        // The following code finds the field name from the constant union
+        const ConstantUnion *constantUnion = intermConstantUnion->getUnionArrayPointer();
+        const TStructure *structure = node->getLeft()->getType().getStruct();
+        const TInterfaceBlock *interfaceBlock = node->getLeft()->getType().getInterfaceBlock();
+        ASSERT(structure || interfaceBlock);
+
+        const TFieldList &fields = structure ? structure->fields() : interfaceBlock->fields();
+
+        const TField *field = fields[constantUnion->getIConst()];
+
+        out << constantUnion->getIConst() << " (field '" << field->name() << "')";
+
+        return false;
+    }
+
     return true;
 }