diff options
author | JoanVC <github-91yu@joanvc.cat> | 2024-09-15 15:59:34 +0200 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2024-09-16 16:07:50 +0000 |
commit | b0c8579ee6d6936acbd7893a0a0b290ae9deb8e2 (patch) | |
tree | d38d4a8f4df0fc561aa0b934f2ec5d9651695371 /gcc/rust/backend/rust-compile-expr.cc | |
parent | ba7b5a42302b6ac7b13c527307feaa5937569d0c (diff) | |
download | gcc-b0c8579ee6d6936acbd7893a0a0b290ae9deb8e2.zip gcc-b0c8579ee6d6936acbd7893a0a0b290ae9deb8e2.tar.gz gcc-b0c8579ee6d6936acbd7893a0a0b290ae9deb8e2.tar.bz2 |
[#3141] Remove double negation by returning CompileExpr::Compile early
Fixes #3141.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc
Signed-off-by: Joan Vilardaga <github-91yu@joanvc.cat>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index f6b9dfd..5053036 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -237,6 +237,8 @@ CompileExpr::visit (HIR::NegationExpr &expr) auto op = expr.get_expr_type (); const auto literal_expr = expr.get_expr ().get (); + + // If it's a negated integer/float literal, we can return early if (op == NegationOperator::NEGATE && literal_expr->get_expression_type () == HIR::Expr::ExprType::Lit) { @@ -246,10 +248,12 @@ CompileExpr::visit (HIR::NegationExpr &expr) || lit_type == HIR::Literal::LitType::FLOAT) { new_literal_expr->set_negative (); + translated = CompileExpr::Compile (literal_expr, ctx); + return; } } - auto negated_expr = CompileExpr::Compile (literal_expr, ctx); + auto negated_expr = CompileExpr::Compile (literal_expr, ctx); auto location = expr.get_locus (); // this might be an operator overload situation lets check @@ -1531,11 +1535,6 @@ CompileExpr::compile_integer_literal (const HIR::LiteralExpr &expr, tyty->get_name ().c_str ()); return error_mark_node; } - // Other tests break if we don't reverse the negation - if (expr.is_negative ()) - { - mpz_neg (ival, ival); - } tree result = wide_int_to_tree (type, wi::from_mpz (type, ival, true)); |