Skip to content

Commit 236bf64

Browse files
authored
Allow OpPoisonKHR as a constituent (KhronosGroup#6713)
Spec change: KhronosGroup/SPIRV-Registry#417
1 parent bf3ad6e commit 236bf64

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

source/opcode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ int32_t spvOpcodeIsConstant(const spv::Op opcode) {
164164
}
165165

166166
bool spvOpcodeIsConstantOrUndef(const spv::Op opcode) {
167-
return opcode == spv::Op::OpUndef || spvOpcodeIsConstant(opcode);
167+
return opcode == spv::Op::OpUndef || opcode == spv::Op::OpPoisonKHR ||
168+
spvOpcodeIsConstant(opcode);
168169
}
169170

170171
int32_t spvOpcodeIsComposite(const spv::Op opcode) {

source/val/validate_constants.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ spv_result_t ValidateConstantOperand(ValidationState_t& _,
5050
const bool is_constant = spvOpcodeIsConstantOrUndef(operand_opcode);
5151
const bool is_spec_constant = spvOpcodeIsSpecConstant(operand_opcode);
5252
if (!is_constant) {
53-
// All operands must be constant or undef.
53+
// All operands must be constant, undef, or poison.
5454
return _.diag(SPV_ERROR_INVALID_ID, inst)
55-
<< opcode_name << " must only have constant or undef operands: <id> "
55+
<< opcode_name
56+
<< " must only have constant, undef, or poison operands: <id> "
5657
<< _.getIdName(operand_id);
5758
} else if (!inst_is_spec_constant && is_spec_constant) {
5859
// Spec constants are only allowed for spec constant opcodes.

test/val/val_constants_test.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ TEST_F(ValidateConstant, ConstantCompositeReplicateNotConstant) {
655655
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
656656
EXPECT_THAT(getDiagnosticString(),
657657
HasSubstr("OpConstantCompositeReplicateEXT must only have "
658-
"constant or undef operands: <id>"));
658+
"constant, undef, or poison operands: <id>"));
659659
}
660660

661661
TEST_F(ValidateConstant, ConstantCompositeSpecOperand) {
@@ -697,9 +697,44 @@ TEST_F(ValidateConstant, ConstantCompositeNotConstant) {
697697
)";
698698
CompileSuccessfully(spirv);
699699
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
700-
EXPECT_THAT(getDiagnosticString(),
701-
HasSubstr("OpConstantComposite must only have constant or undef "
702-
"operands: <id>"));
700+
EXPECT_THAT(
701+
getDiagnosticString(),
702+
HasSubstr("OpConstantComposite must only have constant, undef, or "
703+
"poison operands: <id>"));
704+
}
705+
706+
TEST_F(ValidateConstant, ConstantCompositePoisonConstituentGood) {
707+
std::string spirv =
708+
std::string(
709+
"OpCapability Shader\nOpCapability Linkage\nOpCapability "
710+
"PoisonFreezeKHR\nOpExtension \"SPV_KHR_poison_freeze\"\n"
711+
"OpMemoryModel Logical Simple\n") +
712+
R"(
713+
%int = OpTypeInt 32 1
714+
%int_4 = OpConstant %int 4
715+
%arr = OpTypeArray %int %int_4
716+
%poison = OpPoisonKHR %int
717+
%const_arr = OpConstantComposite %arr %poison %poison %poison %poison
718+
)";
719+
CompileSuccessfully(spirv);
720+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
721+
}
722+
723+
TEST_F(ValidateConstant, SpecConstantCompositePoisonConstituentGood) {
724+
std::string spirv =
725+
std::string(
726+
"OpCapability Shader\nOpCapability Linkage\nOpCapability "
727+
"PoisonFreezeKHR\nOpExtension \"SPV_KHR_poison_freeze\"\n"
728+
"OpMemoryModel Logical Simple\n") +
729+
R"(
730+
%int = OpTypeInt 32 1
731+
%int_4 = OpConstant %int 4
732+
%arr = OpTypeArray %int %int_4
733+
%poison = OpPoisonKHR %int
734+
%const_arr = OpSpecConstantComposite %arr %poison %poison %poison %poison
735+
)";
736+
CompileSuccessfully(spirv);
737+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
703738
}
704739

705740
TEST_F(ValidateConstant, ConstantCompositeReplicateNotComposite) {

0 commit comments

Comments
 (0)