Commit 9f01a0d4 by Olli Etuaho Committed by Commit Bot

Fix RewriteElseBlocks using a non-prefixed struct name

RewriteElseBlocks used to have an issue where it could add an unprefixed struct name to the AST in a TIntermRaw node, as opposed to the prefixed name that the struct would be defined with. Use a proper return statement node instead of a raw node to fix this issue and make the code more robust. BUG=angleproject:2061 TEST=angle_unittests Change-Id: I3993b5093646983f038268f3a5ffe26ccdae66e8 Reviewed-on: https://chromium-review.googlesource.com/530785Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 4f86d053
...@@ -84,12 +84,10 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse) ...@@ -84,12 +84,10 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse)
// returns (that are unreachable) we can silence this compile error. // returns (that are unreachable) we can silence this compile error.
if (mFunctionType && mFunctionType->getBasicType() != EbtVoid) if (mFunctionType && mFunctionType->getBasicType() != EbtVoid)
{ {
TString typeString = mFunctionType->getStruct() ? mFunctionType->getStruct()->name() TIntermNode *returnNode =
: mFunctionType->getBasicString(); new TIntermBranch(EOpReturn, TIntermTyped::CreateZero(*mFunctionType));
TString rawText = "return (" + typeString + ")0"; negatedElse = new TIntermBlock();
TIntermRaw *returnNode = new TIntermRaw(*mFunctionType, rawText); negatedElse->appendStatement(returnNode);
negatedElse = new TIntermBlock();
negatedElse->getSequence()->push_back(returnNode);
} }
TIntermSymbol *conditionSymbolElse = createTempSymbol(boolType); TIntermSymbol *conditionSymbolElse = createTempSymbol(boolType);
...@@ -109,7 +107,8 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse) ...@@ -109,7 +107,8 @@ TIntermNode *ElseBlockRewriter::rewriteIfElse(TIntermIfElse *ifElse)
return block; return block;
} }
}
} // anonymous namespace
void RewriteElseBlocks(TIntermNode *node, unsigned int *temporaryIndex) void RewriteElseBlocks(TIntermNode *node, unsigned int *temporaryIndex)
{ {
...@@ -117,4 +116,5 @@ void RewriteElseBlocks(TIntermNode *node, unsigned int *temporaryIndex) ...@@ -117,4 +116,5 @@ void RewriteElseBlocks(TIntermNode *node, unsigned int *temporaryIndex)
rewriter.useTemporaryIndex(temporaryIndex); rewriter.useTemporaryIndex(temporaryIndex);
node->traverse(&rewriter); node->traverse(&rewriter);
} }
}
} // namespace sh
...@@ -20,6 +20,12 @@ class HLSLOutputTest : public MatchOutputCodeTest ...@@ -20,6 +20,12 @@ class HLSLOutputTest : public MatchOutputCodeTest
HLSLOutputTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_HLSL_4_1_OUTPUT) {} HLSLOutputTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_HLSL_4_1_OUTPUT) {}
}; };
class HLSL30VertexOutputTest : public MatchOutputCodeTest
{
public:
HLSL30VertexOutputTest() : MatchOutputCodeTest(GL_VERTEX_SHADER, 0, SH_HLSL_3_0_OUTPUT) {}
};
// Test that having dynamic indexing of a vector inside the right hand side of logical or doesn't // Test that having dynamic indexing of a vector inside the right hand side of logical or doesn't
// trigger asserts in HLSL output. // trigger asserts in HLSL output.
TEST_F(HLSLOutputTest, DynamicIndexingOfVectorOnRightSideOfLogicalOr) TEST_F(HLSLOutputTest, DynamicIndexingOfVectorOnRightSideOfLogicalOr)
...@@ -35,3 +41,34 @@ TEST_F(HLSLOutputTest, DynamicIndexingOfVectorOnRightSideOfLogicalOr) ...@@ -35,3 +41,34 @@ TEST_F(HLSLOutputTest, DynamicIndexingOfVectorOnRightSideOfLogicalOr)
"}\n"; "}\n";
compile(shaderString); compile(shaderString);
} }
// Test that rewriting else blocks in a function that returns a struct doesn't use the struct name
// without a prefix.
TEST_F(HLSL30VertexOutputTest, RewriteElseBlockReturningStruct)
{
const std::string &shaderString =
"struct foo\n"
"{\n"
" float member;\n"
"};\n"
"uniform bool b;\n"
"foo getFoo()\n"
"{\n"
" if (b)\n"
" {\n"
" return foo(0.0);\n"
" }\n"
" else\n"
" {\n"
" return foo(1.0);\n"
" }\n"
"}\n"
"void main()\n"
"{\n"
" gl_Position = vec4(getFoo().member);\n"
"}\n";
compile(shaderString);
EXPECT_TRUE(foundInCode("_foo"));
EXPECT_FALSE(foundInCode("(foo)"));
EXPECT_FALSE(foundInCode(" foo"));
}
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