--- /dev/null
+#!amber
+
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# A test for a bug found by GraphicsFuzz.
+
+# Short description: A pair of fragment shaders that both render red
+
+# The test passes because both shaders are equivalent; we check that both shaders
+# render the same image. Both shaders manipulate a binary search tree and should render red.
+# The variant shader has a redundant loop that should not affect the rendered image.
+
+SHADER vertex reference_vertex_shader PASSTHROUGH
+
+# reference_fragment_shader is derived from the following GLSL:
+# #version 310 es
+# precision highp float;
+#
+# precision highp int;
+#
+# layout(location = 0) out vec4 _GLF_color;
+#
+# struct BST
+# {
+# int data;
+# int leftIndex;
+# int rightIndex;
+# };
+#
+# BST tree[10];
+#
+# void makeTreeNode(inout BST node, int data)
+# {
+# node.data = data;
+# node.leftIndex = -1;
+# node.rightIndex = -1;
+# }
+# void insert(int treeIndex, int data)
+# {
+# int baseIndex = 0;
+# while (baseIndex <= treeIndex)
+# {
+# if (data <= tree[baseIndex].data)
+# {
+# if (tree[baseIndex].leftIndex == -1)
+# {
+# tree[baseIndex].leftIndex = treeIndex;
+# makeTreeNode(tree[treeIndex], data);
+# return;
+# }
+# else
+# {
+# baseIndex = tree[baseIndex].leftIndex;
+# continue;
+# }
+# }
+# else
+# {
+# if (tree[baseIndex].rightIndex == -1)
+# {
+# tree[baseIndex].rightIndex = treeIndex;
+# makeTreeNode(tree[treeIndex], data);
+# return;
+# }
+# else
+# {
+# baseIndex = tree[baseIndex].rightIndex;
+# continue;
+# }
+# }
+# }
+# }
+# int search(int target)
+# {
+# BST currentNode;
+# int index = 0;
+# while (index != -1)
+# {
+# currentNode = tree[index];
+# if (currentNode.data == target)
+# {
+# return target;
+# }
+# index = target > currentNode.data ? currentNode.rightIndex : currentNode.leftIndex;
+# }
+# return -1;
+# }
+# void main()
+# {
+# int treeIndex = 0;
+# makeTreeNode(tree[0], 9);
+# treeIndex++;
+# insert(treeIndex, 5);
+# treeIndex++;
+# insert(treeIndex, 12);
+# treeIndex++;
+# insert(treeIndex, 15);
+# treeIndex++;
+# insert(treeIndex, 7);
+# treeIndex++;
+# insert(treeIndex, 8);
+# treeIndex++;
+# insert(treeIndex, 2);
+# treeIndex++;
+# insert(treeIndex, 6);
+# treeIndex++;
+# insert(treeIndex, 17);
+# treeIndex++;
+# insert(treeIndex, 13);
+# int count = 0;
+# for (
+# int i = 0;
+# i < 20;
+# i++)
+# {
+# int result = search(i);
+# switch (i)
+# {
+# case 9:
+# case 5:
+# case 12:
+# case 15:
+# case 7:
+# case 8:
+# case 2:
+# case 6:
+# case 17:
+# case 13:
+# if (result == i)
+# {
+# count++;
+# }
+# break;
+# default:
+# if (result == -1)
+# {
+# count++;
+# }
+# break;
+# }
+# }
+# if (count == 20)
+# {
+# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
+# }
+# else
+# {
+# _GLF_color = vec4(0.0, 0.0, 1.0, 1.0);
+# }
+# }
+SHADER fragment reference_fragment_shader SPIRV-ASM
+; SPIR-V
+; Version: 1.0
+; Generator: Khronos Glslang Reference Front End; 8
+; Bound: 260
+; Schema: 0
+ OpCapability Shader
+ %1 = OpExtInstImport "GLSL.std.450"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %4 "main" %254
+ OpExecutionMode %4 OriginUpperLeft
+ OpSource ESSL 310
+ OpName %4 "main"
+ OpName %7 "BST"
+ OpMemberName %7 0 "data"
+ OpMemberName %7 1 "leftIndex"
+ OpMemberName %7 2 "rightIndex"
+ OpName %13 "makeTreeNode(struct-BST-i1-i1-i11;i1;"
+ OpName %11 "node"
+ OpName %12 "data"
+ OpName %18 "insert(i1;i1;"
+ OpName %16 "treeIndex"
+ OpName %17 "data"
+ OpName %22 "search(i1;"
+ OpName %21 "target"
+ OpName %32 "baseIndex"
+ OpName %47 "tree"
+ OpName %65 "param"
+ OpName %69 "param"
+ OpName %91 "param"
+ OpName %94 "param"
+ OpName %105 "index"
+ OpName %113 "currentNode"
+ OpName %140 "treeIndex"
+ OpName %142 "param"
+ OpName %145 "param"
+ OpName %152 "param"
+ OpName %154 "param"
+ OpName %159 "param"
+ OpName %161 "param"
+ OpName %166 "param"
+ OpName %168 "param"
+ OpName %173 "param"
+ OpName %175 "param"
+ OpName %180 "param"
+ OpName %182 "param"
+ OpName %186 "param"
+ OpName %188 "param"
+ OpName %193 "param"
+ OpName %195 "param"
+ OpName %200 "param"
+ OpName %202 "param"
+ OpName %207 "param"
+ OpName %209 "param"
+ OpName %211 "count"
+ OpName %212 "i"
+ OpName %221 "result"
+ OpName %222 "param"
+ OpName %254 "_GLF_color"
+ OpDecorate %254 Location 0
+ %2 = OpTypeVoid
+ %3 = OpTypeFunction %2
+ %6 = OpTypeInt 32 1
+ %7 = OpTypeStruct %6 %6 %6
+ %8 = OpTypePointer Function %7
+ %9 = OpTypePointer Function %6
+ %10 = OpTypeFunction %2 %8 %9
+ %15 = OpTypeFunction %2 %9 %9
+ %20 = OpTypeFunction %6 %9
+ %24 = OpConstant %6 0
+ %27 = OpConstant %6 1
+ %28 = OpConstant %6 -1
+ %30 = OpConstant %6 2
+ %40 = OpTypeBool
+ %43 = OpTypeInt 32 0
+ %44 = OpConstant %43 10
+ %45 = OpTypeArray %7 %44
+ %46 = OpTypePointer Private %45
+ %47 = OpVariable %46 Private
+ %49 = OpTypePointer Private %6
+ %66 = OpTypePointer Private %7
+ %141 = OpConstant %6 9
+ %151 = OpConstant %6 5
+ %158 = OpConstant %6 12
+ %165 = OpConstant %6 15
+ %172 = OpConstant %6 7
+ %179 = OpConstant %6 8
+ %192 = OpConstant %6 6
+ %199 = OpConstant %6 17
+ %206 = OpConstant %6 13
+ %219 = OpConstant %6 20
+ %251 = OpTypeFloat 32
+ %252 = OpTypeVector %251 4
+ %253 = OpTypePointer Output %252
+ %254 = OpVariable %253 Output
+ %255 = OpConstant %251 1
+ %256 = OpConstant %251 0
+ %257 = OpConstantComposite %252 %255 %256 %256 %255
+ %259 = OpConstantComposite %252 %256 %256 %255 %255
+ %4 = OpFunction %2 None %3
+ %5 = OpLabel
+ %140 = OpVariable %9 Function
+ %142 = OpVariable %8 Function
+ %145 = OpVariable %9 Function
+ %152 = OpVariable %9 Function
+ %154 = OpVariable %9 Function
+ %159 = OpVariable %9 Function
+ %161 = OpVariable %9 Function
+ %166 = OpVariable %9 Function
+ %168 = OpVariable %9 Function
+ %173 = OpVariable %9 Function
+ %175 = OpVariable %9 Function
+ %180 = OpVariable %9 Function
+ %182 = OpVariable %9 Function
+ %186 = OpVariable %9 Function
+ %188 = OpVariable %9 Function
+ %193 = OpVariable %9 Function
+ %195 = OpVariable %9 Function
+ %200 = OpVariable %9 Function
+ %202 = OpVariable %9 Function
+ %207 = OpVariable %9 Function
+ %209 = OpVariable %9 Function
+ %211 = OpVariable %9 Function
+ %212 = OpVariable %9 Function
+ %221 = OpVariable %9 Function
+ %222 = OpVariable %9 Function
+ OpStore %140 %24
+ %143 = OpAccessChain %66 %47 %24
+ %144 = OpLoad %7 %143
+ OpStore %142 %144
+ OpStore %145 %141
+ %146 = OpFunctionCall %2 %13 %142 %145
+ %147 = OpLoad %7 %142
+ %148 = OpAccessChain %66 %47 %24
+ OpStore %148 %147
+ %149 = OpLoad %6 %140
+ %150 = OpIAdd %6 %149 %27
+ OpStore %140 %150
+ %153 = OpLoad %6 %140
+ OpStore %152 %153
+ OpStore %154 %151
+ %155 = OpFunctionCall %2 %18 %152 %154
+ %156 = OpLoad %6 %140
+ %157 = OpIAdd %6 %156 %27
+ OpStore %140 %157
+ %160 = OpLoad %6 %140
+ OpStore %159 %160
+ OpStore %161 %158
+ %162 = OpFunctionCall %2 %18 %159 %161
+ %163 = OpLoad %6 %140
+ %164 = OpIAdd %6 %163 %27
+ OpStore %140 %164
+ %167 = OpLoad %6 %140
+ OpStore %166 %167
+ OpStore %168 %165
+ %169 = OpFunctionCall %2 %18 %166 %168
+ %170 = OpLoad %6 %140
+ %171 = OpIAdd %6 %170 %27
+ OpStore %140 %171
+ %174 = OpLoad %6 %140
+ OpStore %173 %174
+ OpStore %175 %172
+ %176 = OpFunctionCall %2 %18 %173 %175
+ %177 = OpLoad %6 %140
+ %178 = OpIAdd %6 %177 %27
+ OpStore %140 %178
+ %181 = OpLoad %6 %140
+ OpStore %180 %181
+ OpStore %182 %179
+ %183 = OpFunctionCall %2 %18 %180 %182
+ %184 = OpLoad %6 %140
+ %185 = OpIAdd %6 %184 %27
+ OpStore %140 %185
+ %187 = OpLoad %6 %140
+ OpStore %186 %187
+ OpStore %188 %30
+ %189 = OpFunctionCall %2 %18 %186 %188
+ %190 = OpLoad %6 %140
+ %191 = OpIAdd %6 %190 %27
+ OpStore %140 %191
+ %194 = OpLoad %6 %140
+ OpStore %193 %194
+ OpStore %195 %192
+ %196 = OpFunctionCall %2 %18 %193 %195
+ %197 = OpLoad %6 %140
+ %198 = OpIAdd %6 %197 %27
+ OpStore %140 %198
+ %201 = OpLoad %6 %140
+ OpStore %200 %201
+ OpStore %202 %199
+ %203 = OpFunctionCall %2 %18 %200 %202
+ %204 = OpLoad %6 %140
+ %205 = OpIAdd %6 %204 %27
+ OpStore %140 %205
+ %208 = OpLoad %6 %140
+ OpStore %207 %208
+ OpStore %209 %206
+ %210 = OpFunctionCall %2 %18 %207 %209
+ OpStore %211 %24
+ OpStore %212 %24
+ OpBranch %213
+ %213 = OpLabel
+ OpLoopMerge %215 %216 None
+ OpBranch %217
+ %217 = OpLabel
+ %218 = OpLoad %6 %212
+ %220 = OpSLessThan %40 %218 %219
+ OpBranchConditional %220 %214 %215
+ %214 = OpLabel
+ %223 = OpLoad %6 %212
+ OpStore %222 %223
+ %224 = OpFunctionCall %6 %22 %222
+ OpStore %221 %224
+ %225 = OpLoad %6 %212
+ OpSelectionMerge %228 None
+ OpSwitch %225 %227 9 %226 5 %226 12 %226 15 %226 7 %226 8 %226 2 %226 6 %226 17 %226 13 %226
+ %227 = OpLabel
+ %237 = OpLoad %6 %221
+ %238 = OpIEqual %40 %237 %28
+ OpSelectionMerge %240 None
+ OpBranchConditional %238 %239 %240
+ %239 = OpLabel
+ %241 = OpLoad %6 %211
+ %242 = OpIAdd %6 %241 %27
+ OpStore %211 %242
+ OpBranch %240
+ %240 = OpLabel
+ OpBranch %228
+ %226 = OpLabel
+ %229 = OpLoad %6 %221
+ %230 = OpLoad %6 %212
+ %231 = OpIEqual %40 %229 %230
+ OpSelectionMerge %233 None
+ OpBranchConditional %231 %232 %233
+ %232 = OpLabel
+ %234 = OpLoad %6 %211
+ %235 = OpIAdd %6 %234 %27
+ OpStore %211 %235
+ OpBranch %233
+ %233 = OpLabel
+ OpBranch %228
+ %228 = OpLabel
+ OpBranch %216
+ %216 = OpLabel
+ %245 = OpLoad %6 %212
+ %246 = OpIAdd %6 %245 %27
+ OpStore %212 %246
+ OpBranch %213
+ %215 = OpLabel
+ %247 = OpLoad %6 %211
+ %248 = OpIEqual %40 %247 %219
+ OpSelectionMerge %250 None
+ OpBranchConditional %248 %249 %258
+ %249 = OpLabel
+ OpStore %254 %257
+ OpBranch %250
+ %258 = OpLabel
+ OpStore %254 %259
+ OpBranch %250
+ %250 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %13 = OpFunction %2 None %10
+ %11 = OpFunctionParameter %8
+ %12 = OpFunctionParameter %9
+ %14 = OpLabel
+ %25 = OpLoad %6 %12
+ %26 = OpAccessChain %9 %11 %24
+ OpStore %26 %25
+ %29 = OpAccessChain %9 %11 %27
+ OpStore %29 %28
+ %31 = OpAccessChain %9 %11 %30
+ OpStore %31 %28
+ OpReturn
+ OpFunctionEnd
+ %18 = OpFunction %2 None %15
+ %16 = OpFunctionParameter %9
+ %17 = OpFunctionParameter %9
+ %19 = OpLabel
+ %32 = OpVariable %9 Function
+ %65 = OpVariable %8 Function
+ %69 = OpVariable %9 Function
+ %91 = OpVariable %8 Function
+ %94 = OpVariable %9 Function
+ OpStore %32 %24
+ OpBranch %33
+ %33 = OpLabel
+ OpLoopMerge %35 %36 None
+ OpBranch %37
+ %37 = OpLabel
+ %38 = OpLoad %6 %32
+ %39 = OpLoad %6 %16
+ %41 = OpSLessThanEqual %40 %38 %39
+ OpBranchConditional %41 %34 %35
+ %34 = OpLabel
+ %42 = OpLoad %6 %17
+ %48 = OpLoad %6 %32
+ %50 = OpAccessChain %49 %47 %48 %24
+ %51 = OpLoad %6 %50
+ %52 = OpSLessThanEqual %40 %42 %51
+ OpSelectionMerge %54 None
+ OpBranchConditional %52 %53 %80
+ %53 = OpLabel
+ %55 = OpLoad %6 %32
+ %56 = OpAccessChain %49 %47 %55 %27
+ %57 = OpLoad %6 %56
+ %58 = OpIEqual %40 %57 %28
+ OpSelectionMerge %60 None
+ OpBranchConditional %58 %59 %75
+ %59 = OpLabel
+ %61 = OpLoad %6 %32
+ %62 = OpLoad %6 %16
+ %63 = OpAccessChain %49 %47 %61 %27
+ OpStore %63 %62
+ %64 = OpLoad %6 %16
+ %67 = OpAccessChain %66 %47 %64
+ %68 = OpLoad %7 %67
+ OpStore %65 %68
+ %70 = OpLoad %6 %17
+ OpStore %69 %70
+ %71 = OpFunctionCall %2 %13 %65 %69
+ %72 = OpLoad %7 %65
+ %73 = OpAccessChain %66 %47 %64
+ OpStore %73 %72
+ OpReturn
+ %75 = OpLabel
+ %76 = OpLoad %6 %32
+ %77 = OpAccessChain %49 %47 %76 %27
+ %78 = OpLoad %6 %77
+ OpStore %32 %78
+ OpBranch %36
+ %60 = OpLabel
+ OpUnreachable
+ %80 = OpLabel
+ %81 = OpLoad %6 %32
+ %82 = OpAccessChain %49 %47 %81 %30
+ %83 = OpLoad %6 %82
+ %84 = OpIEqual %40 %83 %28
+ OpSelectionMerge %86 None
+ OpBranchConditional %84 %85 %100
+ %85 = OpLabel
+ %87 = OpLoad %6 %32
+ %88 = OpLoad %6 %16
+ %89 = OpAccessChain %49 %47 %87 %30
+ OpStore %89 %88
+ %90 = OpLoad %6 %16
+ %92 = OpAccessChain %66 %47 %90
+ %93 = OpLoad %7 %92
+ OpStore %91 %93
+ %95 = OpLoad %6 %17
+ OpStore %94 %95
+ %96 = OpFunctionCall %2 %13 %91 %94
+ %97 = OpLoad %7 %91
+ %98 = OpAccessChain %66 %47 %90
+ OpStore %98 %97
+ OpReturn
+ %100 = OpLabel
+ %101 = OpLoad %6 %32
+ %102 = OpAccessChain %49 %47 %101 %30
+ %103 = OpLoad %6 %102
+ OpStore %32 %103
+ OpBranch %36
+ %86 = OpLabel
+ OpUnreachable
+ %54 = OpLabel
+ OpUnreachable
+ %36 = OpLabel
+ OpBranch %33
+ %35 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %22 = OpFunction %6 None %20
+ %21 = OpFunctionParameter %9
+ %23 = OpLabel
+ %105 = OpVariable %9 Function
+ %113 = OpVariable %8 Function
+ %129 = OpVariable %9 Function
+ OpStore %105 %24
+ OpBranch %106
+ %106 = OpLabel
+ OpLoopMerge %108 %109 None
+ OpBranch %110
+ %110 = OpLabel
+ %111 = OpLoad %6 %105
+ %112 = OpINotEqual %40 %111 %28
+ OpBranchConditional %112 %107 %108
+ %107 = OpLabel
+ %114 = OpLoad %6 %105
+ %115 = OpAccessChain %66 %47 %114
+ %116 = OpLoad %7 %115
+ OpStore %113 %116
+ %117 = OpAccessChain %9 %113 %24
+ %118 = OpLoad %6 %117
+ %119 = OpLoad %6 %21
+ %120 = OpIEqual %40 %118 %119
+ OpSelectionMerge %122 None
+ OpBranchConditional %120 %121 %122
+ %121 = OpLabel
+ %123 = OpLoad %6 %21
+ OpReturnValue %123
+ %122 = OpLabel
+ %125 = OpLoad %6 %21
+ %126 = OpAccessChain %9 %113 %24
+ %127 = OpLoad %6 %126
+ %128 = OpSGreaterThan %40 %125 %127
+ OpSelectionMerge %131 None
+ OpBranchConditional %128 %130 %134
+ %130 = OpLabel
+ %132 = OpAccessChain %9 %113 %30
+ %133 = OpLoad %6 %132
+ OpStore %129 %133
+ OpBranch %131
+ %134 = OpLabel
+ %135 = OpAccessChain %9 %113 %27
+ %136 = OpLoad %6 %135
+ OpStore %129 %136
+ OpBranch %131
+ %131 = OpLabel
+ %137 = OpLoad %6 %129
+ OpStore %105 %137
+ OpBranch %109
+ %109 = OpLabel
+ OpBranch %106
+ %108 = OpLabel
+ OpReturnValue %28
+ OpFunctionEnd
+END
+
+
+BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
+
+PIPELINE graphics reference_pipeline
+ ATTACH reference_vertex_shader
+ ATTACH reference_fragment_shader
+ FRAMEBUFFER_SIZE 256 256
+ BIND BUFFER reference_framebuffer AS color LOCATION 0
+END
+CLEAR_COLOR reference_pipeline 0 0 0 255
+
+CLEAR reference_pipeline
+RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
+
+
+SHADER vertex variant_vertex_shader PASSTHROUGH
+
+# variant_fragment_shader is derived from the following GLSL:
+# #version 310 es
+# precision highp float;
+#
+# precision highp int;
+#
+# layout(location = 0) out vec4 _GLF_color;
+#
+# struct BST
+# {
+# int data;
+# int leftIndex;
+# int rightIndex;
+# };
+#
+# BST tree[10];
+#
+#
+# // Start of additional globals and functions just in the variant shader.
+#
+# layout(set = 0, binding = 0) uniform buf0 {
+# // Always (0.0, 1.0).
+# vec2 injectionSwitch;
+# };
+#
+# struct QuicksortObject
+# {
+# int numbers[10];
+# };
+#
+# QuicksortObject obj;
+#
+# // "a" is always 2.
+# // Thus, always returns 2.
+# int identity(int a)
+# {
+# obj.numbers[a] = a;
+# return obj.numbers[2];
+# }
+# // End of additional globals and functions just in the variant shader.
+#
+# void makeTreeNode(inout BST node, int data)
+# {
+# node.data = data;
+# node.leftIndex = -1;
+# node.rightIndex = -1;
+# }
+# void insert(int treeIndex, int data)
+# {
+# int baseIndex = 0;
+# while (baseIndex <= treeIndex)
+# {
+# if (data <= tree[baseIndex].data)
+# {
+# if (tree[baseIndex].leftIndex == -1)
+# {
+# tree[baseIndex].leftIndex = treeIndex;
+# makeTreeNode(tree[treeIndex], data);
+# return;
+# }
+# else
+# {
+# baseIndex = tree[baseIndex].leftIndex;
+# continue;
+# }
+# }
+# else
+# {
+# if (tree[baseIndex].rightIndex == -1)
+# {
+# tree[baseIndex].rightIndex = treeIndex;
+# makeTreeNode(tree[treeIndex], data);
+# return;
+# }
+# else
+# {
+# baseIndex = tree[baseIndex].rightIndex;
+# continue;
+# }
+# }
+# }
+# }
+# int search(int target)
+# {
+# BST currentNode;
+# int index = 0;
+# while (index != -1)
+# {
+# currentNode = tree[index];
+# if (currentNode.data == target)
+# {
+# return target;
+# }
+# index = target > currentNode.data ? currentNode.rightIndex : currentNode.leftIndex;
+# }
+# return -1;
+# }
+# void main()
+# {
+# int treeIndex = 0;
+# makeTreeNode(tree[0], 9);
+# treeIndex++;
+# insert(treeIndex, 5);
+# treeIndex++;
+# insert(treeIndex, 12);
+# treeIndex++;
+# insert(treeIndex, 15);
+# treeIndex++;
+# insert(treeIndex, 7);
+# treeIndex++;
+# insert(treeIndex, 8);
+# treeIndex++;
+# insert(treeIndex, 2);
+# treeIndex++;
+# insert(treeIndex, 6);
+# treeIndex++;
+# insert(treeIndex, 17);
+# treeIndex++;
+# insert(treeIndex, 13);
+#
+#
+# // Start of code that does nothing.
+#
+# // The following code essentially just stores the value 2 in "pp" and then checks that pp == 2
+# // but it does so by writing 2 into the global struct "obj" and then reading it back.
+# int pp = 0;
+# int looplimiter0 = 0;
+#
+# // This loop iterates 2 times because of "looplimiter0".
+# for (
+# int i = 0;
+# i < 10000;
+# i++)
+# {
+# // "injectionSwitch.y" is 1.0.
+# if (looplimiter0 >= int(injectionSwitch.y))
+# {
+# // "identity(2)" returns 2, so "pp" becomes 2.
+# pp = identity(1 + int(injectionSwitch.y));
+# break;
+# }
+# looplimiter0++;
+# }
+# // "pp" is always 2.
+# if (pp != 2)
+# {
+# return;
+# }
+#
+# // End of code that does nothing.
+#
+# int count = 0;
+# for (
+# int i = 0;
+# i < 20;
+# i++)
+# {
+# int result = search(i);
+# switch (i)
+# {
+# case 9:
+# case 5:
+# case 12:
+# case 15:
+# case 7:
+# case 8:
+# case 2:
+# case 6:
+# case 17:
+# case 13:
+# if (result == i)
+# {
+# count++;
+# }
+# break;
+# default:
+# if (result == -1)
+# {
+# count++;
+# }
+# break;
+# }
+# }
+# if (count == 20)
+# {
+# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
+# }
+# else
+# {
+# _GLF_color = vec4(0.0, 0.0, 1.0, 1.0);
+# }
+# }
+SHADER fragment variant_fragment_shader SPIRV-ASM
+; SPIR-V
+; Version: 1.0
+; Generator: Khronos Glslang Reference Front End; 8
+; Bound: 314
+; Schema: 0
+ OpCapability Shader
+ %1 = OpExtInstImport "GLSL.std.450"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %4 "main" %308
+ OpExecutionMode %4 OriginUpperLeft
+ OpSource ESSL 310
+ OpName %4 "main"
+ OpName %10 "identity(i1;"
+ OpName %9 "a"
+ OpName %12 "BST"
+ OpMemberName %12 0 "data"
+ OpMemberName %12 1 "leftIndex"
+ OpMemberName %12 2 "rightIndex"
+ OpName %17 "makeTreeNode(struct-BST-i1-i1-i11;i1;"
+ OpName %15 "node"
+ OpName %16 "data"
+ OpName %22 "insert(i1;i1;"
+ OpName %20 "treeIndex"
+ OpName %21 "data"
+ OpName %25 "search(i1;"
+ OpName %24 "target"
+ OpName %30 "QuicksortObject"
+ OpMemberName %30 0 "numbers"
+ OpName %32 "obj"
+ OpName %49 "baseIndex"
+ OpName %62 "tree"
+ OpName %79 "param"
+ OpName %83 "param"
+ OpName %105 "param"
+ OpName %108 "param"
+ OpName %119 "index"
+ OpName %127 "currentNode"
+ OpName %154 "treeIndex"
+ OpName %156 "param"
+ OpName %159 "param"
+ OpName %166 "param"
+ OpName %168 "param"
+ OpName %173 "param"
+ OpName %175 "param"
+ OpName %180 "param"
+ OpName %182 "param"
+ OpName %187 "param"
+ OpName %189 "param"
+ OpName %194 "param"
+ OpName %196 "param"
+ OpName %200 "param"
+ OpName %202 "param"
+ OpName %207 "param"
+ OpName %209 "param"
+ OpName %214 "param"
+ OpName %216 "param"
+ OpName %221 "param"
+ OpName %223 "param"
+ OpName %225 "pp"
+ OpName %226 "looplimiter0"
+ OpName %227 "i"
+ OpName %239 "buf0"
+ OpMemberName %239 0 "injectionSwitch"
+ OpName %241 ""
+ OpName %254 "param"
+ OpName %266 "count"
+ OpName %267 "i"
+ OpName %276 "result"
+ OpName %277 "param"
+ OpName %308 "_GLF_color"
+ OpMemberDecorate %239 0 Offset 0
+ OpDecorate %239 Block
+ OpDecorate %241 DescriptorSet 0
+ OpDecorate %241 Binding 0
+ OpDecorate %308 Location 0
+ %2 = OpTypeVoid
+ %3 = OpTypeFunction %2
+ %6 = OpTypeInt 32 1
+ %7 = OpTypePointer Function %6
+ %8 = OpTypeFunction %6 %7
+ %12 = OpTypeStruct %6 %6 %6
+ %13 = OpTypePointer Function %12
+ %14 = OpTypeFunction %2 %13 %7
+ %19 = OpTypeFunction %2 %7 %7
+ %27 = OpTypeInt 32 0
+ %28 = OpConstant %27 10
+ %29 = OpTypeArray %6 %28
+ %30 = OpTypeStruct %29
+ %31 = OpTypePointer Private %30
+ %32 = OpVariable %31 Private
+ %33 = OpConstant %6 0
+ %36 = OpTypePointer Private %6
+ %38 = OpConstant %6 2
+ %45 = OpConstant %6 1
+ %46 = OpConstant %6 -1
+ %57 = OpTypeBool
+ %60 = OpTypeArray %12 %28
+ %61 = OpTypePointer Private %60
+ %62 = OpVariable %61 Private
+ %80 = OpTypePointer Private %12
+ %155 = OpConstant %6 9
+ %165 = OpConstant %6 5
+ %172 = OpConstant %6 12
+ %179 = OpConstant %6 15
+ %186 = OpConstant %6 7
+ %193 = OpConstant %6 8
+ %206 = OpConstant %6 6
+ %213 = OpConstant %6 17
+ %220 = OpConstant %6 13
+ %234 = OpConstant %6 10000
+ %237 = OpTypeFloat 32
+ %238 = OpTypeVector %237 2
+ %239 = OpTypeStruct %238
+ %240 = OpTypePointer Uniform %239
+ %241 = OpVariable %240 Uniform
+ %242 = OpConstant %27 1
+ %243 = OpTypePointer Uniform %237
+ %274 = OpConstant %6 20
+ %306 = OpTypeVector %237 4
+ %307 = OpTypePointer Output %306
+ %308 = OpVariable %307 Output
+ %309 = OpConstant %237 1
+ %310 = OpConstant %237 0
+ %311 = OpConstantComposite %306 %309 %310 %310 %309
+ %313 = OpConstantComposite %306 %310 %310 %309 %309
+ %4 = OpFunction %2 None %3
+ %5 = OpLabel
+ %154 = OpVariable %7 Function
+ %156 = OpVariable %13 Function
+ %159 = OpVariable %7 Function
+ %166 = OpVariable %7 Function
+ %168 = OpVariable %7 Function
+ %173 = OpVariable %7 Function
+ %175 = OpVariable %7 Function
+ %180 = OpVariable %7 Function
+ %182 = OpVariable %7 Function
+ %187 = OpVariable %7 Function
+ %189 = OpVariable %7 Function
+ %194 = OpVariable %7 Function
+ %196 = OpVariable %7 Function
+ %200 = OpVariable %7 Function
+ %202 = OpVariable %7 Function
+ %207 = OpVariable %7 Function
+ %209 = OpVariable %7 Function
+ %214 = OpVariable %7 Function
+ %216 = OpVariable %7 Function
+ %221 = OpVariable %7 Function
+ %223 = OpVariable %7 Function
+ %225 = OpVariable %7 Function
+ %226 = OpVariable %7 Function
+ %227 = OpVariable %7 Function
+ %254 = OpVariable %7 Function
+ %266 = OpVariable %7 Function
+ %267 = OpVariable %7 Function
+ %276 = OpVariable %7 Function
+ %277 = OpVariable %7 Function
+ OpStore %154 %33
+ %157 = OpAccessChain %80 %62 %33
+ %158 = OpLoad %12 %157
+ OpStore %156 %158
+ OpStore %159 %155
+ %160 = OpFunctionCall %2 %17 %156 %159
+ %161 = OpLoad %12 %156
+ %162 = OpAccessChain %80 %62 %33
+ OpStore %162 %161
+ %163 = OpLoad %6 %154
+ %164 = OpIAdd %6 %163 %45
+ OpStore %154 %164
+ %167 = OpLoad %6 %154
+ OpStore %166 %167
+ OpStore %168 %165
+ %169 = OpFunctionCall %2 %22 %166 %168
+ %170 = OpLoad %6 %154
+ %171 = OpIAdd %6 %170 %45
+ OpStore %154 %171
+ %174 = OpLoad %6 %154
+ OpStore %173 %174
+ OpStore %175 %172
+ %176 = OpFunctionCall %2 %22 %173 %175
+ %177 = OpLoad %6 %154
+ %178 = OpIAdd %6 %177 %45
+ OpStore %154 %178
+ %181 = OpLoad %6 %154
+ OpStore %180 %181
+ OpStore %182 %179
+ %183 = OpFunctionCall %2 %22 %180 %182
+ %184 = OpLoad %6 %154
+ %185 = OpIAdd %6 %184 %45
+ OpStore %154 %185
+ %188 = OpLoad %6 %154
+ OpStore %187 %188
+ OpStore %189 %186
+ %190 = OpFunctionCall %2 %22 %187 %189
+ %191 = OpLoad %6 %154
+ %192 = OpIAdd %6 %191 %45
+ OpStore %154 %192
+ %195 = OpLoad %6 %154
+ OpStore %194 %195
+ OpStore %196 %193
+ %197 = OpFunctionCall %2 %22 %194 %196
+ %198 = OpLoad %6 %154
+ %199 = OpIAdd %6 %198 %45
+ OpStore %154 %199
+ %201 = OpLoad %6 %154
+ OpStore %200 %201
+ OpStore %202 %38
+ %203 = OpFunctionCall %2 %22 %200 %202
+ %204 = OpLoad %6 %154
+ %205 = OpIAdd %6 %204 %45
+ OpStore %154 %205
+ %208 = OpLoad %6 %154
+ OpStore %207 %208
+ OpStore %209 %206
+ %210 = OpFunctionCall %2 %22 %207 %209
+ %211 = OpLoad %6 %154
+ %212 = OpIAdd %6 %211 %45
+ OpStore %154 %212
+ %215 = OpLoad %6 %154
+ OpStore %214 %215
+ OpStore %216 %213
+ %217 = OpFunctionCall %2 %22 %214 %216
+ %218 = OpLoad %6 %154
+ %219 = OpIAdd %6 %218 %45
+ OpStore %154 %219
+ %222 = OpLoad %6 %154
+ OpStore %221 %222
+ OpStore %223 %220
+ %224 = OpFunctionCall %2 %22 %221 %223
+ OpStore %225 %33
+ OpStore %226 %33
+ OpStore %227 %33
+ OpBranch %228
+ %228 = OpLabel
+ OpLoopMerge %230 %231 None
+ OpBranch %232
+ %232 = OpLabel
+ %233 = OpLoad %6 %227
+ %235 = OpSLessThan %57 %233 %234
+ OpBranchConditional %235 %229 %230
+ %229 = OpLabel
+ %236 = OpLoad %6 %226
+ %244 = OpAccessChain %243 %241 %33 %242
+ %245 = OpLoad %237 %244
+ %246 = OpConvertFToS %6 %245
+ %247 = OpSGreaterThanEqual %57 %236 %246
+ OpSelectionMerge %249 None
+ OpBranchConditional %247 %248 %249
+ %248 = OpLabel
+ %250 = OpAccessChain %243 %241 %33 %242
+ %251 = OpLoad %237 %250
+ %252 = OpConvertFToS %6 %251
+ %253 = OpIAdd %6 %45 %252
+ OpStore %254 %253
+ %255 = OpFunctionCall %6 %10 %254
+ OpStore %225 %255
+ OpBranch %230
+ %249 = OpLabel
+ %257 = OpLoad %6 %226
+ %258 = OpIAdd %6 %257 %45
+ OpStore %226 %258
+ OpBranch %231
+ %231 = OpLabel
+ %259 = OpLoad %6 %227
+ %260 = OpIAdd %6 %259 %45
+ OpStore %227 %260
+ OpBranch %228
+ %230 = OpLabel
+ %261 = OpLoad %6 %225
+ %262 = OpINotEqual %57 %261 %38
+ OpSelectionMerge %264 None
+ OpBranchConditional %262 %263 %264
+ %263 = OpLabel
+ OpReturn
+ %264 = OpLabel
+ OpStore %266 %33
+ OpStore %267 %33
+ OpBranch %268
+ %268 = OpLabel
+ OpLoopMerge %270 %271 None
+ OpBranch %272
+ %272 = OpLabel
+ %273 = OpLoad %6 %267
+ %275 = OpSLessThan %57 %273 %274
+ OpBranchConditional %275 %269 %270
+ %269 = OpLabel
+ %278 = OpLoad %6 %267
+ OpStore %277 %278
+ %279 = OpFunctionCall %6 %25 %277
+ OpStore %276 %279
+ %280 = OpLoad %6 %267
+ OpSelectionMerge %283 None
+ OpSwitch %280 %282 9 %281 5 %281 12 %281 15 %281 7 %281 8 %281 2 %281 6 %281 17 %281 13 %281
+ %282 = OpLabel
+ %292 = OpLoad %6 %276
+ %293 = OpIEqual %57 %292 %46
+ OpSelectionMerge %295 None
+ OpBranchConditional %293 %294 %295
+ %294 = OpLabel
+ %296 = OpLoad %6 %266
+ %297 = OpIAdd %6 %296 %45
+ OpStore %266 %297
+ OpBranch %295
+ %295 = OpLabel
+ OpBranch %283
+ %281 = OpLabel
+ %284 = OpLoad %6 %276
+ %285 = OpLoad %6 %267
+ %286 = OpIEqual %57 %284 %285
+ OpSelectionMerge %288 None
+ OpBranchConditional %286 %287 %288
+ %287 = OpLabel
+ %289 = OpLoad %6 %266
+ %290 = OpIAdd %6 %289 %45
+ OpStore %266 %290
+ OpBranch %288
+ %288 = OpLabel
+ OpBranch %283
+ %283 = OpLabel
+ OpBranch %271
+ %271 = OpLabel
+ %300 = OpLoad %6 %267
+ %301 = OpIAdd %6 %300 %45
+ OpStore %267 %301
+ OpBranch %268
+ %270 = OpLabel
+ %302 = OpLoad %6 %266
+ %303 = OpIEqual %57 %302 %274
+ OpSelectionMerge %305 None
+ OpBranchConditional %303 %304 %312
+ %304 = OpLabel
+ OpStore %308 %311
+ OpBranch %305
+ %312 = OpLabel
+ OpStore %308 %313
+ OpBranch %305
+ %305 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %10 = OpFunction %6 None %8
+ %9 = OpFunctionParameter %7
+ %11 = OpLabel
+ %34 = OpLoad %6 %9
+ %35 = OpLoad %6 %9
+ %37 = OpAccessChain %36 %32 %33 %34
+ OpStore %37 %35
+ %39 = OpAccessChain %36 %32 %33 %38
+ %40 = OpLoad %6 %39
+ OpReturnValue %40
+ OpFunctionEnd
+ %17 = OpFunction %2 None %14
+ %15 = OpFunctionParameter %13
+ %16 = OpFunctionParameter %7
+ %18 = OpLabel
+ %43 = OpLoad %6 %16
+ %44 = OpAccessChain %7 %15 %33
+ OpStore %44 %43
+ %47 = OpAccessChain %7 %15 %45
+ OpStore %47 %46
+ %48 = OpAccessChain %7 %15 %38
+ OpStore %48 %46
+ OpReturn
+ OpFunctionEnd
+ %22 = OpFunction %2 None %19
+ %20 = OpFunctionParameter %7
+ %21 = OpFunctionParameter %7
+ %23 = OpLabel
+ %49 = OpVariable %7 Function
+ %79 = OpVariable %13 Function
+ %83 = OpVariable %7 Function
+ %105 = OpVariable %13 Function
+ %108 = OpVariable %7 Function
+ OpStore %49 %33
+ OpBranch %50
+ %50 = OpLabel
+ OpLoopMerge %52 %53 None
+ OpBranch %54
+ %54 = OpLabel
+ %55 = OpLoad %6 %49
+ %56 = OpLoad %6 %20
+ %58 = OpSLessThanEqual %57 %55 %56
+ OpBranchConditional %58 %51 %52
+ %51 = OpLabel
+ %59 = OpLoad %6 %21
+ %63 = OpLoad %6 %49
+ %64 = OpAccessChain %36 %62 %63 %33
+ %65 = OpLoad %6 %64
+ %66 = OpSLessThanEqual %57 %59 %65
+ OpSelectionMerge %68 None
+ OpBranchConditional %66 %67 %94
+ %67 = OpLabel
+ %69 = OpLoad %6 %49
+ %70 = OpAccessChain %36 %62 %69 %45
+ %71 = OpLoad %6 %70
+ %72 = OpIEqual %57 %71 %46
+ OpSelectionMerge %74 None
+ OpBranchConditional %72 %73 %89
+ %73 = OpLabel
+ %75 = OpLoad %6 %49
+ %76 = OpLoad %6 %20
+ %77 = OpAccessChain %36 %62 %75 %45
+ OpStore %77 %76
+ %78 = OpLoad %6 %20
+ %81 = OpAccessChain %80 %62 %78
+ %82 = OpLoad %12 %81
+ OpStore %79 %82
+ %84 = OpLoad %6 %21
+ OpStore %83 %84
+ %85 = OpFunctionCall %2 %17 %79 %83
+ %86 = OpLoad %12 %79
+ %87 = OpAccessChain %80 %62 %78
+ OpStore %87 %86
+ OpReturn
+ %89 = OpLabel
+ %90 = OpLoad %6 %49
+ %91 = OpAccessChain %36 %62 %90 %45
+ %92 = OpLoad %6 %91
+ OpStore %49 %92
+ OpBranch %53
+ %74 = OpLabel
+ OpUnreachable
+ %94 = OpLabel
+ %95 = OpLoad %6 %49
+ %96 = OpAccessChain %36 %62 %95 %38
+ %97 = OpLoad %6 %96
+ %98 = OpIEqual %57 %97 %46
+ OpSelectionMerge %100 None
+ OpBranchConditional %98 %99 %114
+ %99 = OpLabel
+ %101 = OpLoad %6 %49
+ %102 = OpLoad %6 %20
+ %103 = OpAccessChain %36 %62 %101 %38
+ OpStore %103 %102
+ %104 = OpLoad %6 %20
+ %106 = OpAccessChain %80 %62 %104
+ %107 = OpLoad %12 %106
+ OpStore %105 %107
+ %109 = OpLoad %6 %21
+ OpStore %108 %109
+ %110 = OpFunctionCall %2 %17 %105 %108
+ %111 = OpLoad %12 %105
+ %112 = OpAccessChain %80 %62 %104
+ OpStore %112 %111
+ OpReturn
+ %114 = OpLabel
+ %115 = OpLoad %6 %49
+ %116 = OpAccessChain %36 %62 %115 %38
+ %117 = OpLoad %6 %116
+ OpStore %49 %117
+ OpBranch %53
+ %100 = OpLabel
+ OpUnreachable
+ %68 = OpLabel
+ OpUnreachable
+ %53 = OpLabel
+ OpBranch %50
+ %52 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %25 = OpFunction %6 None %8
+ %24 = OpFunctionParameter %7
+ %26 = OpLabel
+ %119 = OpVariable %7 Function
+ %127 = OpVariable %13 Function
+ %143 = OpVariable %7 Function
+ OpStore %119 %33
+ OpBranch %120
+ %120 = OpLabel
+ OpLoopMerge %122 %123 None
+ OpBranch %124
+ %124 = OpLabel
+ %125 = OpLoad %6 %119
+ %126 = OpINotEqual %57 %125 %46
+ OpBranchConditional %126 %121 %122
+ %121 = OpLabel
+ %128 = OpLoad %6 %119
+ %129 = OpAccessChain %80 %62 %128
+ %130 = OpLoad %12 %129
+ OpStore %127 %130
+ %131 = OpAccessChain %7 %127 %33
+ %132 = OpLoad %6 %131
+ %133 = OpLoad %6 %24
+ %134 = OpIEqual %57 %132 %133
+ OpSelectionMerge %136 None
+ OpBranchConditional %134 %135 %136
+ %135 = OpLabel
+ %137 = OpLoad %6 %24
+ OpReturnValue %137
+ %136 = OpLabel
+ %139 = OpLoad %6 %24
+ %140 = OpAccessChain %7 %127 %33
+ %141 = OpLoad %6 %140
+ %142 = OpSGreaterThan %57 %139 %141
+ OpSelectionMerge %145 None
+ OpBranchConditional %142 %144 %148
+ %144 = OpLabel
+ %146 = OpAccessChain %7 %127 %38
+ %147 = OpLoad %6 %146
+ OpStore %143 %147
+ OpBranch %145
+ %148 = OpLabel
+ %149 = OpAccessChain %7 %127 %45
+ %150 = OpLoad %6 %149
+ OpStore %143 %150
+ OpBranch %145
+ %145 = OpLabel
+ %151 = OpLoad %6 %143
+ OpStore %119 %151
+ OpBranch %123
+ %123 = OpLabel
+ OpBranch %120
+ %122 = OpLabel
+ OpReturnValue %46
+ OpFunctionEnd
+END
+
+# uniforms for variant
+
+# injectionSwitch
+BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
+ 0.0 1.0
+END
+
+BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
+
+PIPELINE graphics variant_pipeline
+ ATTACH variant_vertex_shader
+ ATTACH variant_fragment_shader
+ FRAMEBUFFER_SIZE 256 256
+ BIND BUFFER variant_framebuffer AS color LOCATION 0
+ BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
+END
+CLEAR_COLOR variant_pipeline 0 0 0 255
+
+CLEAR variant_pipeline
+RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
+
+EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005
+EXPECT reference_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
+EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255