Add missing operator to regex fuzzer

Fixes a problem where the regex fuzzer would identify '==' as a
candidate operator for replacement, but where the replacement code did
not actually handle the '==' case.

Fixes http://crbug.com/1367902
Change-Id: I9a3bda9e7bae5e42872f17427419ab690d477533

Change-Id: If9cbb2db779c6873ff7a02d132981e8ee3410bb1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104200
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: Alastair Donaldson <afdx@google.com>
This commit is contained in:
Alastair Donaldson 2022-09-29 14:36:08 +00:00 committed by Dawn LUCI CQ
parent f6772c1332
commit 2af7ab3b16

View File

@ -416,7 +416,7 @@ std::string WgslMutator::ChooseRandomReplacementForOperator(const std::string& e
"=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="};
std::vector<std::string> expression_operators{"+", "-", "*", "/", "%", "&&", "||",
"&", "|", "^", "<<", ">>", "<", ">",
"<=", ">=", "!", "!=", "~"};
"<=", ">=", "!", "==", "!=", "~"};
std::vector<std::string> increment_operators{"++", "--"};
for (auto operators : {assignment_operators, expression_operators, increment_operators}) {
auto it = std::find(operators.begin(), operators.end(), existing_operator);
@ -471,6 +471,12 @@ std::optional<std::pair<uint32_t, uint32_t>> WgslMutator::FindOperatorOccurrence
switch (first_character) {
case '!':
case '^':
case '*':
case '/':
case '%':
case '=':
// The above cases are all stand-alone operators, and if followed by '=' are also
// operators.
switch (second_character) {
case '=':
return {{current_index, 2}};
@ -481,26 +487,15 @@ std::optional<std::pair<uint32_t, uint32_t>> WgslMutator::FindOperatorOccurrence
case '&':
case '+':
case '-':
// The above cases are all stand-alone operators, and if repeated or followed by '='
// are also operators.
if (second_character == first_character || second_character == '=') {
return {{current_index, 2}};
}
return {{current_index, 1}};
case '*':
case '/':
case '%':
switch (second_character) {
case '=':
return {{current_index, 2}};
default:
return {{current_index, 1}};
}
case '=':
if (second_character == '=') {
return {{current_index, 2}};
}
return {{current_index, 1}};
case '<':
case '>':
// The following caters for '<', '<=', '<<', '<<=', '>', '>=', '>>' and '>>='.
if (second_character == '=') {
return {{current_index, 2}};
}