Commit 78d13744 by Olli Etuaho Committed by Commit Bot

Validate main() prototype declarations with incorrect parameters

Instead of just validating definitions of main(), do the validation for all function headers for functions named "main", including headers in prototype declarations. BUG=angleproject:1712 TEST=angle_unittests Change-Id: Ia34a2a756e1cc27b241b27e8c01c6ef09bffba71 Reviewed-on: https://chromium-review.googlesource.com/430010Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 65603eb8
...@@ -2530,21 +2530,6 @@ void TParseContext::parseFunctionDefinitionHeader(const TSourceLoc &location, ...@@ -2530,21 +2530,6 @@ void TParseContext::parseFunctionDefinitionHeader(const TSourceLoc &location,
(*function)->setDefined(); (*function)->setDefined();
} }
// Raise error message if main function takes any parameters or return anything other than void
if ((*function)->getName() == "main")
{
if ((*function)->getParamCount() > 0)
{
error(location, "function cannot take any parameter(s)",
(*function)->getName().c_str());
}
if ((*function)->getReturnType().getBasicType() != EbtVoid)
{
error(location, "main function cannot return a value",
(*function)->getReturnType().getBasicString());
}
}
// Remember the return type for later checking for return statements. // Remember the return type for later checking for return statements.
mCurrentFunctionType = &((*function)->getReturnType()); mCurrentFunctionType = &((*function)->getReturnType());
mFunctionReturnsValue = false; mFunctionReturnsValue = false;
...@@ -2615,6 +2600,20 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF ...@@ -2615,6 +2600,20 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF
// Add the function prototype to the surrounding scope instead. // Add the function prototype to the surrounding scope instead.
symbolTable.getOuterLevel()->insert(function); symbolTable.getOuterLevel()->insert(function);
// Raise error message if main function takes any parameters or return anything other than void
if (function->getName() == "main")
{
if (function->getParamCount() > 0)
{
error(location, "function cannot take any parameter(s)", "main");
}
if (function->getReturnType().getBasicType() != EbtVoid)
{
error(location, "main function cannot return a value",
function->getReturnType().getBasicString());
}
}
// //
// If this is a redeclaration, it could also be a definition, in which case, we want to use the // If this is a redeclaration, it could also be a definition, in which case, we want to use the
// variable names from this one, and not the one that's // variable names from this one, and not the one that's
......
...@@ -3401,6 +3401,21 @@ TEST_F(FragmentShaderValidationTest, Sampler2DMSInESSL300Shader) ...@@ -3401,6 +3401,21 @@ TEST_F(FragmentShaderValidationTest, Sampler2DMSInESSL300Shader)
if (compile(shaderString)) if (compile(shaderString))
{ {
FAIL() << "Shader compilation succeed, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
\ No newline at end of file
// Declare main() with incorrect parameters.
// ESSL 3.00.6 section 6.1 Function Definitions.
TEST_F(FragmentShaderValidationTest, InvalidMainPrototypeParameters)
{
const std::string &shaderString =
"#version 300 es\n"
"void main(int a);\n"
"void main() {}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
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