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:
John Stiles 2021-10-13 15:04:32 -04:00 committed by SkCQ
parent 9467361423
commit 64c907c052
25 changed files with 75 additions and 9 deletions

View File

@ -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",

View File

@ -0,0 +1 @@
int isampler2D;

View File

@ -0,0 +1 @@
int sampler;

View File

@ -0,0 +1 @@
int sampler1D;

View File

@ -0,0 +1 @@
int sampler2D;

View File

@ -0,0 +1 @@
int sampler2DRect;

View File

@ -0,0 +1 @@
int sampler3D;

View File

@ -0,0 +1 @@
int samplerExternalOES;

View File

@ -0,0 +1 @@
int subpassInput;

View File

@ -0,0 +1 @@
int subpassInputMS;

View File

@ -0,0 +1 @@
int texture2D;

View File

@ -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() {

View File

@ -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");
}

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'isampler2D'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'sampler'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'sampler1D'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'sampler2D'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'sampler2DRect'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'sampler3D'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'samplerExternalOES'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'subpassInput'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'subpassInputMS'
1 error

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 1: expected an identifier, but found type 'texture2D'
1 error

View File

@ -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

View File

@ -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