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 <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
8a519ac8a9
commit
ec4b650adb
|
@ -19,7 +19,6 @@
|
|||
#include <vector>
|
||||
|
||||
#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,26 +150,11 @@ bool MutationDeleteStatement::CanBeDeleted(const ast::Statement& statement_node,
|
|||
}
|
||||
|
||||
if (auto* case_statement = statement_node.As<ast::CaseStatement>()) {
|
||||
// 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<ast::SwitchStatement>();
|
||||
|
||||
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<ast::FallthroughStatement>()) {
|
||||
// The penultimate case statement falls through to the final case statement, thus
|
||||
// the final case statement cannot be removed.
|
||||
// It is not OK to delete the case statement which contains the default selector.
|
||||
if (case_statement->ContainsDefault()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto* parent_sem = program.Sem().Get(&statement_node)->Parent();
|
||||
if (parent_sem == nullptr) {
|
||||
|
|
|
@ -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<ast::SwitchStatement>()
|
||||
->body[1]
|
||||
->As<ast::CaseStatement>()
|
||||
->body->statements[0]
|
||||
->As<ast::FallthroughStatement>();
|
||||
};
|
||||
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<ast::SwitchStatement>()
|
||||
->body[1]
|
||||
->body[0]
|
||||
->As<ast::CaseStatement>();
|
||||
};
|
||||
CheckStatementDeletionNotAllowed(original, statement_finder);
|
||||
|
|
Loading…
Reference in New Issue