From 5ac2f2864ca65d691ab461f1a176e80028aaee76 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 2 Dec 2024 13:54:29 +0000 Subject: gccrs: add checks for division by zero and left shift overflow These are ported from the c-family code c-warn.cc and c/c-typchk.cc Fixes Rust-GCC#2394 gcc/rust/ChangeLog: * backend/rust-constexpr.cc (eval_store_expression): check for null (eval_call_expression): remove bad warning * rust-gcc.cc (arithmetic_or_logical_expression): add warnings gcc/testsuite/ChangeLog: * rust/compile/issue-2394.rs: New test. Signed-off-by: Philip Herron --- gcc/testsuite/rust/compile/issue-2394.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2394.rs (limited to 'gcc/testsuite/rust/compile') diff --git a/gcc/testsuite/rust/compile/issue-2394.rs b/gcc/testsuite/rust/compile/issue-2394.rs new file mode 100644 index 0000000..92f7afc --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2394.rs @@ -0,0 +1,14 @@ +const A: i32 = (1 / 0); +// { dg-error "division by zero" "" { target *-*-* } .-1 } + +fn main() { + let a = 1 / 0; + // { dg-error "division by zero" "" { target *-*-* } .-1 } + + let b = 3; + let c = b / 0; + // { dg-error "division by zero" "" { target *-*-* } .-1 } + + let a = 1 << 500; + // { dg-error "left shift count >= width of type" "" { target *-*-* } .-1 } +} -- cgit v1.1