Reject struct vardecls with modifiers.

These aren't allowed in GLSL, and typically don't make sense.

Change-Id: I0afca0df638590466922a809e91ef0be35b13ca8
Bug: skia:10765
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324816
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2020-10-09 17:42:31 -04:00 committed by Skia Commit-Bot
parent 61003cde76
commit 13fc260c70
4 changed files with 29 additions and 3 deletions

View File

@ -99,6 +99,7 @@ sksl_error_tests = [
"$_tests/sksl/errors/InvalidAssignment.sksl",
"$_tests/sksl/errors/InvalidOutParams.sksl",
"$_tests/sksl/errors/InvalidUnary.sksl",
"$_tests/sksl/errors/ModifiersInStruct.sksl",
"$_tests/sksl/errors/OpenArray.sksl",
"$_tests/sksl/errors/ReturnDifferentType.sksl",
"$_tests/sksl/errors/ReturnFromVoid.sksl",

View File

@ -503,9 +503,18 @@ ASTNode::ID Parser::structDeclaration() {
return ASTNode::ID::Invalid();
}
ASTNode& declsNode = getNode(decls);
Modifiers modifiers = declsNode.begin()->getModifiers();
if (modifiers.fFlags != Modifiers::kNo_Flag) {
String desc = modifiers.description();
desc.pop_back(); // remove trailing space
this->error(declsNode.fOffset,
"modifier '" + desc + "' is not permitted on a struct field");
}
const Symbol* symbol = fSymbols[(declsNode.begin() + 1)->getTypeData().fName];
SkASSERT(symbol && symbol->kind() == Symbol::Kind::kType);
const Type* type = (const Type*) symbol;
SkASSERT(symbol);
const Type* type = &symbol->as<Type>();
for (auto iter = declsNode.begin() + 2; iter != declsNode.end(); ++iter) {
ASTNode& var = *iter;
ASTNode::VarData vd = var.getVarData();
@ -521,7 +530,8 @@ ASTNode::ID Parser::structDeclaration() {
std::make_unique<Type>(typeName, Type::TypeKind::kArray, *type,
(int)columns));
}
fields.push_back(Type::Field(declsNode.begin()->getModifiers(), vd.fName, type));
fields.push_back(Type::Field(modifiers, vd.fName, type));
if (vd.fSizeCount ? (var.begin() + (vd.fSizeCount - 1))->fNext : var.fFirstChild) {
this->error(declsNode.fOffset, "initializers are not permitted on struct fields");
}

View File

@ -0,0 +1,7 @@
struct S {
const float a;
uniform int b;
flat half4 c;
noperspective float4 d;
inout volatile restrict varying buffer coherent bool e;
};

View File

@ -0,0 +1,8 @@
### Compilation failed:
error: 1: modifier 'const' is not permitted on a struct field
error: 1: modifier 'uniform' is not permitted on a struct field
error: 1: modifier 'flat' is not permitted on a struct field
error: 1: modifier 'noperspective' is not permitted on a struct field
error: 1: modifier 'coherent volatile restrict buffer varying inout' is not permitted on a struct field
5 errors