diff options
author | JoanVC <github-91yu@joanvc.cat> | 2024-09-10 21:52:50 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-19 15:32:10 +0100 |
commit | 5db515e56893efd82c048993123b3cb3f0667315 (patch) | |
tree | 3bf376e16ad3254c8c2bb4342a3f6e085810703e /gcc/rust/hir | |
parent | da48816297db523cac4bd69aceafb7cafc7478e2 (diff) | |
download | gcc-5db515e56893efd82c048993123b3cb3f0667315.zip gcc-5db515e56893efd82c048993123b3cb3f0667315.tar.gz gcc-5db515e56893efd82c048993123b3cb3f0667315.tar.bz2 |
gccrs: [gccrs#3141] Fix incorrect handling of overflow in numeric types
Fixes gccrs#3141.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc: Fix range checking for both integers and floats.
* hir/tree/rust-hir-expr.h: Add "negative_number" boolean to LiteralExpr class.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3141.rs: New test.
Signed-off-by: Joan Vilardaga <github-91yu@joanvc.cat>
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-expr.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 8a2d82f..1ee1066 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -93,6 +93,7 @@ class LiteralExpr : public ExprWithoutBlock { Literal literal; location_t locus; + bool negative_number = false; public: std::string as_string () const override @@ -132,6 +133,14 @@ public: ExprType get_expression_type () const override final { return ExprType::Lit; } + bool is_negative () const { return negative_number; } + void set_negative () + { + rust_assert (get_lit_type () == Literal::LitType::INT + || get_lit_type () == Literal::LitType::FLOAT); + negative_number = true; + } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ |