-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #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 <[email protected]>
- Loading branch information
Showing
3 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
} |