diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-05-30 10:15:34 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-31 19:04:56 +0000 |
commit | d9fe7006723a0e33295c416f7e5b1ab16b09a485 (patch) | |
tree | 5e3c5e4296e9143031bcea130e4ebefe9785e796 /src/sksl/SkSLCFGGenerator.cpp | |
parent | 068acd5cf930212510c69f7909c8b999be7965e2 (diff) |
fix incorrect variable not assigned error in skslc
Bug: skia:
Change-Id: Id89db8acb0b14024b79b00d98d32f9c10f019537
Reviewed-on: https://skia-review.googlesource.com/18121
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLCFGGenerator.cpp')
-rw-r--r-- | src/sksl/SkSLCFGGenerator.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/sksl/SkSLCFGGenerator.cpp b/src/sksl/SkSLCFGGenerator.cpp index 02e4e702a7..71bd37f39a 100644 --- a/src/sksl/SkSLCFGGenerator.cpp +++ b/src/sksl/SkSLCFGGenerator.cpp @@ -545,8 +545,13 @@ void CFGGenerator::addStatement(CFG& cfg, std::unique_ptr<Statement>* s) { fLoopExits.push(loopExit); if (f.fTest) { this->addExpression(cfg, &f.fTest, true); - BlockId test = cfg.fCurrent; - cfg.addExit(test, loopExit); + // this isn't quite right; we should have an exit from here to the loop exit, and + // remove the exit from the loop body to the loop exit. Structuring it like this + // forces the optimizer to believe that the loop body is always executed at least + // once. While not strictly correct, this avoids incorrect "variable not assigned" + // errors on variables which are assigned within the loop. The correct solution to + // this is to analyze the loop to see whether or not at least one iteration is + // guaranteed to happen, but for the time being we take the easy way out. } cfg.newBlock(); this->addStatement(cfg, &f.fStatement); @@ -556,6 +561,7 @@ void CFGGenerator::addStatement(CFG& cfg, std::unique_ptr<Statement>* s) { this->addExpression(cfg, &f.fNext, true); } cfg.addExit(cfg.fCurrent, loopStart); + cfg.addExit(cfg.fCurrent, loopExit); fLoopContinues.pop(); fLoopExits.pop(); cfg.fCurrent = loopExit; |