aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-06-09 13:46:34 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-12 14:32:40 +0000
commitb310fd597fc37dee888cfd5a760c4e156af08a6d (patch)
tree01a9f53a153eabf6945f59bec44f11f3eed1f68d
parent2ee0f42a4b678529d6d62a2619e66fec5e637412 (diff)
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>
-rw-r--r--src/sksl/SkSLGLSLCodeGenerator.cpp2
-rw-r--r--tests/SkSLGLSLTest.cpp18
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