aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir
diff options
context:
space:
mode:
authorJoanVC <github-91yu@joanvc.cat>2024-09-10 21:52:50 +0200
committerPhilip Herron <philip.herron@embecosm.com>2024-09-16 16:07:50 +0000
commitba7b5a42302b6ac7b13c527307feaa5937569d0c (patch)
tree3067620acca3902ec2b8ca7df7c9f451616ee164 /gcc/rust/hir
parentf8e46bb8a8137583ea24196ff07f366e85246716 (diff)
downloadgcc-ba7b5a42302b6ac7b13c527307feaa5937569d0c.zip
gcc-ba7b5a42302b6ac7b13c527307feaa5937569d0c.tar.gz
gcc-ba7b5a42302b6ac7b13c527307feaa5937569d0c.tar.bz2
[#3141] Fix incorrect handling of overflow in numeric types
Fixes #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.h9
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 da91f36..56cb7d8 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 */