It is invalid to apply both Restrict and Aliased to the same <id> (#2408)

to fix #2408 - It is invalid to apply both Restrict and Aliased to the same
This commit is contained in:
Sarah 2019-02-21 12:03:52 -05:00 committed by GitHub
parent fde69dcd80
commit 4c43afcade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 5 deletions

View File

@ -1035,6 +1035,10 @@ bool AtMostOncePerMember(SpvDecoration decoration) {
// Returns the string name for |decoration|.
const char* GetDecorationName(SpvDecoration decoration) {
switch (decoration) {
case SpvDecorationAliased:
return "Aliased";
case SpvDecorationRestrict:
return "Restrict";
case SpvDecorationArrayStride:
return "ArrayStride";
case SpvDecorationOffset:
@ -1061,7 +1065,8 @@ spv_result_t CheckDecorationsCompatibility(ValidationState_t& vstate) {
// An Array of pairs where the decorations in the pair cannot both be applied
// to the same id.
static const SpvDecoration mutually_exclusive_per_id[][2] = {
{SpvDecorationBlock, SpvDecorationBufferBlock}};
{SpvDecorationBlock, SpvDecorationBufferBlock},
{SpvDecorationRestrict, SpvDecorationAliased}};
static const auto num_mutually_exclusive_per_id_pairs =
sizeof(mutually_exclusive_per_id) / (2 * sizeof(SpvDecoration));

View File

@ -5151,7 +5151,6 @@ OpFunctionEnd
TEST_F(AggressiveDCETest, ParitallyDeadDecorationGroup) {
const std::string text = R"(
; CHECK: OpDecorate [[grp:%\w+]] Restrict
; CHECK: OpDecorate [[grp]] Aliased
; CHECK: [[grp]] = OpDecorationGroup
; CHECK: OpGroupDecorate [[grp]] [[output:%\w+]]
; CHECK: [[output]] = OpVariable {{%\w+}} Output
@ -5161,7 +5160,6 @@ OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %output
OpExecutionMode %main OriginUpperLeft
OpDecorate %1 Restrict
OpDecorate %1 Aliased
%1 = OpDecorationGroup
OpGroupDecorate %1 %var %output
%void = OpTypeVoid
@ -5185,7 +5183,6 @@ OpFunctionEnd
TEST_F(AggressiveDCETest, ParitallyDeadDecorationGroupDifferentGroupDecorate) {
const std::string text = R"(
; CHECK: OpDecorate [[grp:%\w+]] Restrict
; CHECK: OpDecorate [[grp]] Aliased
; CHECK: [[grp]] = OpDecorationGroup
; CHECK: OpGroupDecorate [[grp]] [[output:%\w+]]
; CHECK-NOT: OpGroupDecorate
@ -5196,7 +5193,6 @@ OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %output
OpExecutionMode %main OriginUpperLeft
OpDecorate %1 Restrict
OpDecorate %1 Aliased
%1 = OpDecorationGroup
OpGroupDecorate %1 %output
OpGroupDecorate %1 %var

View File

@ -5126,6 +5126,37 @@ TEST_F(ValidateDecorations, NoUnsignedWrapExtInstGLSLGood) {
EXPECT_THAT(getDiagnosticString(), Eq(""));
}
TEST_F(ValidateDecorations, AliasedandRestrictBad) {
const std::string body = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpSource GLSL 430
OpMemberDecorate %Output 0 Offset 0
OpDecorate %Output BufferBlock
OpDecorate %dataOutput Restrict
OpDecorate %dataOutput Aliased
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%Output = OpTypeStruct %float
%_ptr_Uniform_Output = OpTypePointer Uniform %Output
%dataOutput = OpVariable %_ptr_Uniform_Output Uniform
%main = OpFunction %void None %3
%5 = OpLabel
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(body.c_str());
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("decorated with both Aliased and Restrict is not allowed"));
}
// TODO(dneto): For NoUnsignedWrap and NoUnsignedWrap, permit
// "OpExtInst for instruction numbers specified in the extended
// instruction-set specifications as accepting this decoration."