<< inst->words[returnTypeIndex] << "' is not a type.";
return false;
}
+ size_t num_args = 0;
for (size_t paramTypeIndex = 3; paramTypeIndex < inst->words.size();
- ++paramTypeIndex) {
+ ++paramTypeIndex, ++num_args) {
auto paramType = module_.FindDef(inst->words[paramTypeIndex]);
if (!paramType || !spvOpcodeGeneratesType(paramType->opcode())) {
DIAG(paramTypeIndex) << "OpTypeFunction Parameter Type <id> '"
return false;
}
}
+ if (num_args > 255) {
+ DIAG(returnTypeIndex) << "OpTypeFunction may not take more than 255 "
+ "arguments. OpTypeFunction <id> '"
+ << inst->words[1] << "' has " << num_args
+ << " arguments.";
+ return false;
+ }
return true;
}
// to OpPhi instructions or OpSelect instructions, or any instructions other
// than the image lookup and query instructions specified to take an operand
// whose type is OpTypeSampledImage.
- std::vector<uint32_t> consumers =
- module_.getSampledImageConsumers(resultID);
+ std::vector<uint32_t> consumers = module_.getSampledImageConsumers(resultID);
if (!consumers.empty()) {
for (auto consumer_id : consumers) {
auto consumer_instr = module_.FindDef(consumer_id);
"exceeds the limit (16383)."));
}
+// Valid: OpTypeFunction with 255 arguments.
+TEST_F(ValidateLimits, OpTypeFunctionGood) {
+ int num_args = 255;
+ std::ostringstream spirv;
+ spirv << header << R"(
+%1 = OpTypeInt 32 0
+%2 = OpTypeFunction %1)";
+ // add parameters
+ for (int i = 0; i < num_args; ++i) {
+ spirv << " %1";
+ }
+ CompileSuccessfully(spirv.str());
+ EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
+}
+
+// Invalid: OpTypeFunction with 256 arguments. (limit is 255 according to the
+// spec Universal Limits (2.17).
+TEST_F(ValidateLimits, OpTypeFunctionBad) {
+ int num_args = 256;
+ std::ostringstream spirv;
+ spirv << header << R"(
+%1 = OpTypeInt 32 0
+%2 = OpTypeFunction %1)";
+ for (int i = 0; i < num_args; ++i) {
+ spirv << " %1";
+ }
+ CompileSuccessfully(spirv.str());
+ EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
+ EXPECT_THAT(getDiagnosticString(),
+ HasSubstr("OpTypeFunction may not take more than 255 arguments. "
+ "OpTypeFunction <id> '2' has 256 arguments."));
+}