You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I included a patch for review below rather than forking all of rust to propose a change to 3 lines of code.
Even though the subject says 1.0.0 this fix may be applicable to master and 1.1.0-dev as well.
Problem:
Building rust-1.0.0 from source crashes building stage1 libcore due to librustc_lint/builtins.rs in TypeLimits.LintPass::check_expr calling MIN::abs() resulting in panick at 'arithmetic operation overflowed'.
This is coincidentally related to the decision to close #25378 and not back-port range check to abs() since the abs() panic issue had already been fixed in master and 1.1.0-dev (confirmed).
In librustc_lint/builtins.rs check_expr can easily be modified to eliminate the need to call i32::MIN::abs() and avoid the panic during compile. The call to abs() is within a match block that deals only with signed integer literals with a positive sign (as far as I can tell that's what ast::Plus means), so there should not be a need to check for negative or call min.abs() here:
match lit.node{
ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) |
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => {let int_type = iflet ast::TyIs = t {
cx.sess().target.int_type}else{
t
};let(min, max) = int_ty_range(int_type);let negative = self.negated_expr_id == e.id;if(negative && v > (min.abs()asu64)) ||
(!negative && v > (max.abs()asu64)){
cx.span_lint(OVERFLOWING_LITERALS, e.span,&*format!("literal out of range for {:?}", t));return;}}
_ => panic!()};
I am contributing the following patch against 1.0.0 but this same fix applies to master and 1.1.0-dev as far as I can tell. Not only does this fix the compile panic issue by not calling abs() and also simplifies the code a bit in this section:
--- rustc-1.0.0/src/librustc_lint/builtin.rs 2015-05-13 14:03:53.000000000 -0600+++ rustc-1.0.0-fix/src/librustc_lint/builtin.rs 2015-05-16 05:43:01.743023679 -0600@@ -203,11 +203,9 @@
} else {
t
};
- let (min, max) = int_ty_range(int_type);- let negative = self.negated_expr_id == e.id;+ let (_, max) = int_ty_range(int_type);- if (negative && v > (min.abs() as u64)) ||- (!negative && v > (max.abs() as u64)) {+ if v as u64 > max as u64 {
cx.span_lint(OVERFLOWING_LITERALS, e.span,
&*format!("literal out of range for {:?}", t));
return;
I tried this code:
$ tar xpf rustc-1.0.0.tar.gz
$ mkdir objdir2 && cd objdir2
$ ../rustc-1.0.0/configure --prefix=/opt/rust-1.0.0 --enable-debug
$ make
I expected to see this happen:
A successful compile of rust 1.0.0 from sources.
Instead, this happened:
thread 'rustc' panicked at 'arithmetic operation overflowed', /tmp/build/rustc-1.0.0/src/libcore/num/mod.rs:509
NOTES:
After applying the above patch and building from source, the compile succeeds.
I searched for calls to abs() throughout the entire 1.0.0 code base, and read each section of code carefully and this is the only place I could find where the Rust code is unsafely calling MIN::abs() explicitly. Of course I might have missed some... so no promises :-)
Closing this issue as my patch incorrectly produces warnings for values like -128i8 and -32768i16 and -2147483648i32, which is clearly incorrect. I should have tested more thoroughly before posting the issue. I will keep digging for another work-around.
I included a patch for review below rather than forking all of rust to propose a change to 3 lines of code.
Even though the subject says 1.0.0 this fix may be applicable to master and 1.1.0-dev as well.
Problem:
Building rust-1.0.0 from source crashes building stage1 libcore due to librustc_lint/builtins.rs in TypeLimits.LintPass::check_expr calling MIN::abs() resulting in panick at 'arithmetic operation overflowed'.
This is coincidentally related to the decision to close #25378 and not back-port range check to abs() since the abs() panic issue had already been fixed in master and 1.1.0-dev (confirmed).
In librustc_lint/builtins.rs check_expr can easily be modified to eliminate the need to call i32::MIN::abs() and avoid the panic during compile. The call to abs() is within a match block that deals only with signed integer literals with a positive sign (as far as I can tell that's what ast::Plus means), so there should not be a need to check for negative or call min.abs() here:
I am contributing the following patch against 1.0.0 but this same fix applies to master and 1.1.0-dev as far as I can tell. Not only does this fix the compile panic issue by not calling abs() and also simplifies the code a bit in this section:
I tried this code:
I expected to see this happen:
A successful compile of rust 1.0.0 from sources.
Instead, this happened:
thread 'rustc' panicked at 'arithmetic operation overflowed', /tmp/build/rustc-1.0.0/src/libcore/num/mod.rs:509
NOTES:
Meta
Backtrace:
The text was updated successfully, but these errors were encountered: