SkSL: Ensure struct declarations contain at least one member
Bug: skia:11314 Change-Id: I66476543462ae378a5bfb6cbd902dfa2f5fc45f5 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/369917 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
1f19ce2272
commit
6c3b23fcf3
@ -96,6 +96,7 @@ sksl_error_tests = [
|
||||
"/sksl/errors/DuplicateFunction.sksl",
|
||||
"/sksl/errors/DuplicateOutput.sksl",
|
||||
"/sksl/errors/DuplicateSymbol.sksl",
|
||||
"/sksl/errors/EmptyStruct.sksl",
|
||||
"/sksl/errors/EnumValueMustBeConstInt.sksl",
|
||||
"/sksl/errors/ErrorsInDeadCode.sksl",
|
||||
"/sksl/errors/FloatRemainder.sksl",
|
||||
|
@ -11,6 +11,7 @@ void functionBoth() {
|
||||
}
|
||||
|
||||
struct S {
|
||||
float x;
|
||||
} s;
|
||||
|
||||
void structLeft() {
|
||||
|
1
resources/sksl/errors/EmptyStruct.sksl
Normal file
1
resources/sksl/errors/EmptyStruct.sksl
Normal file
@ -0,0 +1 @@
|
||||
struct S { };
|
@ -1,4 +1,4 @@
|
||||
struct Foo {} bar;
|
||||
struct Foo { float x; } bar;
|
||||
|
||||
void preincrement_matrix() { float4x4 x = float4x4(1); ++x; }
|
||||
void predecrement_vector() { float3 x = float3(1); --x; }
|
||||
|
@ -626,6 +626,11 @@ ASTNode::ID Parser::structDeclaration() {
|
||||
if (!this->expect(Token::Kind::TK_RBRACE, "'}'")) {
|
||||
return ASTNode::ID::Invalid();
|
||||
}
|
||||
if (fields.empty()) {
|
||||
this->error(name.fOffset,
|
||||
"struct '" + this->text(name) + "' must contain at least one field");
|
||||
return ASTNode::ID::Invalid();
|
||||
}
|
||||
std::unique_ptr<Type> newType = Type::MakeStructType(name.fOffset, this->text(name), fields);
|
||||
if (struct_is_too_deeply_nested(*newType, kMaxStructDepth)) {
|
||||
this->error(name.fOffset, "struct '" + this->text(name) + "' is too deeply nested");
|
||||
|
@ -3,13 +3,13 @@
|
||||
error: 2: type mismatch: '*' cannot operate on '<INVALID>', 'int'
|
||||
error: 6: type mismatch: '*' cannot operate on 'int', '<INVALID>'
|
||||
error: 10: type mismatch: '*' cannot operate on '<INVALID>', '<INVALID>'
|
||||
error: 17: type mismatch: '*' cannot operate on 'S', 'int'
|
||||
error: 21: type mismatch: '*' cannot operate on 'int', 'S'
|
||||
error: 25: type mismatch: '*' cannot operate on 'S', 'S'
|
||||
error: 31: type mismatch: '*' cannot operate on 'sampler2D', 'int'
|
||||
error: 35: type mismatch: '*' cannot operate on 'int', 'sampler2D'
|
||||
error: 39: type mismatch: '*' cannot operate on 'sampler2D', 'sampler2D'
|
||||
error: 45: type mismatch: '*' cannot operate on 'int[1]', 'int'
|
||||
error: 49: type mismatch: '*' cannot operate on 'int', 'int[1]'
|
||||
error: 53: type mismatch: '*' cannot operate on 'int[1]', 'int[1]'
|
||||
error: 18: type mismatch: '*' cannot operate on 'S', 'int'
|
||||
error: 22: type mismatch: '*' cannot operate on 'int', 'S'
|
||||
error: 26: type mismatch: '*' cannot operate on 'S', 'S'
|
||||
error: 32: type mismatch: '*' cannot operate on 'sampler2D', 'int'
|
||||
error: 36: type mismatch: '*' cannot operate on 'int', 'sampler2D'
|
||||
error: 40: type mismatch: '*' cannot operate on 'sampler2D', 'sampler2D'
|
||||
error: 46: type mismatch: '*' cannot operate on 'int[1]', 'int'
|
||||
error: 50: type mismatch: '*' cannot operate on 'int', 'int[1]'
|
||||
error: 54: type mismatch: '*' cannot operate on 'int[1]', 'int[1]'
|
||||
12 errors
|
||||
|
4
tests/sksl/errors/EmptyStruct.glsl
Normal file
4
tests/sksl/errors/EmptyStruct.glsl
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: struct 'S' must contain at least one field
|
||||
1 error
|
Loading…
Reference in New Issue
Block a user