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[], ...@@ -121,7 +121,7 @@ bool TCompiler::compile(const char* const shaderStrings[],
intermediate.outputTree(root); intermediate.outputTree(root);
if (success && (compileOptions & SH_OBJECT_CODE)) if (success && (compileOptions & SH_OBJECT_CODE))
translate(root); success = translate(root);
} }
// Cleanup memory. // Cleanup memory.
......
...@@ -670,9 +670,10 @@ namespace sh ...@@ -670,9 +670,10 @@ namespace sh
Instruction *label = emit(sw::Shader::OPCODE_LABEL); Instruction *label = emit(sw::Shader::OPCODE_LABEL);
label->dst.type = sw::Shader::PARAMETER_LABEL; label->dst.type = sw::Shader::PARAMETER_LABEL;
const Function &function = findFunction(name); const Function *function = findFunction(name);
label->dst.index = function.label; ASSERT(function); // Should have been added during global pass
currentFunction = function.label; label->dst.index = function->label;
currentFunction = function->label;
} }
} }
else if(emitScope == GLOBAL) else if(emitScope == GLOBAL)
...@@ -706,8 +707,15 @@ namespace sh ...@@ -706,8 +707,15 @@ namespace sh
if(node->isUserDefined()) if(node->isUserDefined())
{ {
const TString &name = node->getName(); const TString &name = node->getName();
const Function &function = findFunction(name); const Function *function = findFunction(name);
TIntermSequence &arguments = *function.arg;
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++) for(int i = 0; i < argumentCount; i++)
{ {
...@@ -723,11 +731,11 @@ namespace sh ...@@ -723,11 +731,11 @@ namespace sh
Instruction *call = emit(sw::Shader::OPCODE_CALL); Instruction *call = emit(sw::Shader::OPCODE_CALL);
call->dst.type = sw::Shader::PARAMETER_LABEL; 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++) for(int i = 0; i < argumentCount; i++)
...@@ -1907,18 +1915,17 @@ namespace sh ...@@ -1907,18 +1915,17 @@ namespace sh
return -1; 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++) for(unsigned int f = 0; f < functionArray.size(); f++)
{ {
if(functionArray[f].name == name) if(functionArray[f].name == name)
{ {
return functionArray[f]; return &functionArray[f];
} }
} }
UNREACHABLE(); return 0;
return functionArray[0];
} }
int OutputASM::temporaryRegister(TIntermTyped *temporary) int OutputASM::temporaryRegister(TIntermTyped *temporary)
......
...@@ -121,7 +121,7 @@ namespace sh ...@@ -121,7 +121,7 @@ namespace sh
int readSwizzle(TIntermTyped *argument, int size); int readSwizzle(TIntermTyped *argument, int size);
bool trivial(TIntermTyped *expression, int budget); // Fast to compute and no side effects bool trivial(TIntermTyped *expression, int budget); // Fast to compute and no side effects
int cost(TIntermNode *expression, int budget); int cost(TIntermNode *expression, int budget);
const Function &findFunction(const TString &name); const Function *findFunction(const TString &name);
int temporaryRegister(TIntermTyped *temporary); int temporaryRegister(TIntermTyped *temporary);
int varyingRegister(TIntermTyped *varying); int varyingRegister(TIntermTyped *varying);
......
...@@ -73,7 +73,7 @@ protected: ...@@ -73,7 +73,7 @@ protected:
// Collect info for all attribs and uniforms. // Collect info for all attribs and uniforms.
void collectAttribsUniforms(TIntermNode *root); void collectAttribsUniforms(TIntermNode *root);
// Translate to object code. // Translate to object code.
virtual void translate(TIntermNode *root) = 0; virtual bool translate(TIntermNode *root) = 0;
// Get built-in extensions with default behavior. // Get built-in extensions with default behavior.
const TExtensionBehavior& getExtensionBehavior() const; const TExtensionBehavior& getExtensionBehavior() const;
......
...@@ -17,12 +17,14 @@ TranslatorASM::TranslatorASM(gl::Shader *shaderObject, ShShaderType type, ShShad ...@@ -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(); TParseContext& parseContext = *GetGlobalParseContext();
sh::OutputASM outputASM(parseContext, shaderObject); sh::OutputASM outputASM(parseContext, shaderObject);
outputASM.output(); outputASM.output();
return parseContext.numErrors() == 0;
} }
// //
......
...@@ -28,7 +28,7 @@ public: ...@@ -28,7 +28,7 @@ public:
TranslatorASM(gl::Shader *shaderObject, ShShaderType type, ShShaderSpec spec); TranslatorASM(gl::Shader *shaderObject, ShShaderType type, ShShaderSpec spec);
protected: protected:
virtual void translate(TIntermNode* root); virtual bool translate(TIntermNode* root);
private: private:
gl::Shader *const shaderObject; 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