diff options
-rw-r--r-- | src/sksl/SkSLGLSLCodeGenerator.cpp | 2 | ||||
-rw-r--r-- | tests/SkSLGLSLTest.cpp | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp index c3168e3ed3..6381acb322 100644 --- a/src/sksl/SkSLGLSLCodeGenerator.cpp +++ b/src/sksl/SkSLGLSLCodeGenerator.cpp @@ -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("; "); diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 678ff13dd3..2ea6c7ec71 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -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 |