diff options
author | Tom Tromey <tom@tromey.com> | 2022-12-12 06:36:55 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-12-12 06:42:17 -0700 |
commit | 67a8c89601f6e1947484d5de23411634fef92e68 (patch) | |
tree | 629c90f59a49113b751bf56fd94ea9557bc73273 /gdb/rust-parse.c | |
parent | 167f3beb655da160e9241e76b7f8b1855b30c903 (diff) | |
download | gdb-67a8c89601f6e1947484d5de23411634fef92e68.zip gdb-67a8c89601f6e1947484d5de23411634fef92e68.tar.gz gdb-67a8c89601f6e1947484d5de23411634fef92e68.tar.bz2 |
Another Rust operator precedence bug
My earlier patch to fix PR rust/29859 introduced a new operator
precedence bug in the Rust parser. Assignment operators are
right-associative in Rust. And, while this doesn't often matter, as
Rust assignments always have the value (), still as a matter of
principle we should get this correct.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29859
Diffstat (limited to 'gdb/rust-parse.c')
-rw-r--r-- | gdb/rust-parse.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 3379272..f28514a 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -1344,6 +1344,8 @@ rust_parser::parse_binop (bool required) OPERATION (ANDAND, 2, logical_and_operation) \ OPERATION (OROR, 1, logical_or_operation) +#define ASSIGN_PREC 0 + operation_up start = parse_atom (required); if (start == nullptr) { @@ -1376,7 +1378,7 @@ rust_parser::parse_binop (bool required) compound_assign_op = current_opcode; /* FALLTHROUGH */ case '=': - precedence = 0; + precedence = ASSIGN_PREC; lex (); break; @@ -1398,7 +1400,11 @@ rust_parser::parse_binop (bool required) break; } - while (precedence <= operator_stack.back ().precedence + /* Make sure that assignments are right-associative while other + operations are left-associative. */ + while ((precedence == ASSIGN_PREC + ? precedence < operator_stack.back ().precedence + : precedence <= operator_stack.back ().precedence) && operator_stack.size () > 1) { rustop_item rhs = std::move (operator_stack.back ()); |