Fix seg fault

Check types before accessing typeName.

Fix #2848.
This commit is contained in:
Jeremy Hayes 2021-12-28 15:17:39 -07:00
parent ca13951205
commit 46466be045
5 changed files with 78 additions and 3 deletions

View File

@ -0,0 +1,52 @@
noMatchingFunction.frag
ERROR: 0:17: 'func' : no matching overloaded function found
ERROR: 1 compilation errors. No code generated.
Shader version: 330
ERROR: node is still EOpNull!
0:8 Function Definition: func(struct-S-f11; ( global float)
0:8 Function Parameters:
0:8 's' ( in structure{ global float a})
0:10 Sequence
0:10 Branch: Return with expression
0:10 a: direct index for structure ( global float)
0:10 's' ( in structure{ global float a})
0:10 Constant:
0:10 0 (const int)
0:15 Function Definition: main( ( global void)
0:15 Function Parameters:
0:17 Sequence
0:17 Sequence
0:17 move second child to first child ( temp float)
0:17 'c' ( temp float)
0:17 Constant:
0:17 0.000000
0:18 move second child to first child ( temp 4-component vector of float)
0:18 'o_color' (layout( location=0) out 4-component vector of float)
0:18 Construct vec4 ( temp 4-component vector of float)
0:18 'c' ( temp float)
0:? Linker Objects
0:? 'o_color' (layout( location=0) out 4-component vector of float)
Linked fragment stage:
Shader version: 330
ERROR: node is still EOpNull!
0:15 Function Definition: main( ( global void)
0:15 Function Parameters:
0:17 Sequence
0:17 Sequence
0:17 move second child to first child ( temp float)
0:17 'c' ( temp float)
0:17 Constant:
0:17 0.000000
0:18 move second child to first child ( temp 4-component vector of float)
0:18 'o_color' (layout( location=0) out 4-component vector of float)
0:18 Construct vec4 ( temp 4-component vector of float)
0:18 'c' ( temp float)
0:? Linker Objects
0:? 'o_color' (layout( location=0) out 4-component vector of float)

View File

@ -0,0 +1,19 @@
#version 330
struct S
{
float a;
};
float func(S s)
{
return s.a;
}
layout(location = 0) out vec4 o_color;
void main()
{
float c = func(1.0f); // ERROR: no matching function
o_color = vec4(c);
}

View File

@ -2446,11 +2446,15 @@ public:
//
bool sameStructType(const TType& right) const
{
// TODO: Why return true when neither types are structures?
// Most commonly, they are both nullptr, or the same pointer to the same actual structure
if ((!isStruct() && !right.isStruct()) ||
(isStruct() && right.isStruct() && structure == right.structure))
return true;
if (!isStruct() || !right.isStruct())
return false;
// Structure names have to match
if (*typeName != *right.typeName)
return false;
@ -2460,8 +2464,7 @@ public:
bool isGLPerVertex = *typeName == "gl_PerVertex";
// Both being nullptr was caught above, now they both have to be structures of the same number of elements
if (!isStruct() || !right.isStruct() ||
(structure->size() != right.structure->size() && !isGLPerVertex))
if (structure->size() != right.structure->size() && !isGLPerVertex)
return false;
// Compare the names and types of all the members, which have to match

View File

@ -1321,7 +1321,7 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction
// Find it in the symbol table.
//
const TFunction* fnCandidate;
bool builtIn;
bool builtIn {false};
fnCandidate = findFunction(loc, *function, builtIn);
if (fnCandidate) {
// This is a declared function that might map to

View File

@ -233,6 +233,7 @@ INSTANTIATE_TEST_SUITE_P(
"precise_struct_block.vert",
"maxClipDistances.vert",
"findFunction.frag",
"noMatchingFunction.frag",
"constantUnaryConversion.comp",
"xfbUnsizedArray.error.vert",
"glsl.140.layoutOffset.error.vert",