--- /dev/null
+#!amber
+
+# Copyright 2019 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 with nested control flow and a call
+
+# The test passes because all loops terminate or are not entered and the shader ends by writing red.
+
+SHADER vertex variant_vertex_shader PASSTHROUGH
+
+# variant_fragment_shader is derived from the following GLSL:
+# #version 310 es
+# precision highp float;
+#
+# layout(set = 0, binding = 0) uniform buf0
+# {
+# vec2 injectionSwitch;
+# };
+# layout(location = 0) out vec4 _GLF_color;
+#
+# struct BinarySearchObject
+# {
+# int prime_numbers[10];
+# };
+#
+# int binarySearch(BinarySearchObject obj)
+# {
+# while (injectionSwitch.x > 1.0) // always false
+# {
+# int m = int(injectionSwitch.x);
+# if (obj.prime_numbers[m] == 1)
+# {
+# return 1;
+# }
+# }
+# return 1;
+# }
+#
+# void main()
+# {
+# BinarySearchObject obj;
+# for (
+# int i = 0;
+# i < 10;
+# i++)
+# {
+# if (i != 3)
+# {
+# if ((i - int(injectionSwitch.x)) == 4)
+# {
+# obj.prime_numbers[i] = 11;
+# }
+# else
+# {
+# if (i == 6)
+# {
+# obj.prime_numbers[i] = 17;
+# }
+# continue;
+# }
+# }
+# do
+# {
+# } while (0.0 > injectionSwitch.y); // always false
+# }
+# binarySearch(obj);
+# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
+# }
+SHADER fragment variant_fragment_shader SPIRV-ASM
+; SPIR-V
+; Version: 1.0
+; Generator: Khronos Glslang Reference Front End; 7
+; Bound: 104
+; Schema: 0
+ OpCapability Shader
+ %1 = OpExtInstImport "GLSL.std.450"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %4 "main" %102
+ OpExecutionMode %4 OriginUpperLeft
+ OpSource ESSL 310
+ OpName %4 "main"
+ OpName %10 "BinarySearchObject"
+ OpMemberName %10 0 "prime_numbers"
+ OpName %14 "binarySearch(struct-BinarySearchObject-i1[10]1;"
+ OpName %13 "obj"
+ OpName %23 "buf0"
+ OpMemberName %23 0 "injectionSwitch"
+ OpName %25 ""
+ OpName %35 "m"
+ OpName %49 "i"
+ OpName %72 "obj"
+ OpName %97 "param"
+ OpName %102 "_GLF_color"
+ OpMemberDecorate %10 0 RelaxedPrecision
+ OpDecorate %14 RelaxedPrecision
+ OpMemberDecorate %23 0 Offset 0
+ OpDecorate %23 Block
+ OpDecorate %25 DescriptorSet 0
+ OpDecorate %25 Binding 0
+ OpDecorate %35 RelaxedPrecision
+ OpDecorate %38 RelaxedPrecision
+ OpDecorate %39 RelaxedPrecision
+ OpDecorate %41 RelaxedPrecision
+ OpDecorate %49 RelaxedPrecision
+ OpDecorate %55 RelaxedPrecision
+ OpDecorate %58 RelaxedPrecision
+ OpDecorate %63 RelaxedPrecision
+ OpDecorate %66 RelaxedPrecision
+ OpDecorate %67 RelaxedPrecision
+ OpDecorate %73 RelaxedPrecision
+ OpDecorate %77 RelaxedPrecision
+ OpDecorate %82 RelaxedPrecision
+ OpDecorate %95 RelaxedPrecision
+ OpDecorate %96 RelaxedPrecision
+ OpDecorate %99 RelaxedPrecision
+ OpDecorate %102 Location 0
+ %2 = OpTypeVoid
+ %3 = OpTypeFunction %2
+ %6 = OpTypeInt 32 1
+ %7 = OpTypeInt 32 0
+ %8 = OpConstant %7 10
+ %9 = OpTypeArray %6 %8
+ %10 = OpTypeStruct %9
+ %11 = OpTypePointer Function %10
+ %12 = OpTypeFunction %6 %11
+ %21 = OpTypeFloat 32
+ %22 = OpTypeVector %21 2
+ %23 = OpTypeStruct %22
+ %24 = OpTypePointer Uniform %23
+ %25 = OpVariable %24 Uniform
+ %26 = OpConstant %6 0
+ %27 = OpConstant %7 0
+ %28 = OpTypePointer Uniform %21
+ %31 = OpConstant %21 1
+ %32 = OpTypeBool
+ %34 = OpTypePointer Function %6
+ %42 = OpConstant %6 1
+ %56 = OpConstant %6 10
+ %59 = OpConstant %6 3
+ %68 = OpConstant %6 4
+ %74 = OpConstant %6 11
+ %78 = OpConstant %6 6
+ %83 = OpConstant %6 17
+ %90 = OpConstant %21 0
+ %91 = OpConstant %7 1
+ %100 = OpTypeVector %21 4
+ %101 = OpTypePointer Output %100
+ %102 = OpVariable %101 Output
+ %103 = OpConstantComposite %100 %31 %90 %90 %31
+ %4 = OpFunction %2 None %3
+ %5 = OpLabel
+ %49 = OpVariable %34 Function
+ %72 = OpVariable %11 Function
+ %97 = OpVariable %11 Function
+ OpStore %49 %26
+ OpBranch %50
+ %50 = OpLabel
+ OpLoopMerge %52 %53 None
+ OpBranch %54
+ %54 = OpLabel
+ %55 = OpLoad %6 %49
+ %57 = OpSLessThan %32 %55 %56
+ OpBranchConditional %57 %51 %52
+ %51 = OpLabel
+ %58 = OpLoad %6 %49
+ %60 = OpINotEqual %32 %58 %59
+ OpSelectionMerge %62 None
+ OpBranchConditional %60 %61 %62
+ %61 = OpLabel
+ %63 = OpLoad %6 %49
+ %64 = OpAccessChain %28 %25 %26 %27
+ %65 = OpLoad %21 %64
+ %66 = OpConvertFToS %6 %65
+ %67 = OpISub %6 %63 %66
+ %69 = OpIEqual %32 %67 %68
+ OpSelectionMerge %71 None
+ OpBranchConditional %69 %70 %76
+ %70 = OpLabel
+ %73 = OpLoad %6 %49
+ %75 = OpAccessChain %34 %72 %26 %73
+ OpStore %75 %74
+ OpBranch %71
+ %76 = OpLabel
+ %77 = OpLoad %6 %49
+ %79 = OpIEqual %32 %77 %78
+ OpSelectionMerge %81 None
+ OpBranchConditional %79 %80 %81
+ %80 = OpLabel
+ %82 = OpLoad %6 %49
+ %84 = OpAccessChain %34 %72 %26 %82
+ OpStore %84 %83
+ OpBranch %81
+ %81 = OpLabel
+ OpBranch %53
+ %71 = OpLabel
+ OpBranch %62
+ %62 = OpLabel
+ OpBranch %86
+ %86 = OpLabel
+ OpLoopMerge %88 %89 None
+ OpBranch %87
+ %87 = OpLabel
+ OpBranch %89
+ %89 = OpLabel
+ %92 = OpAccessChain %28 %25 %26 %91
+ %93 = OpLoad %21 %92
+ %94 = OpFOrdGreaterThan %32 %90 %93
+ OpBranchConditional %94 %86 %88
+ %88 = OpLabel
+ OpBranch %53
+ %53 = OpLabel
+ %95 = OpLoad %6 %49
+ %96 = OpIAdd %6 %95 %42
+ OpStore %49 %96
+ OpBranch %50
+ %52 = OpLabel
+ %98 = OpLoad %10 %72
+ OpStore %97 %98
+ %99 = OpFunctionCall %6 %14 %97
+ OpStore %102 %103
+ OpReturn
+ OpFunctionEnd
+ %14 = OpFunction %6 None %12
+ %13 = OpFunctionParameter %11
+ %15 = OpLabel
+ %35 = OpVariable %34 Function
+ OpBranch %16
+ %16 = OpLabel
+ OpLoopMerge %18 %19 None
+ OpBranch %20
+ %20 = OpLabel
+ %29 = OpAccessChain %28 %25 %26 %27
+ %30 = OpLoad %21 %29
+ %33 = OpFOrdGreaterThan %32 %30 %31
+ OpBranchConditional %33 %17 %18
+ %17 = OpLabel
+ %36 = OpAccessChain %28 %25 %26 %27
+ %37 = OpLoad %21 %36
+ %38 = OpConvertFToS %6 %37
+ OpStore %35 %38
+ %39 = OpLoad %6 %35
+ %40 = OpAccessChain %34 %13 %26 %39
+ %41 = OpLoad %6 %40
+ %43 = OpIEqual %32 %41 %42
+ OpSelectionMerge %45 None
+ OpBranchConditional %43 %44 %45
+ %44 = OpLabel
+ OpReturnValue %42
+ %45 = OpLabel
+ OpBranch %19
+ %19 = OpLabel
+ OpBranch %16
+ %18 = OpLabel
+ OpReturnValue %42
+ 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 variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255