Commit 014b9a60 by Nicolas Capens Committed by nicolascapens

Fix crash caused by missing shader function definition and report the error.

BUG=17956386 Change-Id: I89f243b557b70401052b1f7db237fbc410386f64 Reviewed-on: https://swiftshader-review.googlesource.com/1190Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: <nicolascapens@google.com> Reviewed-by: <nicolascapens@google.com>
parent bbcc4e10
......@@ -121,7 +121,7 @@ bool TCompiler::compile(const char* const shaderStrings[],
intermediate.outputTree(root);
if (success && (compileOptions & SH_OBJECT_CODE))
translate(root);
success = translate(root);
}
// Cleanup memory.
......
......@@ -670,9 +670,10 @@ namespace sh
Instruction *label = emit(sw::Shader::OPCODE_LABEL);
label->dst.type = sw::Shader::PARAMETER_LABEL;
const Function &function = findFunction(name);
label->dst.index = function.label;
currentFunction = function.label;
const Function *function = findFunction(name);
ASSERT(function); // Should have been added during global pass
label->dst.index = function->label;
currentFunction = function->label;
}
}
else if(emitScope == GLOBAL)
......@@ -706,8 +707,15 @@ namespace sh
if(node->isUserDefined())
{
const TString &name = node->getName();
const Function &function = findFunction(name);
TIntermSequence &arguments = *function.arg;
const Function *function = findFunction(name);
if(!function)
{
mContext.error(node->getLine(), "function definition not found", name.c_str());
return false;
}
TIntermSequence &arguments = *function->arg;
for(int i = 0; i < argumentCount; i++)
{
......@@ -723,11 +731,11 @@ namespace sh
Instruction *call = emit(sw::Shader::OPCODE_CALL);
call->dst.type = sw::Shader::PARAMETER_LABEL;
call->dst.index = function.label;
call->dst.index = function->label;
if(function.ret && function.ret->getType().getBasicType() != EbtVoid)
if(function->ret && function->ret->getType().getBasicType() != EbtVoid)
{
copy(result, function.ret);
copy(result, function->ret);
}
for(int i = 0; i < argumentCount; i++)
......@@ -1907,18 +1915,17 @@ namespace sh
return -1;
}
const Function &OutputASM::findFunction(const TString &name)
const Function *OutputASM::findFunction(const TString &name)
{
for(unsigned int f = 0; f < functionArray.size(); f++)
{
if(functionArray[f].name == name)
{
return functionArray[f];
return &functionArray[f];
}
}
UNREACHABLE();
return functionArray[0];
return 0;
}
int OutputASM::temporaryRegister(TIntermTyped *temporary)
......
......@@ -121,7 +121,7 @@ namespace sh
int readSwizzle(TIntermTyped *argument, int size);
bool trivial(TIntermTyped *expression, int budget); // Fast to compute and no side effects
int cost(TIntermNode *expression, int budget);
const Function &findFunction(const TString &name);
const Function *findFunction(const TString &name);
int temporaryRegister(TIntermTyped *temporary);
int varyingRegister(TIntermTyped *varying);
......
......@@ -73,7 +73,7 @@ protected:
// Collect info for all attribs and uniforms.
void collectAttribsUniforms(TIntermNode *root);
// Translate to object code.
virtual void translate(TIntermNode *root) = 0;
virtual bool translate(TIntermNode *root) = 0;
// Get built-in extensions with default behavior.
const TExtensionBehavior& getExtensionBehavior() const;
......
......@@ -17,12 +17,14 @@ TranslatorASM::TranslatorASM(gl::Shader *shaderObject, ShShaderType type, ShShad
{
}
void TranslatorASM::translate(TIntermNode* root)
bool TranslatorASM::translate(TIntermNode* root)
{
TParseContext& parseContext = *GetGlobalParseContext();
sh::OutputASM outputASM(parseContext, shaderObject);
outputASM.output();
return parseContext.numErrors() == 0;
}
//
......
......@@ -28,7 +28,7 @@ public:
TranslatorASM(gl::Shader *shaderObject, ShShaderType type, ShShaderSpec spec);
protected:
virtual void translate(TIntermNode* root);
virtual bool translate(TIntermNode* root);
private:
gl::Shader *const shaderObject;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment