public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Change Artihmetic Operation to be a cast type operation
@ 2022-06-08 12:45 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d2dcac6a0bfe6a1ae66b584d231b74bd38fe48fc

commit d2dcac6a0bfe6a1ae66b584d231b74bd38fe48fc
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Tue May 10 11:21:12 2022 +0100

    Change Artihmetic Operation to be a cast type operation
    
    Arithmetic operations like this need a cast to support the range of integer
    types which are allow here.
    
    Fixes #1234

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.h | 12 +++++++++++-
 gcc/testsuite/rust/compile/issue-1234.rs      |  4 ++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index f1dff2cb0f2..b20a048865d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -555,7 +555,17 @@ public:
 	return;
       }
 
-    infered = lhs->unify (rhs);
+    switch (expr.get_expr_type ())
+      {
+      case ArithmeticOrLogicalOperator::LEFT_SHIFT:
+      case ArithmeticOrLogicalOperator::RIGHT_SHIFT:
+	infered = rhs->cast (lhs);
+	break;
+
+      default:
+	infered = lhs->unify (rhs);
+	break;
+      }
   }
 
   void visit (HIR::ComparisonExpr &expr) override
diff --git a/gcc/testsuite/rust/compile/issue-1234.rs b/gcc/testsuite/rust/compile/issue-1234.rs
new file mode 100644
index 00000000000..c6d5932c004
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-1234.rs
@@ -0,0 +1,4 @@
+fn foo() -> u8 {
+    // { dg-warning "function is never used" "" { target *-*-* } .-1 }
+    1u8 << 2u32
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:45 [gcc/devel/rust/master] Change Artihmetic Operation to be a cast type operation Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).