{"action":"created","comment":{"url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/comments/63600248","id":63600248,"diff_hunk":"@@ -0,0 +1,601 @@\n+\n+// Copyright (c) 2015-2016 The Khronos Group Inc.\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a\n+// copy of this software and/or associated documentation files (the\n+// \"Materials\"), to deal in the Materials without restriction, including\n+// without limitation the rights to use, copy, modify, merge, publish,\n+// distribute, sublicense, and/or sell copies of the Materials, and to\n+// permit persons to whom the Materials are furnished to do so, subject to\n+// the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included\n+// in all copies or substantial portions of the Materials.\n+//\n+// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS\n+// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS\n+// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT\n+//    https://www.khronos.org/registry/\n+//\n+// THE MATERIALS ARE PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n+// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n+// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n+// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n+// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.\n+\n+// Validation tests for Control Flow Graph\n+\n+#include <array>\n+#include <functional>\n+#include <iterator>\n+#include <sstream>\n+#include <string>\n+#include <vector>\n+#include <utility>\n+\n+#include \"gmock/gmock.h\"\n+\n+#include \"TestFixture.h\"\n+#include \"UnitSPIRV.h\"\n+#include \"ValidateFixtures.h\"\n+#include \"source/diagnostic.h\"\n+#include \"source/validate.h\"\n+\n+using std::array;\n+using std::make_pair;\n+using std::pair;\n+using std::string;\n+using std::stringstream;\n+using std::vector;\n+\n+using ::testing::HasSubstr;\n+\n+using libspirv::BasicBlock;\n+using libspirv::ValidationState_t;\n+\n+using ValidateCFG = spvtest::ValidateBase<bool>;\n+using spvtest::ScopedContext;\n+\n+namespace {\n+\n+string nameOps() { return \"\"; }\n+\n+template <typename... Args>\n+string nameOps(pair<string, string> head, Args... names) {\n+  return \"OpName %\" + head.first + \" \\\"\" + head.second + \"\\\"\\n\" +\n+         nameOps(names...);\n+}\n+\n+template <typename... Args>\n+string nameOps(string head, Args... names) {\n+  return \"OpName %\" + head + \" \\\"\" + head + \"\\\"\\n\" + nameOps(names...);\n+}\n+\n+class Block {\n+  string label_;\n+  string body_;\n+  SpvOp type_;\n+  vector<Block> successors_;\n+\n+ public:\n+  Block(string label, SpvOp type = SpvOpBranch)\n+      : label_(label), body_(), type_(type), successors_() {}\n+\n+  Block &setBody(std::string body) {\n+    body_ = body;\n+    return *this;\n+  }\n+\n+  operator string() {\n+    stringstream out;\n+    out << std::setw(8) << \"%\" + label_ + \"  = OpLabel \\n\";\n+    if (!body_.empty()) {\n+      out << body_;\n+    }\n+\n+    switch (type_) {\n+      case SpvOpBranchConditional:\n+        out << \"OpBranchConditional %cond \";\n+        for (Block &b : successors_) {\n+          out << \"%\" + b.label_ + \" \";\n+        }\n+        break;\n+      case SpvOpSwitch: {\n+        out << \"OpSwitch %one %\" + successors_.front().label_;\n+        stringstream ss;\n+        for (size_t i = 1; i < successors_.size(); i++) {\n+          ss << \" \" << i << \" %\" << successors_[i].label_;\n+        }\n+        out << ss.str();\n+      } break;\n+      case SpvOpReturn:\n+        out << \"OpReturn\\n\";\n+        break;\n+      case SpvOpUnreachable:\n+        out << \"OpUnreachable\\n\";\n+        break;\n+      case SpvOpBranch:\n+        out << \"OpBranch %\" + successors_.front().label_;\n+        break;\n+      default:\n+        assert(1 != 1 && \"Unhandled\");\n+    }\n+    out << \"\\n\";\n+\n+    return out.str();\n+  }\n+  friend Block &operator>>(Block &curr, vector<Block> successors);\n+  friend Block &operator>>(Block &lhs, Block &successor);\n+};\n+\n+Block &operator>>(Block &lhs, vector<Block> successors) {\n+  if (lhs.type_ == SpvOpBranchConditional) {\n+    assert(successors.size() == 2);\n+  } else if (lhs.type_ == SpvOpSwitch) {\n+    assert(successors.size() > 1);\n+  }\n+  lhs.successors_ = successors;\n+  return lhs;\n+}\n+\n+Block &operator>>(Block &lhs, Block &successor) {\n+  assert(lhs.type_ == SpvOpBranch);\n+  lhs.successors_.push_back(successor);\n+  return lhs;\n+}\n+\n+string header =\n+    \"OpCapability Shader\\n\"\n+    \"OpMemoryModel Logical GLSL450\\n\";\n+\n+string types_consts =\n+    nameOps(\"voidt\", \"boolt\", \"intt\", \"one\", \"two\", \"ptrt\", \"funct\") +\n+    \"%voidt   = OpTypeVoid\\n\"\n+    \"%boolt   = OpTypeBool\\n\"\n+    \"%intt    = OpTypeInt 32 1\\n\"\n+    \"%one     = OpConstant %intt 1\\n\"\n+    \"%two     = OpConstant %intt 2\\n\"\n+    \"%ptrt    = OpTypePointer Function %intt\\n\"\n+    \"%funct   = OpTypeFunction %voidt\\n\";\n+\n+TEST_F(ValidateCFG, Default) {\n+  Block first(\"first\");\n+  Block loop(\"loop\", SpvOpBranchConditional);\n+  Block cont(\"cont\");\n+  Block merge(\"merge\", SpvOpReturn);\n+\n+  loop.setBody(\n+      \"%cond    = OpSLessThan %intt %one %two\\n\"\n+      \"OpLoopMerge %merge %cont None\\n\");\n+\n+  string str = header +\n+               nameOps(\"loop\", \"first\", \"cont\", \"merge\", make_pair(\"func\", \"Main\")) +\n+               types_consts + \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += first >> loop;\n+  str += loop >> vector<Block>({cont, merge});\n+  str += cont >> loop;\n+  str += merge;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());\n+}\n+\n+TEST_F(ValidateCFG, Variable) {\n+  Block entry(\"entry\");\n+  Block cont(\"cont\");\n+  Block exit(\"exit\", SpvOpReturn);\n+\n+  entry.setBody(\"%var = OpVariable %ptrt Function\\n\");\n+\n+  string str = header + nameOps(make_pair(\"func\", \"Main\")) + types_consts +\n+               \" %func    = OpFunction %voidt None %funct\\n\";\n+  str += entry >> cont;\n+  str += cont >> exit;\n+  str += exit;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());\n+}\n+\n+TEST_F(ValidateCFG, VariableNotInFirstBlockBad) {\n+  Block entry(\"entry\");\n+  Block cont(\"cont\");\n+  Block exit(\"exit\", SpvOpReturn);\n+\n+  // This operation should only be performed in the entry block\n+  cont.setBody(\"%var = OpVariable %ptrt Function\\n\");\n+\n+  string str = header + nameOps(make_pair(\"func\", \"Main\")) + types_consts +\n+               \" %func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> cont;\n+  str += cont >> exit;\n+  str += exit;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"first block\"));\n+}\n+\n+TEST_F(ValidateCFG, BlockAppearsBeforeDominatorBad) {\n+  Block entry(\"entry\");\n+  Block cont(\"cont\");\n+  Block branch(\"branch\", SpvOpBranchConditional);\n+  Block merge(\"merge\", SpvOpReturn);\n+\n+  branch.setBody(\n+      \" %cond    = OpSLessThan %intt %one %two\\n\"\n+      \"OpSelectionMerge %merge None\\n\");\n+\n+  string str = header + nameOps(\"cont\", \"branch\", make_pair(\"func\", \"Main\")) +\n+               types_consts + \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> branch;\n+  str += cont >> merge;  // cont appears before its dominator\n+  str += branch >> vector<Block>({cont, merge});\n+  str += merge;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(),\n+              HasSubstr(\"appears in the binary before its dominator\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"cont\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"branch\"));\n+}\n+\n+TEST_F(ValidateCFG, MergeBlockTargetedByMultipleHeaderBlocksBad) {\n+  Block entry(\"entry\");\n+  Block loop(\"loop\");\n+  Block badhead(\"badhead\", SpvOpBranchConditional);\n+  Block t(\"t\");\n+  Block f(\"f\");\n+  Block cont(\"cont\");\n+  Block merge(\"merge\");\n+  Block end(\"end\", SpvOpReturn);\n+\n+  // cannot share the same merge\n+  loop.setBody(\n+      \" %cond2   = OpSLessThan %intt %one %two\\n\"\n+      \" OpLoopMerge %merge %cont None\\n\");\n+  badhead.setBody(\n+      \" %cond1   = OpSLessThan %intt %one %two\\n\"\n+      \"OpSelectionMerge %merge None\\n\");\n+\n+  string str = header + nameOps(\"merge\", make_pair(\"func\", \"Main\")) + types_consts +\n+               \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> loop;\n+  str += loop >> badhead;\n+  str += badhead >> vector<Block>({t, f});\n+  str += t >> merge;\n+  str += f >> cont;\n+  str += cont >> loop;\n+  str += merge >> end;\n+  str += end;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"merge\"));\n+}\n+\n+TEST_F(ValidateCFG, MergeBlockTargetedByMultipleHeaderBlocksSelectionBad) {\n+  Block entry(\"entry\");\n+  Block loop(\"loop\");\n+  Block badhead(\"badhead\", SpvOpBranchConditional);\n+  Block t(\"t\");\n+  Block f(\"f\");\n+  Block cont(\"cont\");\n+  Block merge(\"merge\");\n+  Block end(\"end\", SpvOpReturn);\n+\n+  // cannot share the same merge\n+  loop.setBody(\" OpLoopMerge %merge %cont None\\n\");\n+\n+  badhead.setBody(\n+      \" %cond   = OpSLessThan %intt %one %two\\n\"\n+      \" OpSelectionMerge %merge None\\n\");\n+\n+  string str = header + nameOps(\"merge\", make_pair(\"func\", \"Main\")) + types_consts +\n+               \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> badhead;\n+  str += badhead >> vector<Block>({t, f});\n+  str += t >> merge;\n+  str += f >> cont;\n+  str += cont >> loop;\n+  str += loop >> merge;\n+  str += merge >> end;\n+  str += end;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"merge\"));\n+}\n+\n+TEST_F(ValidateCFG, BranchTargetFirstBlockBad) {\n+  Block entry(\"entry\");\n+  Block bad(\"bad\");\n+  Block end(\"end\", SpvOpReturn);\n+  string str = header + nameOps(\"entry\", \"bad\", make_pair(\"func\", \"Main\")) +\n+               types_consts + \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> bad;\n+  str += bad >> entry;  // Cannot target entry block\n+  str += end;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"First block\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"entry\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"Main\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"bad\"));\n+}\n+\n+TEST_F(ValidateCFG, BranchConditionalTrueTargetFirstBlockBad) {\n+  Block entry(\"entry\");\n+  Block bad(\"bad\", SpvOpBranchConditional);\n+  Block f(\"f\");\n+  Block merge(\"merge\");\n+  Block end(\"end\", SpvOpReturn);\n+\n+  bad.setBody(\n+      \" %cond    = OpSLessThan %intt %one %two\\n\"\n+      \"OpLoopMerge %merge %cont None\\n\");\n+\n+  string str = header + nameOps(\"entry\", \"bad\", make_pair(\"func\", \"Main\")) +\n+               types_consts + \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> bad;\n+  str += bad >> vector<Block>({entry, f});  // cannot target entry block\n+  str += f >> merge;\n+  str += merge >> end;\n+  str += end;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"First block\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"entry\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"Main\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"bad\"));\n+}\n+\n+TEST_F(ValidateCFG, BranchConditionalFalseTargetFirstBlockBad) {\n+  Block entry(\"entry\");\n+  Block bad(\"bad\", SpvOpBranchConditional);\n+  Block t(\"t\");\n+  Block merge(\"merge\");\n+  Block end(\"end\", SpvOpReturn);\n+\n+  bad.setBody(\n+      \"%cond    = OpSLessThan %intt %one %two\\n\"\n+      \"OpLoopMerge %merge %cont None\\n\");\n+\n+  string str = header + nameOps(\"entry\", \"bad\", make_pair(\"func\", \"Main\")) +\n+               types_consts + \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> bad;\n+  str += bad >> vector<Block>({t, entry});\n+  str += merge >> end;\n+  str += end;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"First block\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"entry\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"Main\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"bad\"));\n+}\n+\n+TEST_F(ValidateCFG, SwitchTargetFirstBlockBad) {\n+  Block entry(\"entry\");\n+  Block bad(\"bad\", SpvOpSwitch);\n+  Block block1(\"block1\");\n+  Block block2(\"block2\");\n+  Block block3(\"block3\");\n+  Block def(\"def\");  // default block\n+  Block merge(\"merge\");\n+  Block end(\"end\", SpvOpReturn);\n+\n+  bad.setBody(\n+      \"%cond    = OpSLessThan %intt %one %two\\n\"\n+      \"OpSelectionMerge %merge None\\n\");\n+\n+  string str = header + nameOps(\"entry\", \"bad\", make_pair(\"func\", \"Main\")) +\n+               types_consts + \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> bad;\n+  str += bad >> vector<Block>({def, block1, block2, block3, entry});\n+  str += def >> merge;\n+  str += block1 >> merge;\n+  str += block2 >> merge;\n+  str += block3 >> merge;\n+  str += merge >> end;\n+  str += end;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"First block\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"entry\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"Main\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"bad\"));\n+}\n+\n+TEST_F(ValidateCFG, BranchToBlockInOtherFunctionBad) {\n+  Block entry(\"entry\");\n+  Block middle(\"middle\", SpvOpBranchConditional);\n+  Block end(\"end\", SpvOpReturn);\n+\n+  middle.setBody(\n+      \"%cond    = OpSLessThan %intt %one %two\\n\"\n+      \"OpSelectionMerge %end None\\n\");\n+\n+  Block entry2(\"entry2\");\n+  Block middle2(\"middle2\");\n+  Block end2(\"end2\", SpvOpReturn);\n+\n+  string str = header + nameOps(\"middle2\", make_pair(\"func\", \"Main\")) + types_consts +\n+               \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> middle;\n+  str += middle >> vector<Block>({end, middle2});\n+  str += end;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  str += \"%func2    = OpFunction %voidt None %funct\\n\";\n+  str += entry2 >> middle2;\n+  str += middle2 >> end2;\n+  str += end2;\n+  str += \"OpFunctionEnd\\n\";\n+\n+  CompileSuccessfully(str);\n+  ASSERT_EQ(SPV_ERROR_INVALID_CFG, ValidateInstructions());\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"Main\"));\n+  EXPECT_THAT(getDiagnosticString(), HasSubstr(\"middle2\"));\n+  EXPECT_THAT(getDiagnosticString(),\n+              HasSubstr(\"are referenced but not defined\"));\n+}\n+\n+TEST_F(ValidateCFG, HeaderDoesntDominatesMergeBad) {\n+  Block entry(\"entry\");\n+  Block bad(\"bad\", SpvOpBranchConditional);\n+  Block f(\"f\");\n+  Block merge(\"merge\", SpvOpBranchConditional);\n+  Block cont(\"cont\");\n+  Block end(\"end\", SpvOpReturn);\n+\n+  bad.setBody(\"OpLoopMerge %merge %cont None\\n\");\n+\n+  merge.setBody(\n+      \" %cond    = OpSLessThan %intt %one %two\\n\"\n+      \"OpSelectionMerge %end None\\n\");\n+\n+  string str = header + nameOps(\"bad\", \"merge\", make_pair(\"func\", \"Main\")) +\n+               types_consts + \"%func    = OpFunction %voidt None %funct\\n\";\n+\n+  str += entry >> merge;\n+  str += merge >> vector<Block>({bad, end});\n+  str += bad >> vector<Block>({cont, f});\n+  str += cont >> merge;","path":"test/Validate.CFG.cpp","position":491,"original_position":491,"commit_id":"95f3a1dbc93c3ea8644ba58031d17a5bad7e052a","original_commit_id":"95f3a1dbc93c3ea8644ba58031d17a5bad7e052a","user":{"login":"dekimir","id":1635074,"avatar_url":"https://avatars.githubusercontent.com/u/1635074?v=3","gravatar_id":"","url":"https://api.github.com/users/dekimir","html_url":"https://github.com/dekimir","followers_url":"https://api.github.com/users/dekimir/followers","following_url":"https://api.github.com/users/dekimir/following{/other_user}","gists_url":"https://api.github.com/users/dekimir/gists{/gist_id}","starred_url":"https://api.github.com/users/dekimir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dekimir/subscriptions","organizations_url":"https://api.github.com/users/dekimir/orgs","repos_url":"https://api.github.com/users/dekimir/repos","events_url":"https://api.github.com/users/dekimir/events{/privacy}","received_events_url":"https://api.github.com/users/dekimir/received_events","type":"User","site_admin":false},"body":"This is a back edge not going into a loop header.  In the future, this (instead of merge domination) may trigger the validation failure and make this test fail despite the code working correctly.","created_at":"2016-05-17T20:45:18Z","updated_at":"2016-05-17T20:45:18Z","html_url":"https://github.com/KhronosGroup/SPIRV-Tools/pull/197#discussion_r63600248","pull_request_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/197","_links":{"self":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/comments/63600248"},"html":{"href":"https://github.com/KhronosGroup/SPIRV-Tools/pull/197#discussion_r63600248"},"pull_request":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/197"}}},"pull_request":{"url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/197","id":67625695,"html_url":"https://github.com/KhronosGroup/SPIRV-Tools/pull/197","diff_url":"https://github.com/KhronosGroup/SPIRV-Tools/pull/197.diff","patch_url":"https://github.com/KhronosGroup/SPIRV-Tools/pull/197.patch","issue_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/issues/197","number":197,"state":"open","locked":false,"title":"WIP: Control Flow Graph Validation","user":{"login":"umar456","id":457510,"avatar_url":"https://avatars.githubusercontent.com/u/457510?v=3","gravatar_id":"","url":"https://api.github.com/users/umar456","html_url":"https://github.com/umar456","followers_url":"https://api.github.com/users/umar456/followers","following_url":"https://api.github.com/users/umar456/following{/other_user}","gists_url":"https://api.github.com/users/umar456/gists{/gist_id}","starred_url":"https://api.github.com/users/umar456/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/umar456/subscriptions","organizations_url":"https://api.github.com/users/umar456/orgs","repos_url":"https://api.github.com/users/umar456/repos","events_url":"https://api.github.com/users/umar456/events{/privacy}","received_events_url":"https://api.github.com/users/umar456/received_events","type":"User","site_admin":false},"body":"## Control-Flow Graph\r\n- [x] Blocks exist only within a function.\r\n- [x] The first block in a function definition is the entry point of that function and cannot be the target of any branch.\r\n- [X] The order of blocks in a function must satisfy the rule that blocks appear before all blocks they dominate.\r\n- [X] Each block starts with a label.\r\n  - [X] A label is made by OpLabel.\r\n  - [X] This includes the first block of a function (OpFunction is not a label).\r\n  - [X] Labels are used only to form blocks.\r\n- [X] The last instruction of each block is a branch instruction.\r\n- [X] Branch instructions can only appear as the last instruction in a block.\r\n- [X] OpLabel instructions can only appear within a function.\r\n- [X] All branches within a function must be to labels in that function.\r\n\r\n## Control-Flow declarations\r\n- [X] the merge block declared by a header block cannot be a merge block declared by any other header block\r\n- [X] each header block must dominate (in the CFG) its merge block, unless the merge block is unreachable in the CFG\r\n- [ ] all CFG back edges must branch to a loop header, with each loop header having exactly one back edge branching to it\r\n- [ ] for a given loop, its back-edge block must post dominate the OpLoopMerge's Continue Target, and that Continue Target must dominate the back-edge block\r\n\r\n- [X] Within a function definition:\r\n  - [X] A block always starts with an *OpLabel* instruction. This may be immediately preceded by an *OpLine* instruction, but the *OpLabel* is considered as the beginning of the block.\r\n\r\n  - [X] A block always ends with a branch instruction.\r\n\r\n  - [X] All *OpVariable* instructions in a function must have a Storage Class of *Function*.\r\n\r\n  - [X] All *OpVariable* instructions in a function must be in the first block in the function. These instructions, together with any immediately preceding *OpLine* instructions, must be the first instructions in that block. \r\n\r\n  - [X] A function definition can be immediately preceded by an *OpLine* instruction.\r\n\r\n## Constructs must satisfy\r\n- [ ] the only blocks in a construct that can branch outside the construct are\r\n   - [ ] a block branching to the construct's merge block\r\n   - [ ] a block branching from one _case construct_ to another, for the same *OpSwitch*\r\n   - [ ] a continue block for the innermost loop it is nested inside of\r\n   - [ ] a break block for the innermost loop it is nested inside of\r\n   - [ ] a return block\r\n","created_at":"2016-04-24T03:02:06Z","updated_at":"2016-05-17T20:45:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1bccaf8c6af31dc2238f684cb829326d7c2c401c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/197/commits","review_comments_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/197/comments","review_comment_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/issues/197/comments","statuses_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/statuses/95f3a1dbc93c3ea8644ba58031d17a5bad7e052a","head":{"label":"umar456:cfg","ref":"cfg","sha":"95f3a1dbc93c3ea8644ba58031d17a5bad7e052a","user":{"login":"umar456","id":457510,"avatar_url":"https://avatars.githubusercontent.com/u/457510?v=3","gravatar_id":"","url":"https://api.github.com/users/umar456","html_url":"https://github.com/umar456","followers_url":"https://api.github.com/users/umar456/followers","following_url":"https://api.github.com/users/umar456/following{/other_user}","gists_url":"https://api.github.com/users/umar456/gists{/gist_id}","starred_url":"https://api.github.com/users/umar456/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/umar456/subscriptions","organizations_url":"https://api.github.com/users/umar456/orgs","repos_url":"https://api.github.com/users/umar456/repos","events_url":"https://api.github.com/users/umar456/events{/privacy}","received_events_url":"https://api.github.com/users/umar456/received_events","type":"User","site_admin":false},"repo":{"id":46513608,"name":"SPIRV-Tools","full_name":"umar456/SPIRV-Tools","owner":{"login":"umar456","id":457510,"avatar_url":"https://avatars.githubusercontent.com/u/457510?v=3","gravatar_id":"","url":"https://api.github.com/users/umar456","html_url":"https://github.com/umar456","followers_url":"https://api.github.com/users/umar456/followers","following_url":"https://api.github.com/users/umar456/following{/other_user}","gists_url":"https://api.github.com/users/umar456/gists{/gist_id}","starred_url":"https://api.github.com/users/umar456/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/umar456/subscriptions","organizations_url":"https://api.github.com/users/umar456/orgs","repos_url":"https://api.github.com/users/umar456/repos","events_url":"https://api.github.com/users/umar456/events{/privacy}","received_events_url":"https://api.github.com/users/umar456/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/umar456/SPIRV-Tools","description":"","fork":true,"url":"https://api.github.com/repos/umar456/SPIRV-Tools","forks_url":"https://api.github.com/repos/umar456/SPIRV-Tools/forks","keys_url":"https://api.github.com/repos/umar456/SPIRV-Tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/umar456/SPIRV-Tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/umar456/SPIRV-Tools/teams","hooks_url":"https://api.github.com/repos/umar456/SPIRV-Tools/hooks","issue_events_url":"https://api.github.com/repos/umar456/SPIRV-Tools/issues/events{/number}","events_url":"https://api.github.com/repos/umar456/SPIRV-Tools/events","assignees_url":"https://api.github.com/repos/umar456/SPIRV-Tools/assignees{/user}","branches_url":"https://api.github.com/repos/umar456/SPIRV-Tools/branches{/branch}","tags_url":"https://api.github.com/repos/umar456/SPIRV-Tools/tags","blobs_url":"https://api.github.com/repos/umar456/SPIRV-Tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/umar456/SPIRV-Tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/umar456/SPIRV-Tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/umar456/SPIRV-Tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/umar456/SPIRV-Tools/statuses/{sha}","languages_url":"https://api.github.com/repos/umar456/SPIRV-Tools/languages","stargazers_url":"https://api.github.com/repos/umar456/SPIRV-Tools/stargazers","contributors_url":"https://api.github.com/repos/umar456/SPIRV-Tools/contributors","subscribers_url":"https://api.github.com/repos/umar456/SPIRV-Tools/subscribers","subscription_url":"https://api.github.com/repos/umar456/SPIRV-Tools/subscription","commits_url":"https://api.github.com/repos/umar456/SPIRV-Tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/umar456/SPIRV-Tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/umar456/SPIRV-Tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/umar456/SPIRV-Tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/umar456/SPIRV-Tools/contents/{+path}","compare_url":"https://api.github.com/repos/umar456/SPIRV-Tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/umar456/SPIRV-Tools/merges","archive_url":"https://api.github.com/repos/umar456/SPIRV-Tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/umar456/SPIRV-Tools/downloads","issues_url":"https://api.github.com/repos/umar456/SPIRV-Tools/issues{/number}","pulls_url":"https://api.github.com/repos/umar456/SPIRV-Tools/pulls{/number}","milestones_url":"https://api.github.com/repos/umar456/SPIRV-Tools/milestones{/number}","notifications_url":"https://api.github.com/repos/umar456/SPIRV-Tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/umar456/SPIRV-Tools/labels{/name}","releases_url":"https://api.github.com/repos/umar456/SPIRV-Tools/releases{/id}","deployments_url":"https://api.github.com/repos/umar456/SPIRV-Tools/deployments","created_at":"2015-11-19T18:58:25Z","updated_at":"2016-01-13T16:20:41Z","pushed_at":"2016-05-10T14:18:27Z","git_url":"git://github.com/umar456/SPIRV-Tools.git","ssh_url":"git@github.com:umar456/SPIRV-Tools.git","clone_url":"https://github.com/umar456/SPIRV-Tools.git","svn_url":"https://github.com/umar456/SPIRV-Tools","homepage":null,"size":1634,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"KhronosGroup:master","ref":"master","sha":"34cb0035fd6d29a68daa5c042c109690774ea85e","user":{"login":"KhronosGroup","id":1608701,"avatar_url":"https://avatars.githubusercontent.com/u/1608701?v=3","gravatar_id":"","url":"https://api.github.com/users/KhronosGroup","html_url":"https://github.com/KhronosGroup","followers_url":"https://api.github.com/users/KhronosGroup/followers","following_url":"https://api.github.com/users/KhronosGroup/following{/other_user}","gists_url":"https://api.github.com/users/KhronosGroup/gists{/gist_id}","starred_url":"https://api.github.com/users/KhronosGroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KhronosGroup/subscriptions","organizations_url":"https://api.github.com/users/KhronosGroup/orgs","repos_url":"https://api.github.com/users/KhronosGroup/repos","events_url":"https://api.github.com/users/KhronosGroup/events{/privacy}","received_events_url":"https://api.github.com/users/KhronosGroup/received_events","type":"Organization","site_admin":false},"repo":{"id":45981801,"name":"SPIRV-Tools","full_name":"KhronosGroup/SPIRV-Tools","owner":{"login":"KhronosGroup","id":1608701,"avatar_url":"https://avatars.githubusercontent.com/u/1608701?v=3","gravatar_id":"","url":"https://api.github.com/users/KhronosGroup","html_url":"https://github.com/KhronosGroup","followers_url":"https://api.github.com/users/KhronosGroup/followers","following_url":"https://api.github.com/users/KhronosGroup/following{/other_user}","gists_url":"https://api.github.com/users/KhronosGroup/gists{/gist_id}","starred_url":"https://api.github.com/users/KhronosGroup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KhronosGroup/subscriptions","organizations_url":"https://api.github.com/users/KhronosGroup/orgs","repos_url":"https://api.github.com/users/KhronosGroup/repos","events_url":"https://api.github.com/users/KhronosGroup/events{/privacy}","received_events_url":"https://api.github.com/users/KhronosGroup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/KhronosGroup/SPIRV-Tools","description":"","fork":false,"url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools","forks_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/forks","keys_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/teams","hooks_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/hooks","issue_events_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/issues/events{/number}","events_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/events","assignees_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/assignees{/user}","branches_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/branches{/branch}","tags_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/tags","blobs_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/statuses/{sha}","languages_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/languages","stargazers_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/stargazers","contributors_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/contributors","subscribers_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/subscribers","subscription_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/subscription","commits_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/issues/comments{/number}","contents_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/contents/{+path}","compare_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/merges","archive_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/downloads","issues_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/issues{/number}","pulls_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls{/number}","milestones_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/milestones{/number}","notifications_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/labels{/name}","releases_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/releases{/id}","deployments_url":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/deployments","created_at":"2015-11-11T12:56:25Z","updated_at":"2016-05-12T21:32:08Z","pushed_at":"2016-05-17T13:49:13Z","git_url":"git://github.com/KhronosGroup/SPIRV-Tools.git","ssh_url":"git@github.com:KhronosGroup/SPIRV-Tools.git","clone_url":"https://github.com/KhronosGroup/SPIRV-Tools.git","svn_url":"https://github.com/KhronosGroup/SPIRV-Tools","homepage":null,"size":1993,"stargazers_count":122,"watchers_count":122,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":11,"forks":28,"open_issues":11,"watchers":122,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/197"},"html":{"href":"https://github.com/KhronosGroup/SPIRV-Tools/pull/197"},"issue":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/issues/197"},"comments":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/issues/197/comments"},"review_comments":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/197/comments"},"review_comment":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/pulls/197/commits"},"statuses":{"href":"https://api.github.com/repos/KhronosGroup/SPIRV-Tools/statuses/95f3a1dbc93c3ea8644ba58031d17a5bad7e052a"}}}}