Родитель
eef11cdb71
Коммит
106c98d0fa
|
@ -14,11 +14,10 @@
|
|||
|
||||
// Ensures type declarations are unique unless allowed by the specification.
|
||||
|
||||
#include "source/val/validate.h"
|
||||
|
||||
#include "source/opcode.h"
|
||||
#include "source/spirv_target_env.h"
|
||||
#include "source/val/instruction.h"
|
||||
#include "source/val/validate.h"
|
||||
#include "source/val/validation_state.h"
|
||||
|
||||
namespace spvtools {
|
||||
|
@ -67,6 +66,16 @@ spv_result_t ValidateUniqueness(ValidationState_t& _, const Instruction* inst) {
|
|||
return SPV_SUCCESS;
|
||||
}
|
||||
|
||||
spv_result_t ValidateTypeInt(ValidationState_t& _, const Instruction* inst) {
|
||||
const auto signedness_index = 2;
|
||||
const auto signedness = inst->GetOperandAs<uint32_t>(signedness_index);
|
||||
if (signedness != 0 && signedness != 1) {
|
||||
return _.diag(SPV_ERROR_INVALID_VALUE, inst)
|
||||
<< "OpTypeInt has invalid signedness:";
|
||||
}
|
||||
return SPV_SUCCESS;
|
||||
}
|
||||
|
||||
spv_result_t ValidateTypeVector(ValidationState_t& _, const Instruction* inst) {
|
||||
const auto component_index = 1;
|
||||
const auto component_id = inst->GetOperandAs<uint32_t>(component_index);
|
||||
|
@ -439,6 +448,9 @@ spv_result_t TypePass(ValidationState_t& _, const Instruction* inst) {
|
|||
if (auto error = ValidateUniqueness(_, inst)) return error;
|
||||
|
||||
switch (inst->opcode()) {
|
||||
case SpvOpTypeInt:
|
||||
if (auto error = ValidateTypeInt(_, inst)) return error;
|
||||
break;
|
||||
case SpvOpTypeVector:
|
||||
if (auto error = ValidateTypeVector(_, inst)) return error;
|
||||
break;
|
||||
|
|
|
@ -85,6 +85,16 @@ TEST_F(ValidateLiterals, LiteralsShaderGood) {
|
|||
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
|
||||
}
|
||||
|
||||
TEST_F(ValidateLiterals, InvalidInt) {
|
||||
std::string str = GenerateShaderCode() + R"(
|
||||
%11 = OpTypeInt 32 90
|
||||
)";
|
||||
CompileSuccessfully(str);
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_VALUE, ValidateInstructions());
|
||||
EXPECT_THAT(getDiagnosticString(),
|
||||
HasSubstr("OpTypeInt has invalid signedness:"));
|
||||
}
|
||||
|
||||
TEST_P(ValidateLiteralsShader, LiteralsShaderBad) {
|
||||
std::string str = GenerateShaderCode() + GetParam();
|
||||
std::string inst_id = "11";
|
||||
|
|
Загрузка…
Ссылка в новой задаче