Mark private types as invalid in the public symbol table.
Previously, in public code, private types didn't exist anywhere in the symbol table chain, and those names were free for the taking. Now, we register them as invalid types in the public symbol table. This prevents them from being used as variable names, and gives a more explicit error if you try to use them as a type. Change-Id: I9a943bf923639b72cbf36b1acf4b4fbe70982786 Bug: skia:12538 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/459119 Commit-Queue: John Stiles <johnstiles@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
9467361423
commit
64c907c052
@ -637,6 +637,16 @@ sksl_rte_error_tests = [
|
||||
"/sksl/runtime_errors/ProgramTooLarge_NestedLoops.rts",
|
||||
"/sksl/runtime_errors/ProgramTooLarge_SplitLoops.rts",
|
||||
"/sksl/runtime_errors/ProgramTooLarge_StackDepth.rts",
|
||||
"/sksl/runtime_errors/ReservedNameISampler2D.rts",
|
||||
"/sksl/runtime_errors/ReservedNameSampler.rts",
|
||||
"/sksl/runtime_errors/ReservedNameSampler1D.rts",
|
||||
"/sksl/runtime_errors/ReservedNameSampler2D.rts",
|
||||
"/sksl/runtime_errors/ReservedNameSampler2DRect.rts",
|
||||
"/sksl/runtime_errors/ReservedNameSampler3D.rts",
|
||||
"/sksl/runtime_errors/ReservedNameSamplerExternalOES.rts",
|
||||
"/sksl/runtime_errors/ReservedNameSubpassInput.rts",
|
||||
"/sksl/runtime_errors/ReservedNameSubpassInputMS.rts",
|
||||
"/sksl/runtime_errors/ReservedNameTexture2D.rts",
|
||||
"/sksl/runtime_errors/UnsupportedTypeFragmentProcessor.rts",
|
||||
"/sksl/runtime_errors/UnsupportedTypeSampler.rts",
|
||||
"/sksl/runtime_errors/UnsupportedTypeTexture.rts",
|
||||
|
1
resources/sksl/runtime_errors/ReservedNameISampler2D.rts
Normal file
1
resources/sksl/runtime_errors/ReservedNameISampler2D.rts
Normal file
@ -0,0 +1 @@
|
||||
int isampler2D;
|
1
resources/sksl/runtime_errors/ReservedNameSampler.rts
Normal file
1
resources/sksl/runtime_errors/ReservedNameSampler.rts
Normal file
@ -0,0 +1 @@
|
||||
int sampler;
|
1
resources/sksl/runtime_errors/ReservedNameSampler1D.rts
Normal file
1
resources/sksl/runtime_errors/ReservedNameSampler1D.rts
Normal file
@ -0,0 +1 @@
|
||||
int sampler1D;
|
1
resources/sksl/runtime_errors/ReservedNameSampler2D.rts
Normal file
1
resources/sksl/runtime_errors/ReservedNameSampler2D.rts
Normal file
@ -0,0 +1 @@
|
||||
int sampler2D;
|
@ -0,0 +1 @@
|
||||
int sampler2DRect;
|
1
resources/sksl/runtime_errors/ReservedNameSampler3D.rts
Normal file
1
resources/sksl/runtime_errors/ReservedNameSampler3D.rts
Normal file
@ -0,0 +1 @@
|
||||
int sampler3D;
|
@ -0,0 +1 @@
|
||||
int samplerExternalOES;
|
@ -0,0 +1 @@
|
||||
int subpassInput;
|
@ -0,0 +1 @@
|
||||
int subpassInputMS;
|
1
resources/sksl/runtime_errors/ReservedNameTexture2D.rts
Normal file
1
resources/sksl/runtime_errors/ReservedNameTexture2D.rts
Normal file
@ -0,0 +1 @@
|
||||
int texture2D;
|
@ -243,7 +243,7 @@ const ParsedModule& Compiler::loadVertexModule() {
|
||||
}
|
||||
|
||||
static void add_glsl_type_aliases(SkSL::SymbolTable* symbols, const SkSL::BuiltinTypes& types) {
|
||||
// Add some aliases to the runtime effect modules so that it's friendlier, and more like GLSL
|
||||
// Add some aliases to the runtime effect modules so that it's friendlier, and more like GLSL.
|
||||
symbols->addAlias("vec2", types.fFloat2.get());
|
||||
symbols->addAlias("vec3", types.fFloat3.get());
|
||||
symbols->addAlias("vec4", types.fFloat4.get());
|
||||
@ -259,6 +259,12 @@ static void add_glsl_type_aliases(SkSL::SymbolTable* symbols, const SkSL::Builti
|
||||
symbols->addAlias("mat2", types.fFloat2x2.get());
|
||||
symbols->addAlias("mat3", types.fFloat3x3.get());
|
||||
symbols->addAlias("mat4", types.fFloat4x4.get());
|
||||
|
||||
// Alias every private type to "invalid". This will prevent code from using built-in names like
|
||||
// `sampler2D` as variable names.
|
||||
for (BuiltinTypePtr privateType : kPrivateTypes) {
|
||||
symbols->addAlias((types.*privateType)->name(), types.fInvalid.get());
|
||||
}
|
||||
}
|
||||
|
||||
const ParsedModule& Compiler::loadPublicModule() {
|
||||
|
@ -39,6 +39,10 @@ String VarDeclaration::description() const {
|
||||
|
||||
void VarDeclaration::ErrorCheck(const Context& context, int line, const Modifiers& modifiers,
|
||||
const Type* baseType, Variable::Storage storage) {
|
||||
if (*baseType == *context.fTypes.fInvalid) {
|
||||
context.fErrors->error(line, "invalid type");
|
||||
return;
|
||||
}
|
||||
if (context.fConfig->strictES2Mode() && baseType->isArray()) {
|
||||
context.fErrors->error(line, "array size must appear after variable name");
|
||||
}
|
||||
|
4
tests/sksl/runtime_errors/ReservedNameISampler2D.skvm
Normal file
4
tests/sksl/runtime_errors/ReservedNameISampler2D.skvm
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'isampler2D'
|
||||
1 error
|
4
tests/sksl/runtime_errors/ReservedNameSampler.skvm
Normal file
4
tests/sksl/runtime_errors/ReservedNameSampler.skvm
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'sampler'
|
||||
1 error
|
4
tests/sksl/runtime_errors/ReservedNameSampler1D.skvm
Normal file
4
tests/sksl/runtime_errors/ReservedNameSampler1D.skvm
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'sampler1D'
|
||||
1 error
|
4
tests/sksl/runtime_errors/ReservedNameSampler2D.skvm
Normal file
4
tests/sksl/runtime_errors/ReservedNameSampler2D.skvm
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'sampler2D'
|
||||
1 error
|
4
tests/sksl/runtime_errors/ReservedNameSampler2DRect.skvm
Normal file
4
tests/sksl/runtime_errors/ReservedNameSampler2DRect.skvm
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'sampler2DRect'
|
||||
1 error
|
4
tests/sksl/runtime_errors/ReservedNameSampler3D.skvm
Normal file
4
tests/sksl/runtime_errors/ReservedNameSampler3D.skvm
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'sampler3D'
|
||||
1 error
|
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'samplerExternalOES'
|
||||
1 error
|
4
tests/sksl/runtime_errors/ReservedNameSubpassInput.skvm
Normal file
4
tests/sksl/runtime_errors/ReservedNameSubpassInput.skvm
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'subpassInput'
|
||||
1 error
|
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'subpassInputMS'
|
||||
1 error
|
4
tests/sksl/runtime_errors/ReservedNameTexture2D.skvm
Normal file
4
tests/sksl/runtime_errors/ReservedNameTexture2D.skvm
Normal file
@ -0,0 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: expected an identifier, but found type 'texture2D'
|
||||
1 error
|
@ -1,6 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: no type named 'sampler2D'
|
||||
error: 1: no type named 's'
|
||||
error: 1: expected a declaration, but found ';'
|
||||
3 errors
|
||||
error: 1: invalid type
|
||||
1 error
|
||||
|
@ -1,6 +1,4 @@
|
||||
### Compilation failed:
|
||||
|
||||
error: 1: no type named 'texture2D'
|
||||
error: 1: no type named 's'
|
||||
error: 1: expected a declaration, but found ';'
|
||||
3 errors
|
||||
error: 1: invalid type
|
||||
1 error
|
||||
|
Loading…
Reference in New Issue
Block a user