OpenGL: Fix switch with only a default case.

The compiler would produce an `OPCODE_ELSE` with no preceeding `OPCODE_IF`, causing hilarity downstream in the VertexProgram and PixelProgram.

Credit to Dan Sinclair who did all the hard work here.

Bug: None - surfaced when rolling a new version of SPIR-V cross.
Change-Id: I8a937a4d24768dbcc125c3fff834342bd8d0ef29
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40832
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/OpenGL/compiler/OutputASM.cpp b/src/OpenGL/compiler/OutputASM.cpp
index 8d82eca..9e9d885 100644
--- a/src/OpenGL/compiler/OutputASM.cpp
+++ b/src/OpenGL/compiler/OutputASM.cpp
@@ -2058,7 +2058,11 @@
 		// If there's a default case, traverse it here
 		if(defaultIt != sequence.end())
 		{
-			emit(sw::Shader::OPCODE_ELSE);
+			if(nbCases != 0)
+			{
+				emit(sw::Shader::OPCODE_ELSE);
+			}
+
 			for(++defaultIt; defaultIt != sequence.end(); ++defaultIt)
 			{
 				(*defaultIt)->traverse(this);
diff --git a/tests/GLESUnitTests/unittests.cpp b/tests/GLESUnitTests/unittests.cpp
index ee9693e..92987c6 100644
--- a/tests/GLESUnitTests/unittests.cpp
+++ b/tests/GLESUnitTests/unittests.cpp
@@ -2066,6 +2066,18 @@
 		float F (float f) { return G(-m); })");
 }
 
+TEST_F(SwiftShaderTest, SwitchDefaultOnly)
+{
+	checkCompiles(R"(
+		float F (float f) {
+			switch (0u) {
+			default:
+				return -f;
+			}
+			return f;
+		})");
+}
+
 #ifndef EGL_ANGLE_iosurface_client_buffer
 #	define EGL_ANGLE_iosurface_client_buffer 1
 #	define EGL_IOSURFACE_ANGLE 0x3454