Fixed fuzzer-discovered bug with interface blocks

While I was in this code, I realized that the setVariable method of
InterfaceBlock was unused and there was therefore no reason to be
storing a pointer instead of a reference.

Bug: oss-fuzz:39000
Change-Id: If7505ba87f4060370cfd32ca2e30c76648965101
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/450446
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
Ethan Nicholas 2021-09-21 09:18:47 -04:00 committed by SkCQ
parent ed2babaf94
commit 2816dcfc67
8 changed files with 31 additions and 26 deletions

View File

@ -109,6 +109,7 @@ sksl_error_tests = [
"/sksl/errors/Ossfuzz38560.sksl",
"/sksl/errors/Ossfuzz38865.sksl",
"/sksl/errors/Ossfuzz38944.sksl",
"/sksl/errors/Ossfuzz39000.sksl",
"/sksl/errors/OverflowFloatLiteral.sksl",
"/sksl/errors/OverflowIntLiteral.sksl",
"/sksl/errors/OverflowInt64Literal.sksl",

View File

@ -0,0 +1,2 @@
q { int y; };
G { int q=_; };

View File

@ -794,7 +794,7 @@ std::unique_ptr<SkSL::InterfaceBlock> IRGenerator::convertInterfaceBlock(const A
}
}
std::unique_ptr<SkSL::InterfaceBlock> result = std::make_unique<SkSL::InterfaceBlock>(
intf.fOffset, var, id.fTypeName, id.fInstanceName, arraySize, symbols);
intf.fOffset, *var, id.fTypeName, id.fInstanceName, arraySize, symbols);
this->scanInterfaceBlock(*result);
return result;
}

View File

@ -285,7 +285,7 @@ std::unique_ptr<ProgramElement> Rehydrator::element() {
skstd::string_view typeName = this->readString();
skstd::string_view instanceName = this->readString();
int arraySize = this->readS8();
return std::make_unique<InterfaceBlock>(/*offset=*/-1, &var->as<Variable>(), typeName,
return std::make_unique<InterfaceBlock>(/*offset=*/-1, var->as<Variable>(), typeName,
instanceName, arraySize, nullptr);
}
case Rehydrator::kVarDeclarations_Command: {

View File

@ -3052,7 +3052,7 @@ SpvId SPIRVCodeGenerator::writeInterfaceBlock(const InterfaceBlock& intf, bool a
intfVar.storage()));
fSPIRVBonusVariables.insert(modifiedVar);
InterfaceBlock modifiedCopy(intf.fOffset,
modifiedVar,
*modifiedVar,
intf.typeName(),
intf.instanceName(),
intf.arraySize(),
@ -3459,7 +3459,7 @@ void SPIRVCodeGenerator::writeUniformBuffer(std::shared_ptr<SymbolTable> topLeve
// Create an interface block object for this global variable.
fUniformBuffer.fInterfaceBlock = std::make_unique<InterfaceBlock>(
/*offset=*/-1, fUniformBuffer.fInnerVariable.get(), kUniformBufferName,
/*offset=*/-1, *fUniformBuffer.fInnerVariable, kUniformBufferName,
kUniformBufferName, /*arraySize=*/0, topLevelSymbolTable);
// Generate an interface block and hold onto its ID.
@ -3528,7 +3528,7 @@ void SPIRVCodeGenerator::addRTFlipUniform(int offset) {
fProgram.fSymbols->add(std::make_unique<Field>(/*offset=*/-1, intfVar, /*field=*/0));
}
InterfaceBlock intf(/*offset=*/-1,
intfVar,
*intfVar,
name,
/*instanceName=*/"",
/*arraySize=*/0,

View File

@ -230,20 +230,22 @@ public:
if (!DSLWriter::Settings().fDSLMarkVarsDeclared) {
DSLWriter::MarkDeclared(var);
}
auto intf = std::make_unique<SkSL::InterfaceBlock>(/*offset=*/-1,
DSLWriter::Var(var), typeName, varName, arraySize, DSLWriter::SymbolTable());
DSLWriter::IRGenerator().scanInterfaceBlock(*intf);
DSLWriter::ProgramElements().push_back(std::move(intf));
if (varName.empty()) {
const std::vector<SkSL::Type::Field>& structFields = structType->fields();
const SkSL::Variable* skslVar = DSLWriter::Var(var);
for (size_t i = 0; i < structFields.size(); ++i) {
DSLWriter::SymbolTable()->add(std::make_unique<SkSL::Field>(/*offset=*/-1,
skslVar,
i));
const SkSL::Variable* skslVar = DSLWriter::Var(var);
if (skslVar) {
auto intf = std::make_unique<SkSL::InterfaceBlock>(/*offset=*/-1,
*skslVar, typeName, varName, arraySize, DSLWriter::SymbolTable());
DSLWriter::IRGenerator().scanInterfaceBlock(*intf);
DSLWriter::ProgramElements().push_back(std::move(intf));
if (varName.empty()) {
const std::vector<SkSL::Type::Field>& structFields = structType->fields();
for (size_t i = 0; i < structFields.size(); ++i) {
DSLWriter::SymbolTable()->add(std::make_unique<SkSL::Field>(/*offset=*/-1,
skslVar,
i));
}
} else {
AddToSymbolTable(var);
}
} else {
AddToSymbolTable(var);
}
GetErrorReporter().reportPendingErrors(pos);
return var;

View File

@ -31,7 +31,7 @@ class InterfaceBlock final : public ProgramElement {
public:
static constexpr Kind kProgramElementKind = Kind::kInterfaceBlock;
InterfaceBlock(int offset, const Variable* var, skstd::string_view typeName,
InterfaceBlock(int offset, const Variable& var, skstd::string_view typeName,
skstd::string_view instanceName, int arraySize,
std::shared_ptr<SymbolTable> typeOwner)
: INHERITED(offset, kProgramElementKind)
@ -42,11 +42,7 @@ public:
, fTypeOwner(std::move(typeOwner)) {}
const Variable& variable() const {
return *fVariable;
}
void setVariable(const Variable* var) {
fVariable = var;
return fVariable;
}
skstd::string_view typeName() const {
@ -66,7 +62,7 @@ public:
}
std::unique_ptr<ProgramElement> clone() const override {
return std::make_unique<InterfaceBlock>(fOffset, &this->variable(), this->typeName(),
return std::make_unique<InterfaceBlock>(fOffset, this->variable(), this->typeName(),
this->instanceName(), this->arraySize(),
SymbolTable::WrapIfBuiltin(this->typeOwner()));
}
@ -91,7 +87,7 @@ public:
}
private:
const Variable* fVariable;
const Variable& fVariable;
skstd::string_view fTypeName;
skstd::string_view fInstanceName;
int fArraySize;

View File

@ -0,0 +1,4 @@
### Compilation failed:
error: 2: expected ';', but found '='
1 error