Variable pointers cannot be an operand to OpArrayLength

This commit is contained in:
SarahM0 2019-03-18 14:07:36 -04:00
parent 2ac348b5c0
commit da5a780ff9
3 changed files with 53 additions and 5 deletions

View File

@ -21,7 +21,8 @@ set -e
set -x set -x
BUILD_ROOT=$PWD BUILD_ROOT=$PWD
SRC=$PWD/github/SPIRV-Tools SRC=/usr/local/google/home/sarahmashay/Desktop/SPIRV/spirv2
# Get clang-format-5.0.0. # Get clang-format-5.0.0.
# Once kokoro upgrades the Ubuntu VMs, we can use 'apt-get install clang-format' # Once kokoro upgrades the Ubuntu VMs, we can use 'apt-get install clang-format'
@ -30,10 +31,10 @@ tar xf clang-llvm.tar.xz
export PATH=$PWD/clang+llvm-5.0.0-linux-x86_64-ubuntu14.04/bin:$PATH export PATH=$PWD/clang+llvm-5.0.0-linux-x86_64-ubuntu14.04/bin:$PATH
cd $SRC cd $SRC
git clone --depth=1 https://github.com/KhronosGroup/SPIRV-Headers external/spirv-headers # git clone --depth=1 https://github.com/KhronosGroup/SPIRV-Headers external/spirv-headers
git clone --depth=1 https://github.com/google/googletest external/googletest # git clone --depth=1 https://github.com/google/googletest external/googletest
git clone --depth=1 https://github.com/google/effcee external/effcee # git clone --depth=1 https://github.com/google/effcee external/effcee
git clone --depth=1 https://github.com/google/re2 external/re2 # git clone --depth=1 https://github.com/google/re2 external/re2
curl -L http://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format-diff.py -o utils/clang-format-diff.py; curl -L http://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format-diff.py -o utils/clang-format-diff.py;
echo $(date): Check formatting... echo $(date): Check formatting...

View File

@ -1181,6 +1181,21 @@ spv_result_t ValidateArrayLength(ValidationState_t& state,
<< state.getIdName(inst->id()) << "' must be an OpTypeRuntimeArray."; << state.getIdName(inst->id()) << "' must be an OpTypeRuntimeArray.";
} }
const bool uses_variable_pointers =
state.features().variable_pointers ||
state.features().variable_pointers_storage_buffer;
if (!pointer_type ||
((state.addressing_model() == SpvAddressingModelLogical) &&
((!uses_variable_pointers &&
!spvOpcodeReturnsLogicalPointer(pointer->opcode())) ||
(uses_variable_pointers &&
spvOpcodeReturnsLogicalVariablePointer(pointer->opcode()))))) {
return state.diag(SPV_ERROR_INVALID_ID, inst)
<< "A variable pointer with the Logical addressing model cannot"
<< "be an operand to an OpArrayLength instruction";
}
// The array member must the the index of the last element (the run time // The array member must the the index of the last element (the run time
// array). // array).
if (inst->GetOperandAs<uint32_t>(3) != num_of_members - 1) { if (inst->GetOperandAs<uint32_t>(3) != num_of_members - 1) {

View File

@ -2129,6 +2129,38 @@ OpFunctionEnd
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()); EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
} }
TEST_F(ValidateIdWithMessage, OpVariablePointerAsOpArrayLengthOperandBad) {
const std::string spirv = R"(
OpCapability Shader
OpCapability Linkage
OpCapability VariablePointersStorageBuffer
OpExtension "SPV_KHR_variable_pointers"
OpMemoryModel Logical GLSL450
OpDecorate %block Block
OpMemberDecorate %block 0 Offset 0
%void = OpTypeVoid
%int = OpTypeInt 32 0
%run_arr = OpTypeRuntimeArray %int
%block = OpTypeStruct %run_arr
%ptr_ssbo_block = OpTypePointer StorageBuffer %block
%null = OpConstantNull %ptr_ssbo_block
%voidfn = OpTypeFunction %void
%func = OpFunction %void None %voidfn
%entry = OpLabel
%length = OpArrayLength %int %null 0
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(spirv);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("A variable pointer with the Logical addressing model cannot"
"be an operand to an OpArrayLength instruction"));
}
TEST_F(ValidateIdWithMessage, OpVariablePointerNoVariablePointersBad) { TEST_F(ValidateIdWithMessage, OpVariablePointerNoVariablePointersBad) {
const std::string spirv = R"( const std::string spirv = R"(
OpCapability Shader OpCapability Shader