Skip to content

Commit

Permalink
Remove literal string from error message.
Browse files Browse the repository at this point in the history
The lexer doesn't actually keep the string for literals.

Bug chromium:939239

Change-Id: Ib8b28e75e36d1c6beff8afa580fc4c29c23b6eb0
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26428
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
  • Loading branch information
c0d1f1ed committed Mar 8, 2019
1 parent 6203340 commit d2b1d2f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/OpenGL/compiler/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2828,7 +2828,7 @@ TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierTyp
return qualifier;
}

TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine, const TString &intValueString, int intValue, const TSourceLoc& intValueLine)
TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine, int intValue, const TSourceLoc& intValueLine)
{
TLayoutQualifier qualifier;

Expand All @@ -2846,7 +2846,7 @@ TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierTyp
// must check that location is non-negative
if (intValue < 0)
{
error(intValueLine, "out of range:", intValueString.c_str(), "location must be non-negative");
error(intValueLine, "out of range:", "", "location must be non-negative");
recover();
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/OpenGL/compiler/ParseHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class TParseContext {
const TString* instanceName, const TSourceLoc& instanceLine, TIntermTyped* arrayIndex, const TSourceLoc& arrayIndexLine);

TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine);
TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine, const TString &intValueString, int intValue, const TSourceLoc& intValueLine);
TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine, int intValue, const TSourceLoc& intValueLine);
TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, TLayoutQualifier rightQualifier);
TPublicType joinInterpolationQualifiers(const TSourceLoc &interpolationLoc, TQualifier interpolationQualifier, const TSourceLoc &storageLoc, TQualifier storageQualifier);

Expand Down
4 changes: 2 additions & 2 deletions src/OpenGL/compiler/glslang.y
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,10 @@ layout_qualifier_id
$$ = context->parseLayoutQualifier(*$1.string, @1);
}
| IDENTIFIER EQUAL INTCONSTANT {
$$ = context->parseLayoutQualifier(*$1.string, @1, *$3.string, $3.i, @3);
$$ = context->parseLayoutQualifier(*$1.string, @1, $3.i, @3);
}
| IDENTIFIER EQUAL UINTCONSTANT {
$$ = context->parseLayoutQualifier(*$1.string, @1, *$3.string, $3.i, @3);
$$ = context->parseLayoutQualifier(*$1.string, @1, $3.i, @3);
}
;

Expand Down
4 changes: 2 additions & 2 deletions src/OpenGL/compiler/glslang_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3777,15 +3777,15 @@ YYLTYPE yylloc = yyloc_default;
case 153:

{
(yyval.interm.layoutQualifier) = context->parseLayoutQualifier(*(yyvsp[-2].lex).string, (yylsp[-2]), *(yyvsp[0].lex).string, (yyvsp[0].lex).i, (yylsp[0]));
(yyval.interm.layoutQualifier) = context->parseLayoutQualifier(*(yyvsp[-2].lex).string, (yylsp[-2]), (yyvsp[0].lex).i, (yylsp[0]));
}

break;

case 154:

{
(yyval.interm.layoutQualifier) = context->parseLayoutQualifier(*(yyvsp[-2].lex).string, (yylsp[-2]), *(yyvsp[0].lex).string, (yyvsp[0].lex).i, (yylsp[0]));
(yyval.interm.layoutQualifier) = context->parseLayoutQualifier(*(yyvsp[-2].lex).string, (yylsp[-2]), (yyvsp[0].lex).i, (yylsp[0]));
}

break;
Expand Down
92 changes: 92 additions & 0 deletions tests/GLESUnitTests/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,98 @@ TEST_F(SwiftShaderTest, AttributeLocation)
Uninitialize();
}

// Test negative layout locations
TEST_F(SwiftShaderTest, NegativeLocation)
{
Initialize(3, false);

const std::string vs =
"#version 300 es\n"
"layout(location = 0x86868686u) in vec4 a0;\n" // Explicitly bound in GLSL
"layout(location = 0x96969696u) in vec4 a2;\n" // Explicitly bound in GLSL
"in vec4 a5;\n" // Bound to location 5 by API
"in mat2 a3;\n" // Implicit location
"in vec4 a1;\n" // Implicit location
"in vec4 a6;\n" // Implicit location
"out vec4 color;\n"
"void main()\n"
"{\n"
" vec4 a34 = vec4(a3[0], a3[1]);\n"
" gl_Position = a0;\n"
" color = (a2 == vec4(1.0, 2.0, 3.0, 4.0) &&\n"
" a34 == vec4(5.0, 6.0, 7.0, 8.0) &&\n"
" a5 == vec4(9.0, 10.0, 11.0, 12.0) &&\n"
" a1 == vec4(13.0, 14.0, 15.0, 16.0) &&\n"
" a6 == vec4(17.0, 18.0, 19.0, 20.0)) ?\n"
" vec4(0.0, 1.0, 0.0, 1.0) :\n"
" vec4(1.0, 0.0, 0.0, 1.0);"
"}\n";

const std::string fs =
"#version 300 es\n"
"precision mediump float;\n"
"in vec4 color;\n"
"layout(location = 0xA6A6A6A6u) out vec4 fragColor;\n"
"void main()\n"
"{\n"
" fragColor = color;\n"
"}\n";

{
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
const char* vsSource[1] = { vs.c_str() };
glShaderSource(vertexShader, 1, vsSource, nullptr);
glCompileShader(vertexShader);
EXPECT_GLENUM_EQ(GL_NONE, glGetError());
GLint vsCompileStatus = 0;
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &vsCompileStatus);
EXPECT_EQ(vsCompileStatus, GL_FALSE);

// Expect the info log to contain "out of range: location must be non-negative". This is not a spec requirement.
GLsizei length = 0;
glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &length);
EXPECT_GLENUM_EQ(GL_NONE, glGetError());
EXPECT_NE(length, 0);
char *log = new char[length];
GLsizei written = 0;
glGetShaderInfoLog(vertexShader, length, &written, log);
EXPECT_GLENUM_EQ(GL_NONE, glGetError());
EXPECT_EQ(length, written + 1);
EXPECT_NE(strstr(log, "out of range: location must be non-negative"), nullptr);
delete[] log;

glDeleteShader(vertexShader);
}

{
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
const char* fsSource[1] = { fs.c_str() };
glShaderSource(fragmentShader, 1, fsSource, nullptr);
glCompileShader(fragmentShader);
EXPECT_GLENUM_EQ(GL_NONE, glGetError());
GLint fsCompileStatus = 0;
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &fsCompileStatus);
EXPECT_EQ(fsCompileStatus, GL_FALSE);

// Expect the info log to contain "out of range: location must be non-negative". This is not a spec requirement.
GLsizei length = 0;
glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &length);
EXPECT_GLENUM_EQ(GL_NONE, glGetError());
EXPECT_NE(length, 0);
char *log = new char[length];
GLsizei written = 0;
glGetShaderInfoLog(fragmentShader, length, &written, log);
EXPECT_GLENUM_EQ(GL_NONE, glGetError());
EXPECT_EQ(length, written + 1);
EXPECT_NE(strstr(log, "out of range: location must be non-negative"), nullptr);
delete[] log;

glDeleteShader(fragmentShader);
}

Uninitialize();
}

// Tests clearing of a texture with 'dirty' content.
TEST_F(SwiftShaderTest, ClearDirtyTexture)
{
Expand Down

0 comments on commit d2b1d2f

Please sign in to comment.