fixed SkSL crash when performing binary operations on invalid types
Change-Id: If29ee048d359d0ccd7b0ab708f54d40746b92386 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/343423 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Auto-Submit: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
86424eb0cf
commit
29339074e4
@ -81,6 +81,7 @@ sksl_error_tests = [
|
||||
"$_tests/sksl/errors/BadFieldAccess.sksl",
|
||||
"$_tests/sksl/errors/BadIndex.sksl",
|
||||
"$_tests/sksl/errors/BadModifiers.sksl",
|
||||
"$_tests/sksl/errors/BinaryInvalidType.sksl",
|
||||
"$_tests/sksl/errors/BinaryTypeCoercion.sksl",
|
||||
"$_tests/sksl/errors/BinaryTypeMismatch.sksl",
|
||||
"$_tests/sksl/errors/BitShiftFloat.sksl",
|
||||
|
@ -1647,8 +1647,8 @@ static bool determine_binary_type(const Context& context,
|
||||
|
||||
// Boolean types only support the operators listed above (, = == != || && ^^).
|
||||
// If we've gotten this far with a boolean, we have an unsupported operator.
|
||||
const Type& leftComponentType(left.columns() > 1 ? left.componentType() : left);
|
||||
const Type& rightComponentType(right.columns() > 1 ? right.componentType() : right);
|
||||
const Type& leftComponentType = left.componentType();
|
||||
const Type& rightComponentType = right.componentType();
|
||||
if (leftComponentType.isBoolean() || rightComponentType.isBoolean()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -351,11 +351,13 @@ public:
|
||||
|
||||
/**
|
||||
* For matrices and vectors, returns the type of individual cells (e.g. mat2 has a component
|
||||
* type of kFloat_Type). For all other types, causes an SkASSERTion failure.
|
||||
* type of kFloat_Type). For all other types, returns the type itself.
|
||||
*/
|
||||
const Type& componentType() const {
|
||||
SkASSERT(fComponentType);
|
||||
return *fComponentType;
|
||||
if (fComponentType) {
|
||||
return *fComponentType;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
54
tests/sksl/errors/BinaryInvalidType.sksl
Normal file
54
tests/sksl/errors/BinaryInvalidType.sksl
Normal file
@ -0,0 +1,54 @@
|
||||
void functionLeft() {
|
||||
float x = functionLeft * 2;
|
||||
}
|
||||
|
||||
void functionRight() {
|
||||
float x = 2 * functionRight;
|
||||
}
|
||||
|
||||
void functionBoth() {
|
||||
float x = functionBoth * functionBoth;
|
||||
}
|
||||
|
||||
struct S {
|
||||
} s;
|
||||
|
||||
void structLeft() {
|
||||
float x = s * 2;
|
||||
}
|
||||
|
||||
void structRight() {
|
||||
float x = 2 * s;
|
||||
}
|
||||
|
||||
void structBoth() {
|
||||
float x = s * s;
|
||||
}
|
||||
|
||||
sampler2D smp;
|
||||
|
||||
void samplerLeft() {
|
||||
float x = smp * 2;
|
||||
}
|
||||
|
||||
void samplerRight() {
|
||||
float x = 2 * smp;
|
||||
}
|
||||
|
||||
void samplerBoth() {
|
||||
float x = smp * smp;
|
||||
}
|
||||
|
||||
int array[1];
|
||||
|
||||
void arrayLeft() {
|
||||
float x = array * 2;
|
||||
}
|
||||
|
||||
void arrayRight() {
|
||||
float x = 2 * array;
|
||||
}
|
||||
|
||||
void arrayBoth() {
|
||||
float x = array * array;
|
||||
}
|
15
tests/sksl/errors/golden/BinaryInvalidType.glsl
Normal file
15
tests/sksl/errors/golden/BinaryInvalidType.glsl
Normal file
@ -0,0 +1,15 @@
|
||||
### Compilation failed:
|
||||
|
||||
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]'
|
||||
12 errors
|
Loading…
Reference in New Issue
Block a user