mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-13 16:45:56 +00:00
parser/wgsl: Fix stack overflow in postfix_expression()
Have postfix_expression() use a loop instead of recursively calling itself. Fixed chromium:1229669 Change-Id: Ied7684d00ba453a8b89ab0251d42e2a72169421f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58381 Auto-Submit: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
fa4d4341f4
commit
29c70796d3
@ -2224,42 +2224,57 @@ Maybe<ast::Expression*> ParserImpl::postfix_expression(
|
|||||||
ast::Expression* prefix) {
|
ast::Expression* prefix) {
|
||||||
Source source;
|
Source source;
|
||||||
|
|
||||||
if (match(Token::Type::kPlusPlus, &source) ||
|
while (continue_parsing()) {
|
||||||
match(Token::Type::kMinusMinus, &source)) {
|
if (match(Token::Type::kPlusPlus, &source) ||
|
||||||
add_error(source,
|
match(Token::Type::kMinusMinus, &source)) {
|
||||||
"postfix increment and decrement operators are reserved for a "
|
add_error(source,
|
||||||
"future WGSL version");
|
"postfix increment and decrement operators are reserved for a "
|
||||||
return Failure::kErrored;
|
"future WGSL version");
|
||||||
}
|
|
||||||
|
|
||||||
if (match(Token::Type::kBracketLeft, &source)) {
|
|
||||||
return sync(Token::Type::kBracketRight, [&]() -> Maybe<ast::Expression*> {
|
|
||||||
auto param = logical_or_expression();
|
|
||||||
if (param.errored)
|
|
||||||
return Failure::kErrored;
|
|
||||||
if (!param.matched)
|
|
||||||
return add_error(peek(), "unable to parse expression inside []");
|
|
||||||
|
|
||||||
if (!expect("array accessor", Token::Type::kBracketRight))
|
|
||||||
return Failure::kErrored;
|
|
||||||
|
|
||||||
return postfix_expression(
|
|
||||||
create<ast::ArrayAccessorExpression>(source, prefix, param.value));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match(Token::Type::kPeriod)) {
|
|
||||||
auto ident = expect_ident("member accessor");
|
|
||||||
if (ident.errored)
|
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
|
}
|
||||||
|
|
||||||
return postfix_expression(create<ast::MemberAccessorExpression>(
|
if (match(Token::Type::kBracketLeft, &source)) {
|
||||||
ident.source, prefix,
|
auto res =
|
||||||
create<ast::IdentifierExpression>(
|
sync(Token::Type::kBracketRight, [&]() -> Maybe<ast::Expression*> {
|
||||||
ident.source, builder_.Symbols().Register(ident.value))));
|
auto param = logical_or_expression();
|
||||||
|
if (param.errored)
|
||||||
|
return Failure::kErrored;
|
||||||
|
if (!param.matched) {
|
||||||
|
return add_error(peek(), "unable to parse expression inside []");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!expect("array accessor", Token::Type::kBracketRight)) {
|
||||||
|
return Failure::kErrored;
|
||||||
|
}
|
||||||
|
|
||||||
|
return create<ast::ArrayAccessorExpression>(source, prefix,
|
||||||
|
param.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.errored) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
prefix = res.value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match(Token::Type::kPeriod)) {
|
||||||
|
auto ident = expect_ident("member accessor");
|
||||||
|
if (ident.errored) {
|
||||||
|
return Failure::kErrored;
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix = create<ast::MemberAccessorExpression>(
|
||||||
|
ident.source, prefix,
|
||||||
|
create<ast::IdentifierExpression>(
|
||||||
|
ident.source, builder_.Symbols().Register(ident.value)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
return prefix;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
|
||||||
// singular_expression
|
// singular_expression
|
||||||
|
Loading…
x
Reference in New Issue
Block a user