Emit dead expressions when optimizations are off.

Fixes a minor issue discovered by http://review.skia.org/539198 .

Change-Id: I63f555cc005df33ce50c412796a8c773a501d271
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539199
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-05-10 18:49:30 -04:00 committed by SkCQ
parent 2f13b32f79
commit 462dab699c
3 changed files with 11 additions and 6 deletions

View File

@ -1410,10 +1410,12 @@ void GLSLCodeGenerator::writeDoStatement(const DoStatement& d) {
}
void GLSLCodeGenerator::writeExpressionStatement(const ExpressionStatement& s) {
if (s.expression()->hasSideEffects()) {
this->writeExpression(*s.expression(), Precedence::kTopLevel);
this->write(";");
if (fProgram.fConfig->fSettings.fOptimize && !s.expression()->hasSideEffects()) {
// Don't emit dead expressions.
return;
}
this->writeExpression(*s.expression(), Precedence::kTopLevel);
this->write(";");
}
void GLSLCodeGenerator::writeSwitchStatement(const SwitchStatement& s) {

View File

@ -2280,10 +2280,12 @@ void MetalCodeGenerator::writeDoStatement(const DoStatement& d) {
}
void MetalCodeGenerator::writeExpressionStatement(const ExpressionStatement& s) {
if (s.expression()->hasSideEffects()) {
this->writeExpression(*s.expression(), Precedence::kTopLevel);
this->write(";");
if (fProgram.fConfig->fSettings.fOptimize && !s.expression()->hasSideEffects()) {
// Don't emit dead expressions.
return;
}
this->writeExpression(*s.expression(), Precedence::kTopLevel);
this->write(";");
}
void MetalCodeGenerator::writeSwitchStatement(const SwitchStatement& s) {

View File

@ -37,6 +37,7 @@ bool flatten_matching_ternary_b() {
}
bool flatten_expr_without_side_effects_b() {
bool check = true;
check;
return check;
}
bool flatten_switch_b() {