Commit 76bf01d7 by Qin Jiajia Committed by Commit Bot

Fix that readonly buffer variable can be assigned

This change will add memory qualifier checking for binaryNode in case the memory qualifier information is lost. BUG=angleproject:1951 TEST=angle_unittests Change-Id: I3f0cfd7d8a059753cf3c982ee0a977b4b0fd0128 Reviewed-on: https://chromium-review.googlesource.com/929877 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent e41df655
...@@ -496,6 +496,11 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn ...@@ -496,6 +496,11 @@ bool TParseContext::checkCanBeLValue(const TSourceLoc &line, const char *op, TIn
case EOpIndexIndirect: case EOpIndexIndirect:
case EOpIndexDirectStruct: case EOpIndexDirectStruct:
case EOpIndexDirectInterfaceBlock: case EOpIndexDirectInterfaceBlock:
if (node->getMemoryQualifier().readonly)
{
error(line, "can't modify a readonly variable", op);
return false;
}
return checkCanBeLValue(line, op, binaryNode->getLeft()); return checkCanBeLValue(line, op, binaryNode->getLeft());
default: default:
break; break;
......
...@@ -205,6 +205,66 @@ TEST_F(BufferVariablesTest, AssignToBufferVariableWithinReadonlyBlock) ...@@ -205,6 +205,66 @@ TEST_F(BufferVariablesTest, AssignToBufferVariableWithinReadonlyBlock)
} }
} }
// Test that can't assign to a readonly buffer variable through an instance name.
TEST_F(BufferVariablesTest, AssignToReadonlyBufferVariableByInstanceName)
{
const std::string &source =
R"(#version 310 es
layout(binding = 3) buffer buf {
readonly float f;
} instanceBuffer;
void main()
{
instanceBuffer.f += 0.2;
})";
if (compile(source))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that can't assign to a readonly struct buffer variable.
TEST_F(BufferVariablesTest, AssignToReadonlyStructBufferVariable)
{
const std::string &source =
R"(#version 310 es
struct S {
float f;
};
layout(binding = 3) buffer buf {
readonly S s;
};
void main()
{
s.f += 0.2;
})";
if (compile(source))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that can't assign to a readonly struct buffer variable through an instance name.
TEST_F(BufferVariablesTest, AssignToReadonlyStructBufferVariableByInstanceName)
{
const std::string &source =
R"(#version 310 es
struct S {
float f;
};
layout(binding = 3) buffer buf {
readonly S s;
} instanceBuffer;
void main()
{
instanceBuffer.s.f += 0.2;
})";
if (compile(source))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that a readonly and writeonly buffer variable should neither read or write. // Test that a readonly and writeonly buffer variable should neither read or write.
TEST_F(BufferVariablesTest, AccessReadonlyWriteonlyBufferVariable) TEST_F(BufferVariablesTest, AccessReadonlyWriteonlyBufferVariable)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment