Fix edge case scoped structures name conflict.

Structures with names ending in "_#" such as "_0" could conflict
with the internally rewritten scoped structures. Fix this by using
a prepending rule instead of appending.

Also includes a test, and fixes a WebGL test in Firefox. (Chrome is
not affected because of the variable hashing step.)

BUG=angle:618

Change-Id: I3d441f1de268b6d7e74a0834b43e889b7bfe578c
Reviewed-on: https://chromium-review.googlesource.com/201468
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <nicolascapens@chromium.org>
diff --git a/tests/angle_tests/GLSLStructTest.cpp b/tests/angle_tests/GLSLStructTest.cpp
new file mode 100644
index 0000000..318f41d
--- /dev/null
+++ b/tests/angle_tests/GLSLStructTest.cpp
@@ -0,0 +1,56 @@
+#include "ANGLETest.h"
+
+class GLSLStructTest : public ANGLETest
+{
+protected:
+    GLSLStructTest()
+    {
+        setWindowWidth(128);
+        setWindowHeight(128);
+        setConfigRedBits(8);
+        setConfigGreenBits(8);
+        setConfigBlueBits(8);
+        setConfigAlphaBits(8);
+    }
+};
+
+TEST_F(GLSLStructTest, scoped_structs_bug)
+{
+    const std::string vertexShaderSource = SHADER_SOURCE
+    (
+        attribute vec4 inputAttribute;
+        void main()
+        {
+            gl_Position = inputAttribute;
+        }
+    );
+
+    const std::string fragmentShaderSource = SHADER_SOURCE
+    (
+        precision mediump float;
+
+        struct T_0
+        {
+            float f;
+        };
+
+        void main()
+        {
+            gl_FragColor = vec4(1, 0, 0, 1);
+
+            struct T
+            {
+                vec2 v;
+            };
+
+            T_0 a;
+            T b;
+
+            gl_FragColor.a += a.f;
+            gl_FragColor.a += b.v.x;
+        }
+    );
+
+    GLuint program = compileProgram(vertexShaderSource, fragmentShaderSource);
+    EXPECT_NE(0u, program);
+}