+#!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 fragment shader that compares a float and a coordinate
+
+# The test passes because shader always writes red.
+
+# Optimized using spirv-opt with the following arguments:
+# '--redundancy-elimination'
+# '--redundancy-elimination'
+# '--private-to-local'
+# '--eliminate-dead-inserts'
+# '--eliminate-dead-code-aggressive'
+# '--combine-access-chains'
+# '--reduce-load-size'
+# '--inline-entry-points-exhaustive'
+# '--vector-dce'
+# '--eliminate-dead-branches'
+# '--merge-blocks'
+# '--copy-propagate-arrays'
+# '--vector-dce'
+# '--eliminate-dead-branches'
+# '--merge-blocks'
+# '--eliminate-dead-branches'
+# '--merge-return'
+# '--combine-access-chains'
+# '--eliminate-dead-inserts'
+# '--eliminate-dead-branches'
+# '--if-conversion'
+# '--inline-entry-points-exhaustive'
+# '--simplify-instructions'
+# '--eliminate-local-single-store'
+# '--eliminate-dead-branches'
+# '--eliminate-local-single-block'
+# '--eliminate-local-multi-store'
+# '--convert-local-access-chains'
+# '--ccp'
+# spirv-opt commit hash: ab7ac60f14ae66006bed5c989a2cfd4c4881704c
+
+
+
+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(set = 0, binding = 0) uniform buf0
+# {
+# vec2 injectionSwitch;
+# };
+# layout(location = 0) out vec4 _GLF_color;
+#
+# // Always returns 5.
+# float func()
+# {
+# float zero = 0.0;
+# bool alwaysFalse = gl_FragCoord.x < 0.0;
+#
+# do
+# {
+# if (injectionSwitch.x < injectionSwitch.y) // Always true
+# {
+# while (int(zero) <= bitfieldInsert(101, 0, 0, 0))
+# {
+# if (zero <= gl_FragCoord.x)
+# return 5.0; // Always returns here
+#
+# zero++;
+# }
+# }
+# } while (alwaysFalse);
+#
+# for (int u = 0; u < 1; u++)
+# {
+# if (!alwaysFalse)
+# return zero;
+# }
+#
+# return 0.0;
+# }
+#
+# void main()
+# {
+# float c = 0.0;
+# for (int i = 0; i < 1; i++)
+# {
+# if (!(gl_FragCoord.x < 0.0)) // Always true
+# c = func();
+# }
+#
+# if (c == 5.0)
+# _GLF_color = vec4(1, 0, 0, 1);
+# else
+# _GLF_color = vec4(0);
+# }
+SHADER fragment variant_fragment_shader SPIRV-ASM
+; SPIR-V
+; Version: 1.0
+; Generator: Khronos Glslang Reference Front End; 8
+; Bound: 261
+; Schema: 0
+ OpCapability Shader
+ %1 = OpExtInstImport "GLSL.std.450"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %4 "main" %18 %109
+ OpExecutionMode %4 OriginUpperLeft
+ OpSource ESSL 310
+ OpName %4 "main"
+ OpName %8 "func("
+ OpName %11 "zero"
+ OpName %15 "alwaysFalse"
+ OpName %18 "gl_FragCoord"
+ OpName %30 "buf0"
+ OpMemberName %30 0 "injectionSwitch"
+ OpName %32 ""
+ OpName %67 "u"
+ OpName %86 "c"
+ OpName %87 "i"
+ OpName %109 "_GLF_color"
+ OpDecorate %18 BuiltIn FragCoord
+ OpMemberDecorate %30 0 Offset 0
+ OpDecorate %30 Block
+ OpDecorate %32 DescriptorSet 0
+ OpDecorate %32 Binding 0
+ OpDecorate %109 Location 0
+ %2 = OpTypeVoid
+ %3 = OpTypeFunction %2
+ %6 = OpTypeFloat 32
+ %7 = OpTypeFunction %6
+ %10 = OpTypePointer Function %6
+ %12 = OpConstant %6 0
+ %13 = OpTypeBool
+ %14 = OpTypePointer Function %13
+ %16 = OpTypeVector %6 4
+ %17 = OpTypePointer Input %16
+ %18 = OpVariable %17 Input
+ %19 = OpTypeInt 32 0
+ %20 = OpConstant %19 0
+ %21 = OpTypePointer Input %6
+ %29 = OpTypeVector %6 2
+ %30 = OpTypeStruct %29
+ %31 = OpTypePointer Uniform %30
+ %32 = OpVariable %31 Uniform
+ %33 = OpTypeInt 32 1
+ %34 = OpConstant %33 0
+ %35 = OpTypePointer Uniform %6
+ %38 = OpConstant %19 1
+ %51 = OpConstant %33 101
+ %60 = OpConstant %6 5
+ %63 = OpConstant %6 1
+ %66 = OpTypePointer Function %33
+ %74 = OpConstant %33 1
+ %108 = OpTypePointer Output %16
+ %109 = OpVariable %108 Output
+ %110 = OpConstantComposite %16 %63 %12 %12 %63
+ %112 = OpConstantComposite %16 %12 %12 %12 %12
+ %119 = OpConstantFalse %13
+ %121 = OpConstantTrue %13
+ %211 = OpUndef %6
+ %226 = OpUndef %13
+ %228 = OpUndef %33
+ %256 = OpUndef %6
+ %260 = OpUndef %13
+ %4 = OpFunction %2 None %3
+ %5 = OpLabel
+ %128 = OpVariable %14 Function %119
+ %129 = OpVariable %10 Function
+ %130 = OpVariable %10 Function
+ %131 = OpVariable %14 Function
+ %132 = OpVariable %66 Function
+ %133 = OpVariable %10 Function
+ %86 = OpVariable %10 Function
+ %87 = OpVariable %66 Function
+ OpStore %86 %12
+ OpStore %87 %34
+ OpBranch %88
+ %88 = OpLabel
+ %210 = OpPhi %6 %211 %5 %227 %91
+ %188 = OpPhi %6 %12 %5 %225 %91
+ %187 = OpPhi %33 %34 %5 %103 %91
+ %94 = OpSLessThan %13 %187 %74
+ OpLoopMerge %90 %91 None
+ OpBranchConditional %94 %89 %90
+ %89 = OpLabel
+ %95 = OpAccessChain %21 %18 %20
+ %96 = OpLoad %6 %95
+ %97 = OpFOrdLessThan %13 %96 %12
+ %98 = OpLogicalNot %13 %97
+ OpSelectionMerge %100 None
+ OpBranchConditional %98 %99 %100
+ %99 = OpLabel
+ OpStore %128 %119
+ OpBranch %134
+ %134 = OpLabel
+ %221 = OpPhi %33 %187 %99 %228 %136
+ %209 = OpPhi %6 %210 %99 %211 %136
+ %194 = OpPhi %13 %119 %99 %226 %136
+ OpLoopMerge %135 %136 None
+ OpBranch %137
+ %137 = OpLabel
+ OpStore %130 %12
+ %138 = OpAccessChain %21 %18 %20
+ %139 = OpLoad %6 %138
+ %140 = OpFOrdLessThan %13 %139 %12
+ OpStore %131 %140
+ OpBranch %141
+ %141 = OpLabel
+ %193 = OpPhi %13 %119 %137 %196 %143
+ %190 = OpPhi %6 %12 %137 %201 %143
+ %220 = OpPhi %33 %221 %137 %222 %143
+ %208 = OpPhi %6 %209 %137 %212 %143
+ OpLoopMerge %142 %143 None
+ OpBranch %144
+ %144 = OpLabel
+ %145 = OpAccessChain %35 %32 %34 %20
+ %146 = OpLoad %6 %145
+ %147 = OpAccessChain %35 %32 %34 %38
+ %148 = OpLoad %6 %147
+ %149 = OpFOrdLessThan %13 %146 %148
+ OpSelectionMerge %150 None
+ OpBranchConditional %149 %151 %150
+ %151 = OpLabel
+ OpBranch %152
+ %152 = OpLabel
+ %189 = OpPhi %6 %190 %151 %165 %158
+ %154 = OpConvertFToS %33 %189
+ %155 = OpBitFieldInsert %33 %51 %34 %34 %34
+ %156 = OpSLessThanEqual %13 %154 %155
+ OpLoopMerge %157 %158 None
+ OpBranchConditional %156 %159 %157
+ %159 = OpLabel
+ %161 = OpFOrdLessThanEqual %13 %189 %139
+ OpSelectionMerge %162 None
+ OpBranchConditional %161 %163 %162
+ %163 = OpLabel
+ OpStore %128 %121
+ OpStore %129 %60
+ OpBranch %157
+ %162 = OpLabel
+ %165 = OpFAdd %6 %189 %63
+ OpStore %130 %165
+ OpBranch %158
+ %158 = OpLabel
+ OpBranch %152
+ %157 = OpLabel
+ %206 = OpPhi %6 %208 %152 %60 %163
+ %191 = OpPhi %13 %193 %152 %121 %163
+ OpSelectionMerge %167 None
+ OpBranchConditional %191 %142 %167
+ %167 = OpLabel
+ OpBranch %150
+ %150 = OpLabel
+ %222 = OpPhi %33 %220 %144 %220 %167
+ %212 = OpPhi %6 %208 %144 %206 %167
+ %201 = OpPhi %6 %190 %144 %189 %167
+ %196 = OpPhi %13 %193 %144 %191 %167
+ OpBranch %143
+ %143 = OpLabel
+ OpBranchConditional %140 %141 %142
+ %142 = OpLabel
+ %217 = OpPhi %33 %220 %157 %222 %143
+ %205 = OpPhi %6 %206 %157 %212 %143
+ %199 = OpPhi %6 %189 %157 %201 %143
+ %195 = OpPhi %13 %191 %157 %196 %143
+ OpSelectionMerge %170 None
+ OpBranchConditional %195 %135 %170
+ %170 = OpLabel
+ OpStore %132 %34
+ OpBranch %171
+ %171 = OpLabel
+ %197 = OpPhi %33 %34 %170 %183 %175
+ %173 = OpSLessThan %13 %197 %74
+ OpLoopMerge %174 %175 None
+ OpBranchConditional %173 %176 %174
+ %176 = OpLabel
+ %178 = OpLogicalNot %13 %140
+ OpSelectionMerge %179 None
+ OpBranchConditional %178 %180 %179
+ %180 = OpLabel
+ OpStore %128 %121
+ OpStore %129 %199
+ OpBranch %174
+ %179 = OpLabel
+ OpBranch %175
+ %175 = OpLabel
+ %183 = OpIAdd %33 %197 %74
+ OpStore %132 %183
+ OpBranch %171
+ %174 = OpLabel
+ %213 = OpPhi %6 %205 %171 %199 %180
+ %202 = OpPhi %13 %195 %171 %121 %180
+ OpSelectionMerge %185 None
+ OpBranchConditional %202 %135 %185
+ %185 = OpLabel
+ OpStore %128 %121
+ OpStore %129 %12
+ OpBranch %135
+ %136 = OpLabel
+ OpBranch %134
+ %135 = OpLabel
+ %204 = OpPhi %6 %205 %142 %213 %174 %12 %185
+ OpStore %133 %204
+ OpStore %86 %204
+ OpBranch %100
+ %100 = OpLabel
+ %227 = OpPhi %6 %210 %89 %204 %135
+ %225 = OpPhi %6 %188 %89 %204 %135
+ %215 = OpPhi %33 %187 %89 %217 %135
+ OpBranch %91
+ %91 = OpLabel
+ %103 = OpIAdd %33 %215 %74
+ OpStore %87 %103
+ OpBranch %88
+ %90 = OpLabel
+ %105 = OpFOrdEqual %13 %188 %60
+ OpSelectionMerge %107 None
+ OpBranchConditional %105 %106 %111
+ %106 = OpLabel
+ OpStore %109 %110
+ OpBranch %107
+ %111 = OpLabel
+ OpStore %109 %112
+ OpBranch %107
+ %107 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %8 = OpFunction %6 None %7
+ %9 = OpLabel
+ %120 = OpVariable %14 Function %119
+ %114 = OpVariable %10 Function
+ %11 = OpVariable %10 Function
+ %15 = OpVariable %14 Function
+ %67 = OpVariable %66 Function
+ OpBranch %116
+ %116 = OpLabel
+ %234 = OpPhi %13 %119 %9 %260 %118
+ OpLoopMerge %113 %118 None
+ OpBranch %117
+ %117 = OpLabel
+ OpStore %11 %12
+ %22 = OpAccessChain %21 %18 %20
+ %23 = OpLoad %6 %22
+ %24 = OpFOrdLessThan %13 %23 %12
+ OpStore %15 %24
+ OpBranch %25
+ %25 = OpLabel
+ %233 = OpPhi %13 %234 %117 %240 %28
+ %230 = OpPhi %6 %12 %117 %247 %28
+ %254 = OpPhi %6 %256 %117 %257 %28
+ OpLoopMerge %27 %28 None
+ OpBranch %26
+ %26 = OpLabel
+ %36 = OpAccessChain %35 %32 %34 %20
+ %37 = OpLoad %6 %36
+ %39 = OpAccessChain %35 %32 %34 %38
+ %40 = OpLoad %6 %39
+ %41 = OpFOrdLessThan %13 %37 %40
+ OpSelectionMerge %43 None
+ OpBranchConditional %41 %42 %43
+ %42 = OpLabel
+ OpBranch %44
+ %44 = OpLabel
+ %229 = OpPhi %6 %230 %42 %64 %47
+ %50 = OpConvertFToS %33 %229
+ %52 = OpBitFieldInsert %33 %51 %34 %34 %34
+ %53 = OpSLessThanEqual %13 %50 %52
+ OpLoopMerge %46 %47 None
+ OpBranchConditional %53 %45 %46
+ %45 = OpLabel
+ %57 = OpFOrdLessThanEqual %13 %229 %23
+ OpSelectionMerge %59 None
+ OpBranchConditional %57 %58 %59
+ %58 = OpLabel
+ OpStore %120 %121
+ OpStore %114 %60
+ OpBranch %46
+ %59 = OpLabel
+ %64 = OpFAdd %6 %229 %63
+ OpStore %11 %64
+ OpBranch %47
+ %47 = OpLabel
+ OpBranch %44
+ %46 = OpLabel
+ %252 = OpPhi %6 %254 %44 %60 %58
+ %231 = OpPhi %13 %233 %44 %121 %58
+ OpSelectionMerge %122 None
+ OpBranchConditional %231 %27 %122
+ %122 = OpLabel
+ OpBranch %43
+ %43 = OpLabel
+ %257 = OpPhi %6 %254 %26 %252 %122
+ %247 = OpPhi %6 %230 %26 %229 %122
+ %240 = OpPhi %13 %233 %26 %231 %122
+ OpBranch %28
+ %28 = OpLabel
+ OpBranchConditional %24 %25 %27
+ %27 = OpLabel
+ %251 = OpPhi %6 %252 %46 %257 %28
+ %245 = OpPhi %6 %229 %46 %247 %28
+ %239 = OpPhi %13 %231 %46 %240 %28
+ OpSelectionMerge %124 None
+ OpBranchConditional %239 %113 %124
+ %124 = OpLabel
+ OpStore %67 %34
+ OpBranch %68
+ %68 = OpLabel
+ %241 = OpPhi %33 %34 %124 %83 %71
+ %75 = OpSLessThan %13 %241 %74
+ OpLoopMerge %70 %71 None
+ OpBranchConditional %75 %69 %70
+ %69 = OpLabel
+ %77 = OpLogicalNot %13 %24
+ OpSelectionMerge %79 None
+ OpBranchConditional %77 %78 %79
+ %78 = OpLabel
+ OpStore %120 %121
+ OpStore %114 %245
+ OpBranch %70
+ %79 = OpLabel
+ OpBranch %71
+ %71 = OpLabel
+ %83 = OpIAdd %33 %241 %74
+ OpStore %67 %83
+ OpBranch %68
+ %70 = OpLabel
+ %258 = OpPhi %6 %251 %68 %245 %78
+ %248 = OpPhi %13 %239 %68 %121 %78
+ OpSelectionMerge %126 None
+ OpBranchConditional %248 %113 %126
+ %126 = OpLabel
+ OpStore %120 %121
+ OpStore %114 %12
+ OpBranch %113
+ %118 = OpLabel
+ OpBranch %116
+ %113 = OpLabel
+ %250 = OpPhi %6 %251 %27 %258 %70 %12 %126
+ OpReturnValue %250
+ OpFunctionEnd
+END
+
+# uniforms for variant
+
+# resolution
+BUFFER variant_resolution DATA_TYPE vec2<float> DATA
+ 256.0 256.0
+END
+# 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_resolution AS uniform DESCRIPTOR_SET 0 BINDING 1
+ 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 variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255