| 128 | } |
| 129 | |
| 130 | TEST(CompactIds, InstructionResultIsUpdated) { |
| 131 | // For https://github.com/KhronosGroup/SPIRV-Tools/issues/827 |
| 132 | // In that bug, the compact Ids pass was directly updating the result Id |
| 133 | // word for an OpFunction instruction, but not updating the cached |
| 134 | // result_id_ in that Instruction object. |
| 135 | // |
| 136 | // This test is a bit cheesy. We don't expose internal interfaces enough |
| 137 | // to see the inconsistency. So reproduce the original scenario, with |
| 138 | // compact ids followed by a pass that trips up on the inconsistency. |
| 139 | |
| 140 | const std::string input(R"(OpCapability Shader |
| 141 | OpMemoryModel Logical Simple |
| 142 | OpEntryPoint GLCompute %100 "main" |
| 143 | %200 = OpTypeVoid |
| 144 | %300 = OpTypeFunction %200 |
| 145 | %100 = OpFunction %200 None %300 |
| 146 | %400 = OpLabel |
| 147 | OpReturn |
| 148 | OpFunctionEnd |
| 149 | )"); |
| 150 | |
| 151 | std::vector<uint32_t> binary; |
| 152 | const spv_target_env env = SPV_ENV_UNIVERSAL_1_0; |
| 153 | spvtools::SpirvTools tools(env); |
| 154 | auto assembled = tools.Assemble( |
| 155 | input, &binary, SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 156 | EXPECT_TRUE(assembled); |
| 157 | |
| 158 | spvtools::Optimizer optimizer(env); |
| 159 | optimizer.RegisterPass(CreateCompactIdsPass()); |
| 160 | // The exhaustive inliner will use the result_id |
| 161 | optimizer.RegisterPass(CreateInlineExhaustivePass()); |
| 162 | |
| 163 | // This should not crash! |
| 164 | optimizer.Run(binary.data(), binary.size(), &binary); |
| 165 | |
| 166 | std::string disassembly; |
| 167 | tools.Disassemble(binary, &disassembly, SPV_BINARY_TO_TEXT_OPTION_NO_HEADER); |
| 168 | |
| 169 | const std::string expected(R"(OpCapability Shader |
| 170 | OpMemoryModel Logical Simple |
| 171 | OpEntryPoint GLCompute %1 "main" |
| 172 | %2 = OpTypeVoid |
| 173 | %3 = OpTypeFunction %2 |
| 174 | %1 = OpFunction %2 None %3 |
| 175 | %4 = OpLabel |
| 176 | OpReturn |
| 177 | OpFunctionEnd |
| 178 | )"); |
| 179 | |
| 180 | EXPECT_THAT(disassembly, ::testing::Eq(expected)); |
| 181 | } |
| 182 | |
| 183 | TEST(CompactIds, HeaderIsUpdated) { |
| 184 | const std::string input(R"(OpCapability Shader |
nothing calls this directly
no test coverage detected