diff options
author | David Neto <dneto@google.com> | 2019-01-09 10:36:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-09 10:36:17 -0500 |
commit | 6958d11bc29751e57f350007946d8dca125a8090 (patch) | |
tree | 2fc21ea71b0075b8faef92327cae97f2903fc9e5 /source/val/validate_decorations.cpp | |
parent | df5bd2d05ac1fd3ec3024439f885ec21cc949b22 (diff) | |
download | SPIRV-Tools-6958d11bc29751e57f350007946d8dca125a8090.tar.gz |
Validate decorations from SPV_KHR_no_integer_wrap (#2271)
Validates NoSignedWrap, NoUnsignedWrap.
We are permissive by allowing any extended instruction.
Diffstat (limited to 'source/val/validate_decorations.cpp')
-rw-r--r-- | source/val/validate_decorations.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/val/validate_decorations.cpp b/source/val/validate_decorations.cpp index 730b7ad7..7f150aaf 100644 --- a/source/val/validate_decorations.cpp +++ b/source/val/validate_decorations.cpp @@ -1180,6 +1180,36 @@ spv_result_t CheckUniformDecoration(ValidationState_t& vstate, return SPV_SUCCESS; } +// Returns SPV_SUCCESS if validation rules are satisfied for NoSignedWrap or +// NoUnsignedWrap decorations. Otherwise emits a diagnostic and returns +// something other than SPV_SUCCESS. Assumes each decoration on a group has been +// propagated down to the group members. +spv_result_t CheckIntegerWrapDecoration(ValidationState_t& vstate, + const Instruction& inst, + const Decoration& decoration) { + switch (inst.opcode()) { + case SpvOpIAdd: + case SpvOpISub: + case SpvOpIMul: + case SpvOpShiftLeftLogical: + case SpvOpSNegate: + return SPV_SUCCESS; + case SpvOpExtInst: + // TODO(dneto): Only certain extended instructions allow these + // decorations. For now allow anything. + return SPV_SUCCESS; + default: + break; + } + + return vstate.diag(SPV_ERROR_INVALID_ID, &inst) + << (decoration.dec_type() == SpvDecorationNoSignedWrap + ? "NoSignedWrap" + : "NoUnsignedWrap") + << " decoration may not be applied to " + << spvOpcodeString(inst.opcode()); +} + #define PASS_OR_BAIL_AT_LINE(X, LINE) \ { \ spv_result_t e##LINE = (X); \ @@ -1216,6 +1246,10 @@ spv_result_t CheckDecorationsFromDecoration(ValidationState_t& vstate) { case SpvDecorationUniform: PASS_OR_BAIL(CheckUniformDecoration(vstate, *inst, decoration)); break; + case SpvDecorationNoSignedWrap: + case SpvDecorationNoUnsignedWrap: + PASS_OR_BAIL(CheckIntegerWrapDecoration(vstate, *inst, decoration)); + break; default: break; } |