From ec4b650adb133672f48ed7d76c12459933cb229c Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Mon, 7 Nov 2022 20:56:04 +0000 Subject: [PATCH] Remove fallthrough from fuzzer AST mutation. This CL removes the logic to handle fallthrough in the AST fuzzer. Bug: tint:1644 Change-Id: Ie636e2377bed8acfd7a644d2af6827efaf37a60e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/109000 Kokoro: Kokoro Reviewed-by: Ben Clayton Commit-Queue: Dan Sinclair --- .../mutations/delete_statement.cc | 22 +------ .../mutations/delete_statement_test.cc | 62 ++----------------- 2 files changed, 9 insertions(+), 75 deletions(-) diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.cc index 05435d0c12..1ec3ca414c 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement.cc @@ -19,7 +19,6 @@ #include #include "src/tint/ast/block_statement.h" -#include "src/tint/ast/fallthrough_statement.h" #include "src/tint/ast/for_loop_statement.h" #include "src/tint/ast/if_statement.h" #include "src/tint/ast/loop_statement.h" @@ -151,24 +150,9 @@ bool MutationDeleteStatement::CanBeDeleted(const ast::Statement& statement_node, } if (auto* case_statement = statement_node.As()) { - // It is not OK to delete the final case statement in a switch statement if the penultimate - // case statement falls through to the final case statement. - auto* switch_statement = - program.Sem().Get(case_statement)->Parent()->Declaration()->As(); - - if (switch_statement->body.Length() > 1 && - switch_statement->body[switch_statement->body.Length() - 1] == case_statement) { - // There are at least two case statements, and this is the final case statement. - auto& penultimate_case_statement_body_statements = - switch_statement->body[switch_statement->body.Length() - 2]->body->statements; - if (penultimate_case_statement_body_statements.Length() > 0 && - penultimate_case_statement_body_statements - [penultimate_case_statement_body_statements.Length() - 1] - ->Is()) { - // The penultimate case statement falls through to the final case statement, thus - // the final case statement cannot be removed. - return false; - } + // It is not OK to delete the case statement which contains the default selector. + if (case_statement->ContainsDefault()) { + return false; } } diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement_test.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement_test.cc index 925ee8008a..275a19e028 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement_test.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutations/delete_statement_test.cc @@ -22,7 +22,6 @@ #include "src/tint/ast/assignment_statement.h" #include "src/tint/ast/block_statement.h" #include "src/tint/ast/case_statement.h" -#include "src/tint/ast/fallthrough_statement.h" #include "src/tint/ast/for_loop_statement.h" #include "src/tint/ast/if_statement.h" #include "src/tint/ast/switch_statement.h" @@ -151,10 +150,7 @@ fn main() { switch(1) { case 0, 1: { } - default: { - fallthrough; - } - case 2: { + case 2, default: { } } })"; @@ -171,20 +167,14 @@ fn main() { switch(1) { case 0, 1: { } - default: { - fallthrough; - } - case 2: { + case 2, default: { } } })"; auto expected = R"( fn main() { switch(1) { - default: { - fallthrough; - } - case 2: { + case 2, default: { } } })"; @@ -199,43 +189,6 @@ fn main() { CheckStatementDeletionWorks(original, expected, statement_finder); } -TEST(DeleteStatementTest, DeleteFallthroughStatement) { - auto original = R"( -fn main() { - switch(1) { - case 0, 1: { - } - default: { - fallthrough; - } - case 2: { - } - } -})"; - auto expected = R"( -fn main() { - switch(1) { - case 0, 1: { - } - default: { - } - case 2: { - } - } -})"; - auto statement_finder = [](const Program& program) -> const ast::Statement* { - return program.AST() - .Functions()[0] - ->body->statements[0] - ->As() - ->body[1] - ->As() - ->body->statements[0] - ->As(); - }; - CheckStatementDeletionWorks(original, expected, statement_finder); -} - TEST(DeleteStatementTest, DeleteElse) { auto original = R"( fn main() { @@ -570,14 +523,11 @@ fn main() { CheckStatementDeletionNotAllowed(original, statement_finder); } -TEST(DeleteStatementTest, DoNotDeleteCaseDueToFallthrough) { +TEST(DeleteStatementTest, DoNotDeleteCaseDueToDefault) { auto original = R"( fn main() { switch(1) { - default: { - fallthrough; - } - case 2: { + case 2, default: { } } })"; @@ -586,7 +536,7 @@ fn main() { .Functions()[0] ->body->statements[0] ->As() - ->body[1] + ->body[0] ->As(); }; CheckStatementDeletionNotAllowed(original, statement_finder);