Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE when doing some casts on constant expressions #9867

Closed
LeoTestard opened this issue Oct 15, 2013 · 6 comments
Closed

ICE when doing some casts on constant expressions #9867

LeoTestard opened this issue Oct 15, 2013 · 6 comments
Labels
A-codegen Area: Code generation I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@LeoTestard
Copy link
Contributor

The following code does not compile :

extern
{
    fn foo();
}

static a: u64 = foo as u64;

fn main()
{
    println!("{:u}", a};
}

It fails with the following message :

test.rs:6:18: 6:28 error: internal compiler error: Impossible case reached: bad combination of types for cast
test.rs:6 static baz: u64 = foo as u64;

Where as the following code, that does the same type of cast but in a non-constant expression, is valid :

extern
{
    fn foo();
}

fn main()
{
    let a: u64 = foo as u64;
    println!("{:u}", a};
}

Maybe I'm missing some point, but I don't see any good reason to disallow this type of casts at compile-time.

@flaper87
Copy link
Contributor

Triage bump, updated example:

extern {
    fn read();
}

static a: u64 = read as u64;

fn main() {
    println!("{:u}", a);
}

This hits rustc::middle::trans::consts

@cceckman
Copy link

Getting a similar issue in my code. Alternative example:

static foo : *mut u32 = (0x10) as *mut u32;
static bar : u32 = foo as u32;
fn main() {}

Version is 0.10-pre (50e3aa3 2014-03-17 05:17:02 -0700)
A little bit of the rustc backtrace (provided by RUST_BACKTRACE):

6:     0x7ffcb4e3e640 -driver::session::Session::impossible_case::hd4ebc2a653541a9ccAg::v0.10.pre
7:     0x7ffcb4e36d90 - middle::trans::consts::const_expr_unadjusted::h278e8dbd89fc1c82Dbj::v0.10.pre
8:     0x7ffcb4e34850 - middle::trans::consts::const_expr::hd4588a552760e28daVi::v0.10.pre
9:     0x7ffcb4d8fb90 - middle::trans::base::get_item_val::h705f0e0ab9002b63C9o::v0.10.pre
10:     0x7ffcb4e36770 - middle::trans::consts::trans_const::h2bcd0d481971109blJj::v0.10.pre
11:     0x7ffcb4d8e950 - middle::trans::base::trans_item::haca992924f705714zPo::v0.10.pre

NB this is for the arm-none-eabi target, but looks like the same issue- at least related. Can file a separate bug if it seems to be unrelated.

@jdm
Copy link
Contributor

jdm commented Mar 17, 2014

What is VIC_INT in your example?

@cceckman
Copy link

Oops- had renamed to foo in one place, not the other. Fixed in above comment. Thanks for the catch.

@bkoropoff
Copy link
Contributor

I think all the examples in here were fixed when issue #17458 was fixed.

@alexcrichton
Copy link
Member

🎆

flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 12, 2023
[arithmetic-side-effects] Consider negative numbers and add more tests

Same as rust-lang#9867.

Opening again because it is not possible to randomly choose a reviewer in an ongoing PR like in the rust repo.

---

changelog: PF: [`arithmetic_side_effects`]: No longer lints on corner cases with negative number literals
[rust-lang#9867](rust-lang/rust-clippy#9867)
<!-- changelog_checked -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants