| 28 | using ::testing::Eq; |
| 29 | |
| 30 | TEST(FunctionTest, HasEarlyReturn) { |
| 31 | std::string shader = R"( |
| 32 | OpCapability Shader |
| 33 | %1 = OpExtInstImport "GLSL.std.450" |
| 34 | OpMemoryModel Logical GLSL450 |
| 35 | OpEntryPoint Vertex %6 "main" |
| 36 | |
| 37 | ; Types |
| 38 | %2 = OpTypeBool |
| 39 | %3 = OpTypeVoid |
| 40 | %4 = OpTypeFunction %3 |
| 41 | |
| 42 | ; Constants |
| 43 | %5 = OpConstantTrue %2 |
| 44 | |
| 45 | ; main function without early return |
| 46 | %6 = OpFunction %3 None %4 |
| 47 | %7 = OpLabel |
| 48 | OpBranch %8 |
| 49 | %8 = OpLabel |
| 50 | OpBranch %9 |
| 51 | %9 = OpLabel |
| 52 | OpBranch %10 |
| 53 | %10 = OpLabel |
| 54 | OpReturn |
| 55 | OpFunctionEnd |
| 56 | |
| 57 | ; function with early return |
| 58 | %11 = OpFunction %3 None %4 |
| 59 | %12 = OpLabel |
| 60 | OpSelectionMerge %15 None |
| 61 | OpBranchConditional %5 %13 %14 |
| 62 | %13 = OpLabel |
| 63 | OpReturn |
| 64 | %14 = OpLabel |
| 65 | OpBranch %15 |
| 66 | %15 = OpLabel |
| 67 | OpReturn |
| 68 | OpFunctionEnd |
| 69 | )"; |
| 70 | |
| 71 | const auto context = |
| 72 | BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, shader, |
| 73 | SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 74 | |
| 75 | // Tests |function| without early return. |
| 76 | auto* function = spvtest::GetFunction(context->module(), 6); |
| 77 | ASSERT_FALSE(function->HasEarlyReturn()); |
| 78 | |
| 79 | // Tests |function| with early return. |
| 80 | function = spvtest::GetFunction(context->module(), 11); |
| 81 | ASSERT_TRUE(function->HasEarlyReturn()); |
| 82 | } |
| 83 | |
| 84 | TEST(FunctionTest, IsNotRecursive) { |
| 85 | const std::string text = R"( |
nothing calls this directly
no test coverage detected