OpUndef can appear in type declaration section

This commit is contained in:
Umar Arshad 2016-08-12 14:28:17 -04:00
parent 94912ad1ba
commit b01755a5e2
2 changed files with 21 additions and 3 deletions

View File

@ -122,6 +122,7 @@ bool IsInstructionInLayoutSection(ModuleLayoutSection layout, SpvOp op) {
case SpvOpVariable:
case SpvOpLine:
case SpvOpNoLine:
case SpvOpUndef:
out = true;
break;
default: break;

View File

@ -313,7 +313,7 @@ TEST_F(ValidateLayout, FuncParameterNotImmediatlyAfterFuncBad) {
ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
}
TEST_F(ValidateLayout, InstructionAppearBeforeFunctionDefinition) {
TEST_F(ValidateLayout, OpUndefCanAppearInTypeDeclarationSection) {
string str = R"(
OpCapability Kernel
OpMemoryModel Logical OpenCL
@ -328,8 +328,25 @@ TEST_F(ValidateLayout, InstructionAppearBeforeFunctionDefinition) {
)";
CompileSuccessfully(str);
ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(), StrEq("Undef must appear in a block"));
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateLayout, OpUndefCanAppearInBlock) {
string str = R"(
OpCapability Kernel
OpMemoryModel Logical OpenCL
%voidt = OpTypeVoid
%uintt = OpTypeInt 32 0
%funct = OpTypeFunction %voidt
%func = OpFunction %voidt None %funct
%entry = OpLabel
%udef = OpUndef %uintt
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str);
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateLayout, MissingFunctionEndForFunctionWithBody) {