Disallow switch statements in runtime effects

Bug: skia:10680
Change-Id: Ic77f7355866363ef476a93d8da180cf53207fa6d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353707
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
Brian Osman 2021-01-14 11:40:56 -05:00 committed by Skia Commit-Bot
parent 01f322cce4
commit 890b2b406a
3 changed files with 10 additions and 2 deletions

View File

@ -634,6 +634,11 @@ std::unique_ptr<Statement> IRGenerator::convertDo(const ASTNode& d) {
std::unique_ptr<Statement> IRGenerator::convertSwitch(const ASTNode& s) {
SkASSERT(s.fKind == ASTNode::Kind::kSwitch);
if (this->strictES2Mode()) {
this->errorReporter().error(s.fOffset, "switch statements are not supported");
return nullptr;
}
AutoSwitchLevel level(this);
auto iter = s.begin();
std::unique_ptr<Expression> value = this->convertExpression(*(iter++));

View File

@ -1,7 +1,9 @@
// Expect 3 errors
// Expect 4 errors
void discard_stmt() { discard; }
int do_loop(int x) { do { x++; } while(x < 1); return x; }
int while_loop(int x) { while (x < 1) { x++; } return x; }
int switch_stmt(int x) { switch (x) { case 0: return 1; default: return x; } }

View File

@ -3,4 +3,5 @@
error: 3: discard statement is only permitted in fragment shaders
error: 5: do-while loops are not supported
error: 7: while loops are not supported
3 errors
error: 9: switch statements are not supported
4 errors