Commit 17a5c062 by Corentin Wallez Committed by Commit Bot

IntermTyped::CreateZero: handle non-basictypes

CreateZero is called in ParseContext so it should handle types which don't necessarily make sense to call it with. BUG=chromium:680961 Change-Id: I8627850e49eb9a4f4ecde61ca2d68371ea6a8dd6 Reviewed-on: https://chromium-review.googlesource.com/431001 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent e701dcc8
...@@ -483,8 +483,13 @@ TIntermTyped *TIntermTyped::CreateZero(const TType &type) ...@@ -483,8 +483,13 @@ TIntermTyped *TIntermTyped::CreateZero(const TType &type)
u[i].setBConst(false); u[i].setBConst(false);
break; break;
default: default:
UNREACHABLE(); // CreateZero is called by ParseContext that keeps parsing even when an error
return nullptr; // occurs, so it is possible for CreateZero to be called with non-basic types.
// This happens only on error condition but CreateZero needs to return a value
// with the correct type to continue the typecheck. That's why we handle
// non-basic type by setting whatever value, we just need the type to be right.
u[i].setIConst(42);
break;
} }
} }
......
...@@ -3419,3 +3419,31 @@ TEST_F(FragmentShaderValidationTest, InvalidMainPrototypeParameters) ...@@ -3419,3 +3419,31 @@ TEST_F(FragmentShaderValidationTest, InvalidMainPrototypeParameters)
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
// Regression test for a crash in the empty constructor of unsized array
// of a structure with non-basic fields fields. Test with "void".
TEST_F(FragmentShaderValidationTest, VoidFieldStructUnsizedArrayEmptyConstructor)
{
const std::string &shaderString =
"#version 300 es\n"
"struct S {void a;};"
"void main() {S s[] = S[]();}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Regression test for a crash in the empty constructor of unsized array
// of a structure with non-basic fields fields. Test with something other than "void".
TEST_F(FragmentShaderValidationTest, SamplerFieldStructUnsizedArrayEmptyConstructor)
{
const std::string &shaderString =
"#version 300 es\n"
"struct S {sampler2D a;};"
"void main() {S s[] = S[]();}\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