Repository navigation
Rust programs crash when dividing by zero #944
Copy link
Copy link
Closed
Labels
A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Milestone
Description
Activity
Task failure would be friendlier.
Rust uses the LLVM
sdivandudivinstructions for integer division, which have undefined results for division by zero. Using the current Rust compiler built from master on my 32-bit Linux machine,fn main() { log_err 1/0 }prints0when compiled with optimization. When compiled without optimization, it yields different results each time it is executed, for example139268064.I'm kind of suprised by both of these results; I'd have expected a hardware exception like the one that jruderman reported. Does clang do anything different for integer division? See this thread for some discussion (but no current solutions) from the LLVM point of view.
Should trap SIGFPE and route to failure. Runtime issue.
- added a commit that references this issue
on Mar 7, 2023 - added a commit that references this issue
on Aug 5, 2023 - added a commit that references this issue
on Sep 18, 2026
Metadata
Metadata
Assignees
Labels
A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
SIGFPE / Floating point exception
Is this the intended behavior?