diff --git a/source/val/validate_decorations.cpp b/source/val/validate_decorations.cpp index 0d2ad10462..03d9a324a9 100644 --- a/source/val/validate_decorations.cpp +++ b/source/val/validate_decorations.cpp @@ -773,14 +773,16 @@ spv_result_t CheckDecorationsOfEntryPoints(ValidationState_t& vstate) { std::unordered_set output_var_builtin; for (auto interface : desc.interfaces) { Instruction* var_instr = vstate.FindDef(interface); - if (!var_instr || (spv::Op::OpVariable != var_instr->opcode() && - spv::Op::OpUntypedVariableKHR != var_instr->opcode())) { + if (!var_instr || + (spv::Op::OpVariable != var_instr->opcode() && + spv::Op::OpUntypedVariableKHR != var_instr->opcode())) { return vstate.diag(SPV_ERROR_INVALID_ID, var_instr) << "Interfaces passed to OpEntryPoint must be variables. " "Found Op" << spvOpcodeString(var_instr->opcode()) << "."; } - const bool untyped_pointers = var_instr->opcode() == spv::Op::OpUntypedVariableKHR; + const bool untyped_pointers = + var_instr->opcode() == spv::Op::OpUntypedVariableKHR; const auto sc_index = 2u; const spv::StorageClass storage_class = var_instr->GetOperandAs(sc_index); @@ -891,9 +893,11 @@ spv_result_t CheckDecorationsOfEntryPoints(ValidationState_t& vstate) { << "Untyped workgroup variables in shaders must be " "block decorated"; } - if (hasDecoration(var_instr->id(), spv::Decoration::Aliased, vstate)) + if (hasDecoration(var_instr->id(), spv::Decoration::Aliased, + vstate)) ++num_workgroup_variables_with_aliased; - } else if (untyped_pointers && vstate.HasCapability(spv::Capability::Shader)) { + } else if (untyped_pointers && + vstate.HasCapability(spv::Capability::Shader)) { return vstate.diag(SPV_ERROR_INVALID_ID, var_instr) << "Untyped workgroup variables in shaders must be block " "decorated structs"; @@ -1114,7 +1118,8 @@ spv_result_t CheckDecorationsOfBuffers(ValidationState_t& vstate) { MemberConstraints constraints; if (spv::Op::OpVariable == inst.opcode() || spv::Op::OpUntypedVariableKHR == inst.opcode()) { - const bool untyped_pointer = inst.opcode() == spv::Op::OpUntypedVariableKHR; + const bool untyped_pointer = + inst.opcode() == spv::Op::OpUntypedVariableKHR; const auto var_id = inst.id(); // For storage class / decoration combinations, see Vulkan 14.5.4 "Offset // and Stride Assignment". @@ -1386,9 +1391,9 @@ spv_result_t CheckDecorationsOfBuffers(ValidationState_t& vstate) { ComputeMemberConstraintsForStruct(&constraints, pointee_type_id, LayoutConstraints(), vstate); } - if (auto res = checkLayout(pointee_type_id, "PhysicalStorageBuffer", "Block", - !buffer, scalar_block_layout, 0, constraints, - vstate)) { + if (auto res = checkLayout(pointee_type_id, "PhysicalStorageBuffer", + "Block", !buffer, scalar_block_layout, 0, + constraints, vstate)) { return res; } } else if (vstate.HasCapability(spv::Capability::UntypedPointersKHR) && diff --git a/source/val/validate_function.cpp b/source/val/validate_function.cpp index 3780a4b39b..26b3668282 100644 --- a/source/val/validate_function.cpp +++ b/source/val/validate_function.cpp @@ -157,7 +157,8 @@ spv_result_t ValidateFunctionParameter(ValidationState_t& _, _.FindDef(param_nonarray_type_id)->GetOperandAs(1u); } if (_.GetIdOpcode(param_nonarray_type_id) == spv::Op::OpTypePointer || - _.GetIdOpcode(param_nonarray_type_id) == spv::Op::OpTypeUntypedPointerKHR) { + _.GetIdOpcode(param_nonarray_type_id) == + spv::Op::OpTypeUntypedPointerKHR) { auto param_nonarray_type = _.FindDef(param_nonarray_type_id); if (param_nonarray_type->GetOperandAs(1u) == spv::StorageClass::PhysicalStorageBuffer) { diff --git a/source/val/validate_image.cpp b/source/val/validate_image.cpp index 27b8728bd1..aadc264e02 100644 --- a/source/val/validate_image.cpp +++ b/source/val/validate_image.cpp @@ -1138,7 +1138,8 @@ spv_result_t ValidateImageTexelPointer(ValidationState_t& _, if (result_type->opcode() == spv::Op::OpTypePointer) { ptr_type = result_type->GetOperandAs(2); const auto ptr_opcode = _.GetIdOpcode(ptr_type); - if (ptr_opcode != spv::Op::OpTypeInt && ptr_opcode != spv::Op::OpTypeFloat && + if (ptr_opcode != spv::Op::OpTypeInt && + ptr_opcode != spv::Op::OpTypeFloat && ptr_opcode != spv::Op::OpTypeVoid && !(ptr_opcode == spv::Op::OpTypeVector && _.HasCapability(spv::Capability::AtomicFloat16VectorNV) && diff --git a/source/val/validate_logicals.cpp b/source/val/validate_logicals.cpp index f10de97020..8a2e5d8c42 100644 --- a/source/val/validate_logicals.cpp +++ b/source/val/validate_logicals.cpp @@ -162,7 +162,8 @@ spv_result_t LogicalsPass(ValidationState_t& _, const Instruction* inst) { case spv::Op::OpTypeUntypedPointerKHR: case spv::Op::OpTypePointer: { if (_.addressing_model() == spv::AddressingModel::Logical && - !_.HasCapability(spv::Capability::VariablePointersStorageBuffer)) + !_.HasCapability( + spv::Capability::VariablePointersStorageBuffer)) return _.diag(SPV_ERROR_INVALID_DATA, inst) << "Using pointers with OpSelect requires capability " << "VariablePointers or VariablePointersStorageBuffer"; diff --git a/source/val/validate_memory.cpp b/source/val/validate_memory.cpp index 1b1bec65f4..75dcd3c286 100644 --- a/source/val/validate_memory.cpp +++ b/source/val/validate_memory.cpp @@ -411,7 +411,8 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) { auto result_type = _.FindDef(inst->type_id()); if (untyped_pointer) { - if (!result_type || result_type->opcode() != spv::Op::OpTypeUntypedPointerKHR) + if (!result_type || + result_type->opcode() != spv::Op::OpTypeUntypedPointerKHR) return _.diag(SPV_ERROR_INVALID_ID, inst) << "Result type must be an untyped pointer"; } else { @@ -975,8 +976,9 @@ spv_result_t ValidateLoad(ValidationState_t& _, const Instruction* inst) { } const auto pointer_type = _.FindDef(pointer->type_id()); - if (!pointer_type || (pointer_type->opcode() != spv::Op::OpTypePointer && - pointer_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)) { + if (!pointer_type || + (pointer_type->opcode() != spv::Op::OpTypePointer && + pointer_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)) { return _.diag(SPV_ERROR_INVALID_ID, inst) << "OpLoad type for pointer " << _.getIdName(pointer_id) << " is not a pointer type."; @@ -1033,8 +1035,9 @@ spv_result_t ValidateStore(ValidationState_t& _, const Instruction* inst) { << " is not a logical pointer."; } const auto pointer_type = _.FindDef(pointer->type_id()); - if (!pointer_type || (pointer_type->opcode() != spv::Op::OpTypePointer && - pointer_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)) { + if (!pointer_type || + (pointer_type->opcode() != spv::Op::OpTypePointer && + pointer_type->opcode() != spv::Op::OpTypeUntypedPointerKHR)) { return _.diag(SPV_ERROR_INVALID_ID, inst) << "OpStore type for pointer " << _.getIdName(pointer_id) << " is not a pointer type."; @@ -1126,7 +1129,8 @@ spv_result_t ValidateStore(ValidationState_t& _, const Instruction* inst) { } if (type && (type->id() != object_type->id())) { - if (!_.options()->relax_struct_store || type->opcode() != spv::Op::OpTypeStruct || + if (!_.options()->relax_struct_store || + type->opcode() != spv::Op::OpTypeStruct || object_type->opcode() != spv::Op::OpTypeStruct) { return _.diag(SPV_ERROR_INVALID_ID, inst) << "OpStore Pointer " << _.getIdName(pointer_id) @@ -1246,8 +1250,10 @@ spv_result_t ValidateCopyMemory(ValidationState_t& _, const Instruction* inst) { } if (inst->opcode() == spv::Op::OpCopyMemory) { - const bool target_typed = target_pointer_type->opcode() == spv::Op::OpTypePointer; - const bool source_typed = source_pointer_type->opcode() == spv::Op::OpTypePointer; + const bool target_typed = + target_pointer_type->opcode() == spv::Op::OpTypePointer; + const bool source_typed = + source_pointer_type->opcode() == spv::Op::OpTypePointer; Instruction* target_type = nullptr; Instruction* source_type = nullptr; if (target_typed) { @@ -1458,7 +1464,8 @@ spv_result_t ValidateAccessChain(ValidationState_t& _, // OpTypeUntypedPointerKHR for untyped access chains. auto result_type = _.FindDef(inst->type_id()); if (untyped_pointer) { - if (!result_type || spv::Op::OpTypeUntypedPointerKHR != result_type->opcode()) { + if (!result_type || + spv::Op::OpTypeUntypedPointerKHR != result_type->opcode()) { return _.diag(SPV_ERROR_INVALID_ID, inst) << "The Result Type of " << instr_name << " " << _.getIdName(inst->id()) @@ -2077,7 +2084,8 @@ spv_result_t ValidateCooperativeMatrixLoadStoreKHR(ValidationState_t& _, << " is not a pointer type."; } - const bool untyped = pointer_type->opcode() == spv::Op::OpTypeUntypedPointerKHR; + const bool untyped = + pointer_type->opcode() == spv::Op::OpTypeUntypedPointerKHR; const auto storage_class_index = 1u; const auto storage_class = pointer_type->GetOperandAs(storage_class_index); diff --git a/source/val/validate_type.cpp b/source/val/validate_type.cpp index d2609357f0..32024b7356 100644 --- a/source/val/validate_type.cpp +++ b/source/val/validate_type.cpp @@ -591,7 +591,8 @@ spv_result_t ValidateTypeUntypedPointerKHR(ValidationState_t& _, const auto sc = inst->GetOperandAs(1); switch (sc) { case spv::StorageClass::Workgroup: - if (!_.HasCapability(spv::Capability::WorkgroupMemoryExplicitLayoutKHR)) { + if (!_.HasCapability( + spv::Capability::WorkgroupMemoryExplicitLayoutKHR)) { return _.diag(SPV_ERROR_INVALID_ID, inst) << "Workgroup storage class untyped pointers in Vulkan " "require WorkgroupMemoryExplicitLayoutKHR be declared"; diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp index 3f50cb73c9..e00280613d 100644 --- a/source/val/validation_state.cpp +++ b/source/val/validation_state.cpp @@ -1700,12 +1700,9 @@ bool ValidationState_t::ContainsRuntimeArray(uint32_t id) const { bool ValidationState_t::ContainsUntypedPointer(uint32_t id) const { const auto inst = FindDef(id); - if (!inst) - return false; - if (!spvOpcodeGeneratesType(inst->opcode())) - return false; - if (inst->opcode() == spv::Op::OpTypeUntypedPointerKHR) - return true; + if (!inst) return false; + if (!spvOpcodeGeneratesType(inst->opcode())) return false; + if (inst->opcode() == spv::Op::OpTypeUntypedPointerKHR) return true; switch (inst->opcode()) { case spv::Op::OpTypeArray: diff --git a/test/text_to_binary.extension_test.cpp b/test/text_to_binary.extension_test.cpp index 8f3cf1f1bd..59f2af9e79 100644 --- a/test/text_to_binary.extension_test.cpp +++ b/test/text_to_binary.extension_test.cpp @@ -1357,12 +1357,14 @@ INSTANTIATE_TEST_SUITE_P( MakeInstruction(spv::Op::OpUntypedAccessChainKHR, {1, 2, 3, 4, 5, 6, 7})}, {"%2 = OpUntypedInBoundsAccessChainKHR %1 %3 %4\n", - MakeInstruction(spv::Op::OpUntypedInBoundsAccessChainKHR, {1, 2, 3, 4})}, + MakeInstruction(spv::Op::OpUntypedInBoundsAccessChainKHR, + {1, 2, 3, 4})}, {"%2 = OpUntypedInBoundsAccessChainKHR %1 %3 %4 %5 %6 %7\n", MakeInstruction(spv::Op::OpUntypedInBoundsAccessChainKHR, {1, 2, 3, 4, 5, 6, 7})}, {"%2 = OpUntypedPtrAccessChainKHR %1 %3 %4 %5\n", - MakeInstruction(spv::Op::OpUntypedPtrAccessChainKHR, {1, 2, 3, 4, 5})}, + MakeInstruction(spv::Op::OpUntypedPtrAccessChainKHR, + {1, 2, 3, 4, 5})}, {"%2 = OpUntypedPtrAccessChainKHR %1 %3 %4 %5 %6 %7\n", MakeInstruction(spv::Op::OpUntypedPtrAccessChainKHR, {1, 2, 3, 4, 5, 6, 7})}, diff --git a/test/val/val_decoration_test.cpp b/test/val/val_decoration_test.cpp index 56f592201f..99694df1fb 100644 --- a/test/val/val_decoration_test.cpp +++ b/test/val/val_decoration_test.cpp @@ -10155,7 +10155,8 @@ OpDecorate %var Binding 0 %void = OpTypeVoid %int = OpTypeInt 32 0 %struct = OpTypeStruct %int -%ptr = OpTypeUntypedPointerKHR )" + sc + R"( +%ptr = OpTypeUntypedPointerKHR )" + + sc + R"( %var = OpUntypedVariableKHR %ptr )" + sc + R"( %struct %void_fn = OpTypeFunction %void %main = OpFunction %void None %void_fn @@ -10188,7 +10189,8 @@ OpDecorate %var DescriptorSet 0 %void = OpTypeVoid %int = OpTypeInt 32 0 %struct = OpTypeStruct %int -%ptr = OpTypeUntypedPointerKHR )" + sc + R"( +%ptr = OpTypeUntypedPointerKHR )" + + sc + R"( %var = OpUntypedVariableKHR %ptr )" + sc + R"( %struct %void_fn = OpTypeFunction %void %main = OpFunction %void None %void_fn @@ -10242,7 +10244,8 @@ OpMemberDecorate %test_type 1 Offset 1 %struct = OpTypeStruct %int %int %test_type = OpTypeStruct %int %int %test_val = OpConstantNull %test_type -%ptr = OpTypeUntypedPointerKHR )" + sc + R"( +%ptr = OpTypeUntypedPointerKHR )" + + sc + R"( %var = OpUntypedVariableKHR %ptr )" + sc + R"( %struct %void_fn = OpTypeFunction %void %main = OpFunction %void None %void_fn @@ -10294,7 +10297,8 @@ OpMemberDecorate %struct 1 Offset 4 %test_type = OpTypeArray %int4 %int_4 %test_val = OpConstantNull %test_type %struct = OpTypeStruct %int %int -%ptr = OpTypeUntypedPointerKHR )" + sc + R"( +%ptr = OpTypeUntypedPointerKHR )" + + sc + R"( %var = OpUntypedVariableKHR %ptr )" + sc + R"( %struct %void_fn = OpTypeFunction %void %main = OpFunction %void None %void_fn diff --git a/test/val/val_fixtures.h b/test/val/val_fixtures.h index 71dcc7ce10..db9d0452e1 100644 --- a/test/val/val_fixtures.h +++ b/test/val/val_fixtures.h @@ -76,9 +76,7 @@ class ValidateBase : public ::testing::Test, diagnostic_ = nullptr; } - void SetAssembleOptions(uint32_t options) { - assemble_options_ = options; - } + void SetAssembleOptions(uint32_t options) { assemble_options_ = options; } std::string getDiagnosticString(); spv_position_t getErrorPosition(); diff --git a/test/val/val_function_test.cpp b/test/val/val_function_test.cpp index 9e39f69d16..119edd3e6c 100644 --- a/test/val/val_function_test.cpp +++ b/test/val/val_function_test.cpp @@ -903,7 +903,8 @@ OpFunctionEnd EXPECT_EQ(SPV_SUCCESS, ValidateInstructions()); } -TEST_F(ValidateFunctionCall, UntypedPointerParameterNotMemoryObjectDeclaration) { +TEST_F(ValidateFunctionCall, + UntypedPointerParameterNotMemoryObjectDeclaration) { const std::string spirv = R"( OpCapability Shader OpCapability UntypedPointersKHR @@ -938,7 +939,8 @@ OpFunctionEnd EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); EXPECT_THAT( getDiagnosticString(), - HasSubstr("Pointer operand '3[%gep]' must be a memory object declaration")); + HasSubstr( + "Pointer operand '3[%gep]' must be a memory object declaration")); } INSTANTIATE_TEST_SUITE_P(StorageClass, ValidateFunctionCall, diff --git a/test/val/val_id_test.cpp b/test/val/val_id_test.cpp index a2d752255d..1e050183b2 100644 --- a/test/val/val_id_test.cpp +++ b/test/val/val_id_test.cpp @@ -1199,7 +1199,8 @@ OpMemoryModel Logical GLSL450 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4)); } -TEST_P(ValidateIdWithMessage, OpTypeUntypedPointerWorkgroupMissingExplicitLayout) { +TEST_P(ValidateIdWithMessage, + OpTypeUntypedPointerWorkgroupMissingExplicitLayout) { const std::string spirv = R"( OpCapability Shader OpCapability UntypedPointersKHR