MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ValidateConstantOperand

Function ValidateConstantOperand

source/val/validate_constants.cpp:43–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43spv_result_t ValidateConstantOperand(ValidationState_t& _,
44 const Instruction* inst, size_t operand) {
45 std::string opcode_name = std::string("Op") + spvOpcodeString(inst->opcode());
46
47 const auto operand_id = inst->GetOperandAs<uint32_t>(operand);
48 const bool inst_is_spec_constant = spvOpcodeIsSpecConstant(inst->opcode());
49 const auto operand_opcode = _.GetIdOpcode(operand_id);
50 const bool is_constant = spvOpcodeIsConstantOrUndef(operand_opcode);
51 const bool is_spec_constant = spvOpcodeIsSpecConstant(operand_opcode);
52 if (!is_constant) {
53 // All operands must be constant or undef.
54 return _.diag(SPV_ERROR_INVALID_ID, inst)
55 << opcode_name << " must only have constant or undef operands: <id> "
56 << _.getIdName(operand_id);
57 } else if (!inst_is_spec_constant && is_spec_constant) {
58 // Spec constants are only allowed for spec constant opcodes.
59 return _.diag(SPV_ERROR_INVALID_ID, inst)
60 << opcode_name << " must not have spec constant operands: <id> "
61 << _.getIdName(operand_id);
62 }
63
64 return SPV_SUCCESS;
65}
66
67spv_result_t ValidateConstantComposite(ValidationState_t& _,
68 const Instruction* inst) {

Callers 2

Calls 7

spvOpcodeStringFunction · 0.85
spvOpcodeIsSpecConstantFunction · 0.85
GetIdOpcodeMethod · 0.80
diagMethod · 0.80
getIdNameMethod · 0.80
opcodeMethod · 0.45

Tested by

no test coverage detected