fixed issue with SkSL dead code elimination

Bug: skia:6747
Change-Id: I8566f0f6822a452167079cca004730ec0db318a8
Reviewed-on: https://skia-review.googlesource.com/19275
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2017-06-09 13:46:34 -04:00 committed by Skia Commit-Bot
parent 2ee0f42a4b
commit b310fd597f
2 changed files with 19 additions and 1 deletions

View File

@ -736,7 +736,7 @@ void GLSLCodeGenerator::writeIfStatement(const IfStatement& stmt) {
void GLSLCodeGenerator::writeForStatement(const ForStatement& f) {
this->write("for (");
if (f.fInitializer) {
if (f.fInitializer && !f.fInitializer->isEmpty()) {
this->writeStatement(*f.fInitializer);
} else {
this->write("; ");

View File

@ -1375,4 +1375,22 @@ DEF_TEST(SkSLDependentInitializers, r) {
"}\n");
}
DEF_TEST(SkSLDeadLoopVar, r) {
test(r,
"void main() {"
"for (int x = 0; x < 4; ) {"
"break;"
"}"
"}",
*SkSL::ShaderCapsFactory::Default(),
"#version 400\n"
"out vec4 sk_FragColor;\n"
"void main() {\n"
" for (; true; ) {\n"
" break;\n"
" }\n"
"}\n"
);
}
#endif